如下所示,类似这种写法要怎么实现
CREATE OR REPLACE PROCEDURE GET_PJ_MANAGE_FROMSCXT
AS
Cursor new_pj_cursor3(f_VESSEL_NAME varchar2,f_START_WORK_TIME varchar2) is
select count(VESSEL_NAME) as ct from scxt_send_work_head
where VESSEL_NAME = f_VESSEL_NAME
if START_WORK_TIME is null then
and START_WORK_TIME is null
else
and START_WORK_TIME=f_START_WORK_TIME
end if;
BEGIN
END GET_PJ_MANAGE_FROMSCXT;
两种方法:
用union
用动态sql
动态sql里面可以用if拼接么?
追答if在外面啊,用if判断来动态拼接sql串
比如:
sql:='select * from emp where ';
if parameter = '1' then
sql := sql || ' sex = 1';
elsif parameter = '2' then
sql := sql || ' age >= 20';
else
sql := sql || ' 1=1';
end if;
如此而已。