将SAP HANA SQL中的STRING_AGG存储到过程中的变量中。

huangapple go评论70阅读模式
英文:

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;

huangapple
  • 本文由 发表于 2023年5月23日 00:40:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76308298.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定