this question regarding plsql - improving efficiency of code , coding standards.
any help, pointers, references or suggestions highly appreciated.
question:
i have plsql procedure input parameter i_flag
of type boolean
.
based upon value of i_flag( can either true or false) have execute sql query. if value true
sql1 (assume query 1.1) else if value false
sql2 (assume query 1.2) executed.
sql2 same sql1 except addition of clause.
sql1 (1.1)
select a.user_id, a.user_name, a.dept_id, b.country user , contact b a.user_id = b.user_id;
sql1 (1.2)
select a.user_id, a.user_name, a.dept_id, b.country user , contact b a.user_id = b.user_id , a.user_status not null;
instead of writing if-else in plsql possible write query in single sql query?
you can create same behavior in single query using logical or
operator:
select a.user_id, a.user_name, a.dept_id, b.country user , contact b a.user_id = b.user_id , (i_flag = true or a.user_status not null)
note, way, implicit joins (having 2 tables in from
clause) deprecated syntax, , it's recommended switch modern, explicit, syntax:
select a.user_id, a.user_name, a.dept_id, b.country user join contact b on a.user_id = b.user_id i_flag = true or a.user_status not null
Comments
Post a Comment