If statement PL/SQL if内部声明

If statement PL/SQL if内部声明,if-statement,plsql,header,declaration,plsqldeveloper,If Statement,Plsql,Header,Declaration,Plsqldeveloper,我想知道是否有办法在PL/SQL过程的声明中包含if语句。例如: procedure testing (no IN NUMBER, name IN VARCHAR2) IS if no = 0 then cursor c is select * from table where name = name; else cursor c is select * from table where name = name

我想知道是否有办法在PL/SQL过程的声明中包含if语句。例如:

procedure testing (no IN NUMBER, name IN VARCHAR2) IS
    if no = 0 then 
      cursor c is 
          select * from table where name = name;
    else 
      cursor c is
          select * from table where name = name;
    end if;
BEGIN 
   --work with cursor c
END testing;

这或多或少是它的意图

对不起,我没有把问题读对。在开始之前,你不能这样做

如果C是ref cursor,您可以为select*from table或select name from table打开它,但它的意图还不够清楚,因为在这两种情况下,您都可以处理diffident字段列表


Oracle中的示例:

否,在声明性部分只能有变量声明和初始化

您可以使用游标变量(
REF cursor
type)并从可执行块打开游标:

procedure testing (no IN NUMBER, name IN VARCHAR2) IS
    TYPE YOUR_CURSOR_TYPE IS REF CURSOR;
    c YOUR_CURSOR_TYPE;
BEGIN 
   --work with cursor c
   if no = 0 then 
      OPEN c FOR 
          select * from table where name = name;
    else 
      open c FOR
          select * from table where name = name;
    end if;

    ... do something with c 
END testing;
根据
select
子句的列,必须决定是使用强类型游标变量还是弱类型游标变量


没有。。。不过,您可以嵌套PL/SQL块,因此在begin中有一个declare。