create or replace function getlastdate(tablename in varchar2,sumtype in varchar2) return varchar2 is 2 v_lastdate varchar2(8); 3 v_sql varchar2(200); 4 begin 5 v_sql := 'select to_char(max(C_ENDDATE),''yyyymmdd'') from '|| tablename ||' where C_SUMTYPE = '''||sumtype ||''''; 6 execute immediate v_sql into v_lastdate; 7 return v_lastdate; 8 end getlastdate; 9 /
Function created
SQL> select getlastdate('employees','1') from dual;
GETLASTDATE('EMPLOYEES','1') -------------------------------------------------------------------------------- 20080512
SQL> |
|