CREATE OR REPLACE procedure SHKWON.load_procedure
(
v_datetime IN varchar2, -- 매개변수에는 크기를 정하지않음
v_user_id IN varchar2,
v_action IN varchar2,
v_user_ip IN varchar2,
v_pageCount IN NUMBER,
sel_cur IN OUT sys_refcursor
)
IS
vsQuery varchar(2000);
lf VARCHAR2(1) := chr(10);
BEGIN
vsQuery := 'select * from ('
|| lf || ' select'
|| lf || ' user_id, log_index, action,user_ip,'
|| lf || ' to_char(datetime, ''YYYY/MM/DD HH24:MI:SS'') as datetime,'
|| lf || ' message'
|| lf || ' from aaa'
|| lf || ' where 1=1';
if( v_datetime is not null ) then
vsQuery := vsQuery || lf || ' and datetime = '
|| 'to_date(''' || v_datetime || ''',''YYYY/MM/DD HH24:MI:SS'')';
end if;
if( v_user_id is not null ) then
vsQuery := vsQuery || lf || ' and user_id = ''' || v_user_id || '''';
end if;
if( v_action is not null ) then
vsQuery := vsQuery || lf || ' and action = ''' || v_action || '''';
end if;
if( v_user_ip is not null ) then
vsQuery := vsQuery || lf || ' and user_ip = ''' || v_user_ip ||'''';
end if;
vsQuery := vsQuery || lf || ' )';
vsQuery := vsQuery || lf || 'where log_index >= (select count(*) from aaa)-'
|| v_pageCount;
vsQuery := vsQuery || lf || 'order by log_index desc;';
dbms_output.put_line(vsQuery);
open sel_cur for vsQuery;
END load_procedure;
/