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

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

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

  1. CREATE PROCEDURE My_StrProc
  2. ( IN @rollNumber Varchar(18),
  3. IN @studentType Varchar(3),
  4. OUT @studentID Varchar(15),
  5. OUT @oldStudentType Varchar(4) ,
  6. OUT @oldBranch Varchar(3) ,
  7. OUT @newStudentType Varchar(4) ,
  8. OUT @newBranch Varchar(4)
  9. )
  10. BEGIN
  11. IF @studentType IS NOT NULL
  12. THEN
  13. Select
  14. @studentID = REGISTRATION_NO,
  15. @oldStudentType = OLD_STUD_TYPE,
  16. @oldBranch = OLD_BRANCH,
  17. @newStudentType = NEW_STUD_TYPE,
  18. @newBranch = NEW_BRANCH
  19. From
  20. Migrated_Student
  21. Where
  22. OLD_STUDENT_NUM = @rollNumber and
  23. ACTIVE = 'P';
  24. ELSE
  25. Select
  26. @studentID = REGISTRATIONNO,
  27. @oldStudentType = OLD_STUD_TYPE,
  28. @oldBranch = OLD_BRANCH,
  29. @newStudentType = NEW_STUD_TYPE,
  30. @newBranch = NEW_BRANCH
  31. From
  32. Migrated_Student
  33. Where
  34. OLD_STUDENT _NUM = @rollNumber and
  35. OLD_ STUDENT _TYPE = @studentType and
  36. ACTIVE = 'P';
  37. END IF;
  38. END;
bxjv4tth

bxjv4tth1#

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

  1. CREATE or replace PROCEDURE My_StrProc
  2. ( IN p_rollNumber Varchar(18),
  3. IN p_studentType Varchar(3),
  4. OUT p_studentID Varchar(15),
  5. OUT p_oldStudentType Varchar(4) ,
  6. OUT p_oldBranch Varchar(3) ,
  7. OUT p_newStudentType Varchar(4) ,
  8. OUT p_newBranch Varchar(4)
  9. )
  10. BEGIN
  11. IF p_studentType IS NOT NULL
  12. THEN
  13. Select
  14. REGISTRATION_NO,
  15. OLD_STUD_TYPE,
  16. OLD_BRANCH,
  17. NEW_STUD_TYPE,
  18. NEW_BRANCH
  19. into
  20. p_studentID
  21. ,p_oldStudentType
  22. ,p_oldBranch
  23. ,p_newStudentType
  24. ,p_newBranch
  25. From
  26. Migrated_Student
  27. Where
  28. OLD_STUDENT_NUM = p_rollNumber
  29. and ACTIVE = 'P';
  30. ELSE
  31. Select
  32. REGISTRATION_NO,
  33. OLD_STUD_TYPE,
  34. OLD_BRANCH,
  35. NEW_STUD_TYPE,
  36. NEW_BRANCH
  37. into
  38. p_studentID
  39. ,p_oldStudentType
  40. ,p_oldBranch
  41. ,p_newStudentType
  42. ,p_newBranch
  43. From
  44. Migrated_Student
  45. Where
  46. OLD_STUDENT_NUM = p_rollNumber and
  47. OLD_STUD_TYPE = p_studentType and
  48. ACTIVE = 'P';
  49. END IF;
  50. END
展开查看全部

相关问题