英文:
SAP HANA SQL store STRING_AGG to variable in procedure
问题
I see the issue with the COLS1 := SELECT STRING_AGG(COLUMN_NAME,',') FROM :TAB1;
line. It appears that you're using the wrong syntax for assigning the result of the STRING_AGG
function to the COLS1
variable. You should use the SELECT INTO
statement like this:
SELECT STRING_AGG(COLUMN_NAME,',') INTO COLS1 FROM :TAB1;
This should resolve the error you're encountering.
英文:
I have a procedure where I need to get the fields of a column (in SAP HANA database). I need to assign the output of STRING_AGG
function to a variable
CREATE procedure TAB_COMP (IN T1 VARCHAR(30), IN T2 VARCHAR(30))
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
BEGIN
DECLARE TAB1 TABLE (COLUMN_NAME VARCHAR(500));
DECLARE TAB2 TABLE (COLUMN_NAME VARCHAR(500));
DECLARE COLS1 VARCHAR(500);
DECLARE COLS2 VARCHAR(500);
TAB1 = SELECT COLUMN_NAME FROM TABLE_COLUMNS WHERE TABLE_NAME= :T1 ORDER BY POSITION;
TAB2 = SELECT COLUMN_NAME FROM TABLE_COLUMNS WHERE TABLE_NAME= :T2 ORDER BY POSITION;
 
COLS1 := SELECT STRING_AGG(COLUMN_NAME,',') FROM :TAB1;
END
I'm getting an error with the COLS1 := SELECT STRING_AGG(COLUMN_NAME,',') FROM :TAB1;
line. Can you figure out why its happening?
答案1
得分: 2
To assign a single value (scalar) result from a query to a variable, use the SELECT INTO
command.
SELECT
STRING_AGG(COLUMN_NAME, ',') INTO COLS1
FROM :TAB1;
英文:
To assign a single value (scalar) result from a query to a variable, use the SELECT INTO
command.
SELECT
STRING_AGG(COLUMN_NAME,',') INTO COLS1
FROM :TAB1;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论