else语句创建存储过程时出现编译错误

cedebl8k  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(487)

db2新手。版本11。在创建存储过程时,它在“from”附近给出了一个错误错误语法预期:bulkinfo

CREATE PROCEDURE My_StrProc 
( IN @rollNumber     Varchar(18), 
  IN @studentType       Varchar(3),   
 OUT @studentID        Varchar(15),   
 OUT @oldStudentType   Varchar(4) ,  
 OUT  @oldBranch Varchar(3) ,  
 OUT @newStudentType    Varchar(4) ,  
 OUT @newBranch Varchar(4) 
)
BEGIN
IF @studentType IS NOT NULL 
    THEN
    Select  
            @studentID       =  REGISTRATION_NO,  
            @oldStudentType   = OLD_STUD_TYPE,  
            @oldBranch    = OLD_BRANCH,  
            @newStudentType    = NEW_STUD_TYPE,  
            @newBranch = NEW_BRANCH
        From  
            Migrated_Student  
        Where  
            OLD_STUDENT_NUM = @rollNumber and   
            ACTIVE = 'P';
ELSE
    Select  
            @studentID       = REGISTRATIONNO,  
            @oldStudentType   = OLD_STUD_TYPE,  
            @oldBranch    = OLD_BRANCH,  
            @newStudentType   = NEW_STUD_TYPE,  
            @newBranch    = NEW_BRANCH
                    From  
            Migrated_Student  
        Where  
            OLD_STUDENT _NUM = @rollNumber and  
            OLD_ STUDENT _TYPE = @studentType and  
            ACTIVE = 'P';
END IF;
END;
bxjv4tth

bxjv4tth1#

如果您使用的是ansisqlpl语法,那么您的过程如下所示。
注意,与其他rdbms不同,变量和参数不应该以@字符开头。
使用命名约定,比如 p_ 表示参数,或 v_ 表示变量只是可选的噪声,但有些人喜欢它。

CREATE or replace PROCEDURE My_StrProc 
( IN p_rollNumber        Varchar(18), 
  IN p_studentType       Varchar(3),   
 OUT p_studentID         Varchar(15),   
 OUT p_oldStudentType    Varchar(4) ,  
 OUT p_oldBranch         Varchar(3) ,  
 OUT p_newStudentType    Varchar(4) ,  
 OUT p_newBranch         Varchar(4) 
)
BEGIN

IF p_studentType IS NOT NULL 
THEN
    Select  
            REGISTRATION_NO,  
            OLD_STUD_TYPE,  
            OLD_BRANCH,  
            NEW_STUD_TYPE,  
            NEW_BRANCH
        into
             p_studentID
            ,p_oldStudentType
            ,p_oldBranch
            ,p_newStudentType
            ,p_newBranch
        From  
            Migrated_Student  
        Where  
            OLD_STUDENT_NUM = p_rollNumber 
            and   ACTIVE = 'P';
ELSE
    Select  
            REGISTRATION_NO,  
            OLD_STUD_TYPE,  
            OLD_BRANCH,  
            NEW_STUD_TYPE,  
            NEW_BRANCH
     into
             p_studentID
            ,p_oldStudentType
            ,p_oldBranch
            ,p_newStudentType
            ,p_newBranch
     From  
            Migrated_Student  
        Where  
            OLD_STUDENT_NUM = p_rollNumber and  
            OLD_STUD_TYPE = p_studentType and  
            ACTIVE = 'P';
END IF;
END

相关问题