从参数中插入SAP HANA 2.0中的存储过程

时间:2017-08-04 02:20:35

标签: stored-procedures hana

我想创建商店程序但无法创建。我的代码:

CREATE PROCEDURE "TESTING"."SCALAR_VARIABLE_EXAMPLE_INSERT" (IN paramin NVARCHAR(5000))
                LANGUAGE SQLSCRIPT
                SQL SECURITY INVOKER
                AS
BEGIN
/*****************************
                Write your procedure logic
 *****************************/
                DECLARE username varchar(20) := 'bobbyss';
                DECLARE description varchar(100);

                description := 'select JSON_VALUE('''||:paramin||''', ''$.description'') AS "desc" from DUMMY';

                INSERT INTO "TESTING"."USER" 
                VALUES (:username, :description);

END;

当我调用此过程时,显示SQL语法错误:“select”

附近的语法不正确

如何解决这个问题?感谢。

1 个答案:

答案 0 :(得分:1)

你的语法错了,这是一个有效的例子:

create table test_user (username nvarchar(20), description nvarchar(100));
CREATE PROCEDURE SCALAR_VARIABLE_EXAMPLE_INSERT (IN paramin NVARCHAR(5000))
                LANGUAGE SQLSCRIPT
                SQL SECURITY INVOKER
                AS
BEGIN
/*****************************
                Write your procedure logic
 *****************************/
                DECLARE username varchar(20) := 'bobbyss';
                DECLARE description varchar(100);

                select JSON_VALUE(:paramin, '$.description') into description from DUMMY;

                INSERT INTO test_user 
                VALUES (:username, :description);

END;

call SCALAR_VARIABLE_EXAMPLE_INSERT('{"description":"Test Description..."}');
select * from test_user;