以下是我在存储过程中的内容
CREATE OR REPLACE PROCEDURE GET_USER (IN IN_USER_NAME VARCHAR(256))
DYNAMIC RESULT SETS 1
P1: BEGIN
-- Declare cursor
DECLARE cursor1 CURSOR WITH RETURN for
IF (IN_USER_NAME IS NULL) THEN
SELECT BLUEMSP.USERS.USER_ID FROM BLUEMSP.USERS;
END IF;
-- Cursor left open for client application
OPEN cursor1;
END P1
我在If语句行显示
时出错Multiple markers at this line
"." was expected instead of "(".
- "JOIN" was expected instead of "THEN".
- "IF (IN_USER_NAME IS NULL) THEN
SELECT BLUEMSP.USERS.USER_ID FROM BLUEMSP." appears to be misplaced.
- "(" was expected after "IS".
为什么这不起作用?
由于
答案 0 :(得分:2)
您不能在游标声明中使用IF
语句,因为IF
是PL / SQL,并且游标声明必须是纯SQL。
答案 1 :(得分:0)
CREATE OR REPLACE PROCEDURE GET_USER (IN_USER_NAME IN VARCHAR2)
IS
xxx BLUEMSP.USERS.USER_ID%TYPE;
CURSOR cursor1 IS SELECT BLUEMSP.USERS.USER_ID FROM BLUEMSP.USERS;
BEGIN
IF (IN_USER_NAME IS NULL) THEN
OPEN cursor1;
FETCH cursor1 INTO xxx;
...
END IF
CLOSE cursor1;
END