Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Selecting multiple columns conditionally in Oracle10g
- SELECT column1,
- column2,
- column3,
- column4,
- column5,
- column6,
- --If this condition is not met the following columns are not selected
- IF password = password
- (
- conditional_column1,
- conditional_column2,
- conditional_column3
- )
- FROM source_table
- WHERE username = username
- SQL> create or replace procedure dyn_emp( p_include_empno in boolean,
- 2 p_rc out sys_refcursor )
- 3 as
- 4 l_sql varchar2(1000);
- 5 begin
- 6 l_sql := 'SELECT ename ';
- 7 if( p_include_empno )
- 8 then
- 9 l_sql := l_sql || ', empno ';
- 10 end if;
- 11 l_sql := l_sql || ' from emp';
- 12 open p_rc for l_sql;
- 13 end;
- 14 /
- Procedure created.
- SQL> variable rc refcursor;
- SQL> exec dyn_emp( true, :rc );
- PL/SQL procedure successfully completed.
- SQL> print rc
- ENAME EMPNO
- ---------- ----------
- SMITH 7369
- ALLEN 7499
- WARD 7521
- JONES 7566
- MARTIN 7654
- BLAKE 7698
- CLARK 7782
- SCOTT 7788
- KING 7839
- TURNER 7844
- ADAMS 7876
- JAMES 7900
- FORD 7902
- MILLER 7934
- 14 rows selected.
- SQL> exec dyn_emp( false, :rc );
- PL/SQL procedure successfully completed.
- SQL> print rc
- ENAME
- ----------
- SMITH
- ALLEN
- WARD
- JONES
- MARTIN
- BLAKE
- CLARK
- SCOTT
- KING
- TURNER
- ADAMS
- JAMES
- FORD
- MILLER
- 14 rows selected.
Add Comment
Please, Sign In to add comment