DB2存储过程,什么是psm_pipe

时间:2018-10-30 14:03:19

标签: stored-procedures db2

为什么在线DB2文档中的一致性如此之小?

我正在尝试创建一个返回4个值的SP,它最初是一个时髦的SQL语句,带有“ JOIN”和“ UNIONS”等,但最终由于可能是效率非常低的SP而告终。不会编译..!

代码如下:

CREATE PROCEDURE Lex.LV_LogIn (
  -- Optional: input and output parameters
  --   { parameter-name } [IN | OUT | IN OUT] { data-type },
    IN LogIn VARCHAR(45),
    OUT RoleType BIGINT,
    OUT RoleDescription VARCHAR(45),
    OUT EmpName VARCHAR(45),
    OUT Granted BOOL
) 
LANGUAGE SQL
BEGIN 
    DECLARE empid BIGINT DEFAULT 0;
    DECLARE usrid BIGINT DEFAULT 0;
    SET RoleType = 0;
    SET RoleDescription = '';
    SET Granted = FALSE;

    SELECT "idCustEmployees", "idCustUserIds" INTO empid, usrid FROM LEX.CUSTUSERIDS WHERE "SourceType" = 'LexView' AND "LogIn" = LogIn;
    SELECT "idRoles" INTO RoleType FROM LEX.IDS2ROLES WHERE "idCustUserIds" = usrid;
    CASE
        WHEN RoleType > 0 THEN
            Granted = TRUE;
            SELECT "Description" INTO  RoleDescription FROM LEX.ROLES WHERE "idRoles" = RoleType;
            SELECT "FullName_C" INTO EmpName FROM LEX.CUSTEMPLOYEES WHERE "idCustEmployees" = empid;
        ELSE
            LEAVE;
    END CASE
END @
GRANT EXECUTE ON PROCEDURE TO USER xxxxxxxxxx;

我遇到了一个又一个的错误,这就是为什么我将其分解为疯狂的简单事物的原因,在尝试CASE之前,我尝试了IF(...),IF(...)THEN和IF ..然后...

所有导致相同的错误:-> 预期使用“ psm_pipe”而不是“ CASE ...

问题1:我在SP中做错了什么?

问题2:什么是psm_pipe?如果您通过google db2“ psm_pipe”为何不出现?

有创意吗?

谢谢, 鲍勃·B。

1 个答案:

答案 0 :(得分:1)

您的代码片段有语法错误。下面的代码将在Db2 Linux / Unix / Windows 11.1或更高版本上编译。首字母缩写词PSM表示持久性存储模块。

寻求帮助时,请始终编写您的Db2服务器版本和Db2服务器操作系统(z / os,i系列,linux / unix / windows),因为答案因平台和版本而异。

当您遇到语法错误时,请务必输入确切的错误编号(SQLCODE和/或SQLSTATE),并显示消息,这是对搜索有意义的sqlcode / sqlstate。

CREATE PROCEDURE Lex.LV_LogIn (
    IN LogIn VARCHAR(45),
    OUT RoleType BIGINT,
    OUT RoleDescription VARCHAR(45),
    OUT EmpName VARCHAR(45),
    OUT Granted BOOLEAN
)
LANGUAGE SQL
specific lv_login
BEGIN
    DECLARE empid BIGINT DEFAULT 0;
    DECLARE usrid BIGINT DEFAULT 0;
    SET RoleType = 0;
    SET RoleDescription = '';
    SET Granted = FALSE;

    SELECT "idCustEmployees", "idCustUserIds"
    INTO empid, usrid
    FROM LEX.CUSTUSERIDS
    WHERE "SourceType" = 'LexView'
    AND "LogIn" = LogIn;

    SELECT "idRoles" INTO RoleType
    FROM LEX.IDS2ROLES
    WHERE "idCustUserIds" = usrid;

    IF RoleType > 0 THEN
        set Granted = TRUE;
        SELECT "Description"
        INTO  RoleDescription
        FROM LEX.ROLES
        WHERE "idRoles" = RoleType;

        SELECT "FullName_C"
        INTO EmpName
        FROM LEX.CUSTEMPLOYEES
        WHERE "idCustEmployees" = empid;
    END IF;
END @