Question : utitlity function in oracle to check for data in table exists

I have to write a utility function to determine data exists in the table (there are about 8-10 tables - accept table name as parameter) for all days in the month and if not throw exception the date column in the table is date-time 2009-06-17-00.00.00 format - we need to this ckeck before running a scheduled job to send a sucess or fail criteria before we start the batch

Answer : utitlity function in oracle to check for data in table exists

if we assume every table has the same string column that is formatted the same way and has the same name

and we assume you want to check the current month

and we assume 1 row of data for a day is sufficient for that day to pass

then try something like this...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
CREATE OR REPLACE FUNCTION check_month(p_table IN VARCHAR2)
    RETURN VARCHAR2
IS
    v_sql   VARCHAR2(500);
    v_month DATE := TRUNC(SYSDATE, 'mm');
    v_cnt   INTEGER;
BEGIN
    v_sql :=
        'SELECT COUNT(*) FROM (SELECT dt, ROW_NUMBER() OVER (PARTITION BY TRUNC(dt) ORDER BY 1) rn FROM '
        || p_table
        || ' WHERE to_date(dt,''yyyy-mm-dd-hh24.mi.ss'') >= :v_month'
        || ' AND to_date(dt,''yyyy-mm-dd-hh24.mi.ss'') < ADD_MONTHS(:v_month, 1)) WHERE rn = 1';
 
    EXECUTE IMMEDIATE v_sql INTO v_cnt USING v_month, v_month;
 
    IF v_cnt = TO_NUMBER(TO_CHAR(LAST_DAY(v_month), 'dd'))
    THEN
        RETURN 'Pass';
    ELSE
        RETURN 'Fail';
    END IF;
END;
Open in New Window Select All
Random Solutions  
 
programming4us programming4us