Connor and Chris will both be at AI World from October 12 to October 17 , the premier Oracle conference of 2025. If you're in Vegas, please come say Hi or pop into our sessions
Thanks for the question, Subramanian.
Asked: February 26, 2018 - 9:40 pm UTC
Last updated: February 28, 2018 - 2:03 am UTC
Version: 12cR1
Viewed 1000+ times
SQL> create or replace 2 function dyn_cur(p_type int) return sys_refcursor is 3 rc sys_Refcursor; 4 begin 5 if p_type = 1 then 6 open rc for select * from scott.emp; 7 else 8 open rc for select * from scott.dept; 9 end if; 10 return rc; 11 end; 12 / Function created. SQL> SQL> variable r refcursor SQL> exec :r := dyn_cur(1); PL/SQL procedure successfully completed. SQL> print r EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7788 SCOTT ANALYST 7566 09-DEC-82 3000 20 7839 KING PRESIDENT 17-NOV-81 5000 10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 30 7876 ADAMS CLERK 7788 12-JAN-83 1100 20 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 14 rows selected. SQL> exec :r := dyn_cur(2); PL/SQL procedure successfully completed. SQL> print r DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 4 rows selected. SQL> SQL> SQL>
Racer I., February 27, 2018 - 7:21 am UTC
SELECT sum(Amount), tgt_group_cd from ( SELECT Amount, tgt_group_cd, tv.txn_id from payments_view pv,transactions_view tv where pv.tcd_id=tv.pmt_tgt_id and GetMode = 1 union all SELECT Amount,tgt_group_cd, tv.txn_id from pmt_vw pv, txns_vw tv where pv.tcd_id=tv.pmt_tgt_id and GetMode = 0 ) where txn_id=CV_txn_Id group by tgt_group_cd
Check out more PL/SQL tutorials on our LiveSQL tool.
PL/SQL reference manual from the Oracle documentation library