简体   繁体   English

存储过程 sap hana 中的自定义表类型

[英]custom table type in stored procedure sap hana

I'm new in the sap hana world.我是 sap hana 世界的新手。 I'm trying to use stored procedures to update info.我正在尝试使用存储过程来更新信息。 I want to send a custom table type with the field name, field value and row id.我想发送带有字段名称、字段值和行 ID 的自定义表类型。 I created this type:我创建了这种类型:

CREATE TYPE t_field AS TABLE (
   ID INTEGER,
   FLD VARCHAR(100),
   VAL VARCHAR(100));

And I used it in this procedure:我在这个过程中使用了它:

    PROCEDURE "_SYS_BIC"."Match.procedures::updateAnag" (
    in tfield tt_field,
    out error tt_error
 ) 

 LANGUAGE SQLSCRIPT
 SQL SECURITY INVOKER 
 DEFAULT SCHEMA "_SYS_BIC"
 AS

BEGIN

     declare _id integer; 
     declare _field varchar(100);
     declare _value varchar(100);

     select ID, F_NAME, F_VALUE
     into _id, _field, _value
     from :tfield;

    IF(_field = '' OR _value = '') THEN
        error = SELECT 400 AS http_status_code,
                 'empty field' as error_message,
                  'All fields must be filled' as detail from dummy;
    ELSE

    IF (_field = 'name') THEN
        UPDATE "_SYS_BIC"."TEST_TABLE" 
        SET NAME = _value
        WHERE ID = _id;
    END IF;

    IF (_field = 'surname') THEN
        UPDATE "_SYS_BIC"."TEST_TABLE" 
        SET SURNAME = _value
        WHERE ID = _id;
    END IF;

    END IF;

END; 

But when I try to activate the code, eclipse returns me this error: 'sap-ui-core.js:159 2016-07-19 17:45:47.751550 The following problem occurred: HTTP request failed400,Bad Request,Request contains properties that do not exist in entity 'anagType'.但是当我尝试激活代码时,eclipse 返回给我这个错误:'sap-ui-core.js:159 2016-07-19 17:45:47.751550 出现以下问题:HTTP request failed400,Bad Request,Request contains properties实体“anagType”中不存在的。 -' ——'

Can someone help me to fix it or show me a better way to do this?有人可以帮我修复它或向我展示更好的方法吗?

Alright, from a SQLSCript code point of view, I'd say one problem here is that when you use the variables (like _value or _id) need to have the colon in front of them:好吧,从 SQLSCript 代码的角度来看,我想说的一个问题是,当您使用变量(如 _value 或 _id)时,需要在它们前面加上冒号:

    CREATE PROCEDURE "_SYS_BIC"."Match.procedures::updateAnag" (
    in tfield tt_field,
    out error tt_error
 ) 

 LANGUAGE SQLSCRIPT
 SQL SECURITY INVOKER 
 DEFAULT SCHEMA "_SYS_BIC"
 AS

BEGIN

     declare _id integer; 
     declare _field varchar(100);
     declare _value varchar(100);

     select ID, F_NAME, F_VALUE
     into _id, _field, _value
     from :tfield;

    IF(:_field = '' OR _:value = '') THEN
        error = SELECT 400 AS http_status_code,
                 'empty field' as error_message,
                  'All fields must be filled' as detail from dummy;
    ELSE

    IF (:_field = 'name') THEN
        UPDATE "_SYS_BIC"."TEST_TABLE" 
        SET NAME = :_value
        WHERE ID = :_id;
    END IF;

    IF (:_field = 'surname') THEN
        UPDATE "_SYS_BIC"."TEST_TABLE" 
        SET SURNAME = :_value
        WHERE ID = :_id;
    END IF;

    END IF;

END; 

Another problem is that you don't initialize the table variable error in the second branch of the IF statement.另一个问题是您没有在 IF 语句的第二个分支中初始化表变量错误。

Not quite sure though, what all this has to do with your error message.虽然不太确定,这一切与您的错误消息有什么关系。 You might want to call and test the procedure on its own first and then see why the connection to your xsjs page doesn't work properly.您可能希望首先自行调用和测试该过程,然后查看与 xsjs 页面的连接为何无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM