PL/SQL:在 'WITH ... AS' 子句外使用 'IF' 语句

PL/SQL: Use 'IF' statement outside 'WITH ... AS' clause

我正在尝试编写一个使用子查询分解 'WITH .. AS' 的过程,但是当我在它之前使用 'IF .. THEN' 时,出现语法错误,我不知道该如何编写, 有帮助吗?

  BEGIN
  OPEN my_SYS_REFCURSOR FOR
   IF .. IS NULL
   THEN
     WITH SomeName
          AS (SELECT.....);

您只需将 IF 语句与 OPEN 语句分开:

declare
    my_sys_refcursor sys_refcursor;
begin
    if (1=1) then /* condition satisfied, cursor from some table */
        open my_sys_refcursor for
        with somename as ( select '1' as one from dual)
        select one
        from somename;
    else  /* condition not satisfied, select from different tables */
        open my_sys_refcursor for
        with someOthername as ( select 'one' as one from dual)
        select one
        from someOthername;
    end if;
end;