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

时间:2017-01-23 11:35:16

标签: oracle if-statement plsql syntax subquery-factoring

我正在尝试编写一个程序,我使用Subquery Factoring'WITH .. AS',但是当我在它之前使用'IF .. THEN'时,我得到语法错误,我不知道应该怎么写它,有什么帮助吗?

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

1 个答案:

答案 0 :(得分:1)

您只需将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;