Displaying table data through plsql procedure - plsql

I am trying to display the table info through this plsql code but when it executes the procedure it just show procedure successful. not the output.please help.
CREATE OR REPLACE PROCEDURE CarInfo
AS
V_serial CAR.serial%TYPE;
V_Cid CAR.cid%TYPE;
V_make CAR.make%TYPE ;
V_model CAR.model%TYPE;
V_cyear CAR.cyear%TYPE;
V_color CAR.color%TYPE;
V_trim CAR.trim%TYPE;
V_enginetype CAR.enginetype%TYPE;
V_purchinv CAR.purchinv%TYPE;
V_purchdate CAR.purchdate%TYPE;
V_purchfrom CAR.purchfrom%TYPE;
V_purchcost CAR.purchcost%TYPE;
V_freightcost CAR.freightcost%TYPE;
V_totalcost CAR.totalcost%TYPE;
V_listprice CAR.listprice%TYPE;
BEGIN
SELECT serial, cid, make, model, cyear, color, trim, enginetype, purchinv, purchdate, purchfrom , purchcost, freightcost,
totalcost, listprice
INTO V_serial, V_cid, V_make, V_model, V_cyear, V_color, V_trim, V_enginetype, V_purchinv, V_purchdate, V_purchfrom , V_purchcost, V_freightcost,
V_totalcost, V_listprice
FROM CAR
where cid is null;
Exception
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('No Data Found') ;
DBMS_OUTPUT.PUT_LINE(V_serial||' ' || V_cid||' ' ||V_make||' ' ||V_model||' ' ||V_cyear||' ' ||V_color||' ' ||V_trim||' ' ||V_enginetype||' ' ||V_purchinv||' ' ||V_purchdate||' ' ||V_purchfrom ||' ' ||V_purchcost||' ' ||V_freightcost||' ' ||
V_totalcost||' ' ||V_listprice);
END;

In brief, I would write your procedure the following way:
CREATE OR REPLACE PROCEDURE CarInfo
AS
l_result_clob clob;
BEGIN
SELECT serial ||' ' || cid ||' ' ||make ||' ' ||model ||' ' ||cyear||' ' ||
color ||' ' ||trim ||' ' ||enginetype||' ' ||purchinv ||' ' ||
purchdate||' ' ||purchfrom ||' ' ||purchcost ||' ' ||freightcost||' ' ||totalcost||' ' ||listprice
INTO l_result_clob
FROM CAR
where cid is null;
DBMS_OUTPUT.PUT_LINE(l_result_clob);
Exception
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('No Data Found') ;
WHEN OTHERS THEN
dbms_output.put_line('SQLCODE: ' || SQLCODE) ;
END CarInfo;
That is of course, if all the columns in the SELECT statement are actually convertible to character/clob, as Oracle would implicitly convert them, in order for the concatenation to happen.
Cheers

Related

Dynamic Cursor with parameterised schema name and using for BULK INSERT in target table

I have source_table in different 22 schemas and need procedure to create for bulk collect and insert into same target table in oracle stored procedure.
I'm trying and not getting records inserted getting error ORA-00911: invalid character but there is all column from select cursor and traget_table are same in order.
CREATE OR REPLACE PROCEDURE proc_bulk_circle(p_limit IN PLS_INTEGER DEFAULT 10000,
p_activity_date IN DATE,
p_circle IN VARCHAR2) AS
CURSOR act_cur IS
SELECT activity_date,
circle
FROM circle_load_control
WHERE activity_date = p_activity_date
AND circle = circle;
TYPE type_i6 IS TABLE OF act_cur%ROWTYPE INDEX BY BINARY_INTEGER;
i_tab6 type_i6;
v_count NUMBER := 0;
lv_circle VARCHAR2(2);
lv_schema VARCHAR2(20);
TYPE rc IS REF CURSOR;
con_sap_cur rc;
TYPE con_sap_resp IS TABLE OF target_table%ROWTYPE INDEX BY BINARY_INTEGER;
i_tab1 con_sap_resp;
lv_sql_stmt VARCHAR2(32767);
BEGIN
IF p_circle = 'MUM'
THEN
lv_circle := 'MU';
lv_schema := 'MUMBAI';
ELSIF p_circle = 'MAH'
THEN
lv_circle := 'MH';
lv_schema := 'MHRSTR';
ELSE
lv_circle := NULL;
END IF;
FOR myindex IN act_cur
LOOP
i_tab6(v_count) := myindex;
v_count := v_count + 1;
END LOOP;
FOR myindex IN i_tab6.first .. i_tab6.last
LOOP
IF i_tab6(myindex).activity_date = p_activity_date
AND i_tab6(myindex).circle = p_circle
THEN
BEGIN
lv_sql_stmt := 'SELECT acc_id code,
cust_id c_id,
addr_1 address2,
addr_2 address3,
addr_3 address4,
(SELECT SUM(abc) FROM ' || lv_schema || '.details WHERE <some condition with t1> GROUP BY <columns>) main_charges,
(SELECT SUM(extra_charge) FROM ' || lv_schema || '.details WHERE <some condition with t1> GROUP BY <columns>) extra_charges
FROM ' || lv_schema || '.main_source_details t1
WHERE t1.activity_date = ''' || p_activity_date || ''';';
OPEN con_sap_cur FOR lv_sql_stmt;
LOOP
FETCH con_sap_cur BULK COLLECT
INTO i_tab1 LIMIT p_limit;
FORALL i IN 1 .. i_tab1.count
INSERT INTO target_table (column list....)
VALUES(I_TAB1(i).col1,......;
EXIT WHEN con_sap_cur%NOTFOUND;
END LOOP;
COMMIT;
CLOSE con_sap_cur;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('ERR target_table: ' || SQLCODE || '-' || SQLERRM);
END;
ELSE
dbms_output.put_line(p_activity_date || ' DATE IS NOT MATCH');
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(SQLCODE || ' ' || SQLERRM);
END proc_bulk_circle;
/
I believe this comes down to you having a ; in your definition of the sql (see below line)
WHERE t1.activity_date = ''' || p_activity_date || ''';';
when you are defining SQL for dynamic use (and opening a cursor this way is dynamic) you do not include the ;
To show this I have done a shorter example. The below will error in the same way as yours.
declare
v_sql varchar2(100) default 'select ''X'' from dual;';
TYPE rc IS REF CURSOR;
v_cur rc;
type l_tab_type is table of varchar2(1);
l_tab l_tab_type;
begin
open v_cur for v_sql;
loop
fetch v_cur bulk collect into l_tab;
exit;
end loop;
CLOSE v_cur;
end;
/
but simply remove the ; from the line
v_sql varchar2(100) default 'select ''X'' from dual;';
end it all works fine, fixed example below.
declare
v_sql varchar2(100) default 'select ''X'' from dual';
TYPE rc IS REF CURSOR;
v_cur rc;
type l_tab_type is table of varchar2(1);
l_tab l_tab_type;
begin
open v_cur for v_sql;
loop
fetch v_cur bulk collect into l_tab;
exit;
end loop;
CLOSE v_cur;
end;
/
You're doing an awful lot of work here, if your purpose is to insert some rows.
Instead, you could do the insert and select in one go, something like:
CREATE OR REPLACE PROCEDURE proc_bulk_circle(p_activity_date IN DATE,
p_circle IN VARCHAR2) AS
lv_circle VARCHAR2(2);
lv_schema VARCHAR2(20);
v_query CLOB;
e_table_does_not_exist EXCEPTION;
PRAGMA EXCEPTION_INIT(e_table_does_not_exist, -00942);
BEGIN
IF p_circle = 'MUM'
THEN
lv_circle := 'MU';
lv_schema := 'MUMBAI';
ELSIF p_circle = 'MAH'
THEN
lv_circle := 'MH';
lv_schema := 'MHRSTR';
END IF;
IF lv_schema IS NOT NULL
THEN
-- asserting the schema name to avoid sql injection
-- also using a bind variable for the activity_daate predicates
v_query := 'INSERT INTO target_table (<column list>)' || CHR(10) ||
' WITH main_dets AS (SELECT acc_id,' || CHR(10) ||
' cust_id,' || CHR(10) ||
' addr_1,' || CHR(10) ||
' addr_2,' || CHR(10) ||
' addr_3,' || CHR(10) ||
' (SELECT SUM(abc) FROM ' || dbms_assert.simple_sql_name(lv_schema) || '.details WHERE <some condition with t1>) main_charges,' || CHR(10) || -- no need for the group by
' (SELECT SUM(extra_charge) FROM ' || dbms_assert.simple_sql_name(lv_schema) || '.details WHERE <some condition with t1>) extra_charges' || CHR(10) || -- no need for the group by
' FROM ' || dbms_assert.simple_sql_name(lv_schema) || '.main_source_details t1' || CHR(10) ||
' WHERE activity_date = :p_activity_date)' || CHR(10) ||
' circles AS (SELECT activity_date,' || CHR(10) ||
' circle' || CHR(10) ||
' FROM circle_load_control' || CHR(10) ||
' WHERE activity_date = :p_activity_date' || CHR(10) ||
' AND circle = circle)' || CHR(10) || -- did you really mean circle = circle here? This is equivalent to 1=1 (unless circle is null) and is therefore pretty irrelevant! If you want to exclude rows with null values, use "circle is not null" instead
' SELECT md.acc_id,' || CHR(10) ||
' md.cust_id,' || CHR(10) ||
' md.addr_1,' || CHR(10) ||
' md.addr_2,' || CHR(10) ||
' md.addr_3,' || CHR(10) ||
' md.main_charges,' || CHR(10) ||
' md.extra_charges' || CHR(10) ||
' FROM main_dets md' || CHR(10) ||
' CROSS JOIN circles c';
EXECUTE v_query USING p_activity_date, p_activity_date;
COMMIT;
ELSE
raise_application_error(-20001, 'Invalid circle specified: "' || p_circle || '"');
END IF;
END proc_bulk_circle;
/
(N.B. untested.)
I've assumed that activity_date and circle in circle_load_control aren't unique; if they are, you could avoid the cross join and just have an implicit cursor to fetch the row prior to doing the IF p_circle = ... checks.

Invalid Time Literal in Teradata Dynamic SQL

The following stored procedure works fine when I use static sql to insert values into the DBCMNGR.ALERTREQUEST but does not work when trying to use the dynamic sql string.
I get invalid date literal and time literal when trying to call the below stored procedure.
CALL TESTDB.ALERT_REQUEST_INSERT('Test_JobName','Test_JobDescription',
'Test_ActionDestination','Test_JobFullMessage')
Need help to actually work this without any errors.
In the DBCMNGR.ALERTREQUEST the DATE and time are defined as follows:
ReqDate DATE FORMAT 'YYYY/MM/DD'
ReqTime INTEGER
REPLACE PROCEDURE TESTDB.ALERT_REQUEST_INSERT( IN p_JobName CHARACTER(60), IN p_JobDescription CHARACTER(120), IN p_ActionDestination CHARACTER(120), IN p_JobFullMessage CHARACTER(600) ) )
BEGIN
SET SQLSTR = 'INSERT INTO DBCMNGR.ALERTREQUEST ' || '(AlertRequest.ReqDate ' || ',AlertRequest.ReqTime ' || ',AlertRequest.JobName ' || ',AlertRequest.Description ' || ',AlertRequest.EventValue ' || ',AlertRequest.ActionCode ' || ',AlertRequest.RepeatPeriod ' || ',AlertRequest.Destination ' || ',AlertRequest.Message ' || ') ' || 'VALUES ( ' || ' DATE ' || ',TIME ' || ''',''' || TRIM(p_JobName) || ''',''' || TRIM(p_JobDescription) || ''',0 ' || ',''+'' ' || ',0 ' || ''',''' || TRIM(p_ActionDestination) || ',''' || TRIM(p_JobFullMessage) || ''');';
EXECUTE IMMEDIATE SQLSTR; END;

update query with OR condition in PL/sql

I have a update query in PL/SQL where I need to use OR condition based on itemsetid='XXXX or orgid ='YYYYY' this is because not all tables have these 2 fields so I need to use OR condition. I tried as below but it's not working ,
set serveroutput on size unlimited ;
declare
type item_type
is record (
maxSameas maxattribute.sameasattribute%TYPE,
maxTable maxattribute.objectname%TYPE,
maxAttrib maxattribute.attributename%TYPE
);
Type attribArray is table of item_type;
allAttribs attribArray;
cursor ITEM_ATTRIB_CURSOR is
select a.sameasattribute, a.objectname, a.attributename
from maxattribute a, maxobject b
where a.persistent = 1
and a.objectname = b.objectname
and b.persistent = 1
and ((a.sameasattribute is not null
and a.sameasattribute like 'ITEMNUM')
or (a.attributename = 'ITEMNUM'))
and a.objectname <> 'ITEMHIST'
-- and a.objectname <> 'ITEM'
and b.isView = '0'
order by a.objectname asc, a.attributename asc, a.sameasattribute desc;
type itemXrefType
is record (
currValue itemhist.ITEMNUM%type,
oldValue itemhist.OLDITEMNUM%type
);
type itemXrefTable is table of itemXrefType;
itemXref itemXrefTable;
cursor ITEM_VAL_CURSOR is
select itemnum, olditemnum
from itemhist
where olditemnum is not null and itemsetid='XXXXX';
updateStr varchar2 (4000);
queryStr varchar2 (4000);
tableName varchar2 (30);
attribName varchar2(50);
rowKount NUMBER;
begin
DBMS_OUTPUT.ENABLE(NULL);
-- Fetch Cross Reference Data
open item_val_cursor;
fetch item_val_cursor bulk collect into itemXref;
close item_val_cursor;
-- Fetch all Objects with ITEMNUM attribute
open ITEM_ATTRIB_CURSOR;
fetch ITEM_ATTRIB_CURSOR bulk collect into allAttribs;
close ITEM_ATTRIB_CURSOR;
-- Loop through every Object
for i in allAttribs.first..allAttribs.last loop
tableName := allAttribs(i).maxTable;
if (tableName = 'ITEM') then
attribName := 'ITEMNUM';
else
attribName := allAttribs(i).maxAttrib;
end if;
for j in itemXref.first .. itemXref.last loop
-- For each Item Num, update all objects
queryStr := 'select count (1) from ' || tableName ||
' where ' || attribName || '=' || '''' || itemXref(j).oldValue || '''';
-- Get Count before update
EXECUTE IMMEDIATE queryStr into RowKount;
updateStr := 'update ' || tableName ||
' set ' || attribName || ' = ' || '''' || itemXref(j).currValue
|| ''' where ' || attribName || '=' || '''' || itemXref(j).oldValue || ''' and (itemsetid = ''' || 'XXXX' || ''' or orgid = ''' || 'YYYYY' || ''' ) ''' '''';
--dbms_output.put_line (itemXref(j).currValue || ' ::::' || itemXref(j).oldValue);
dbms_output.put_line (updateStr || ':: Records to be updated is ' || rowKount);
-- Execute the Update
EXECUTE IMMEDIATE updateStr;
-- Commit changes
updateStr := 'Commit';
EXECUTE IMMEDIATE updateStr;
-- Get count after update - should be none!
EXECUTE IMMEDIATE queryStr into RowKount;
dbms_output.put_line (' Count of records after the update is ' || rowKount);
end loop;
end loop; --for i in allAttribs
end;
Thanks in advance!

Looping with If condition in PL/SQL

I created this block to test three conditions from a table called process. I created the sql query based on the requirements and I inserted it into a FOR LOOP that should return more than a value every time I test a date which matches the date in the process table. My problems with this block is -First: When I test invalid date against the DATE_PO records, I get the ELSE condition, but this starts to loop twice for the number of records in the table process:
anonymous block completed
No records made in this date !
No records made in this date !
The second problem, if no data in this table, how do I make an appropriate condition to test and display a message to the user of no records found?
Table process
NUM DATE_PO STATUS
---------- ----------- -----------
1243 21-DEC-15 CANCEL
5678 21-DEC-15 APPROVE
BEGIN
FOR X IN
(SELECT PO.STATUS,
PO.DATE_PO,
SUM(D.QUANTIY) QUANTITY_SUM,
SUM(NVL(D.QUANTIY,0) * NVL (M.COST,0)) T_VALUE
FROM PROCESS.PO, DELETE_PROCESS, MONEY M
WHERE D.PO = M.PO
AND PO.NUM = D.NUM
GROUP BY PO.STATUS, PO.DATE_PO)
LOOP
IF TO_CHAR(X.DATE_PO, 'mm-yyyy') ='10-2015' THEN --Not valid date
IF X.STATUS ='CANCEL' THEN
DBMS_OUTPUT.PUT_LINE('CANCELLATIONS: ' || X.QUANTITY_SUM );
DBMS_OUTPUT.PUT_LINE('VALUE: '|| X.T_VALUE);
DBMS_OUTPUT.PUT_LINE('DATE: ' || X.DATE_PO );
ELSIF X.STATUS ='HOLD' THEN
DBMS_OUTPUT.PUT_LINE('HOLDS: ' || X.QUANTITY_SUM );
DBMS_OUTPUT.PUT_LINE('VALUE: '|| X.T_VALUE);
DBMS_OUTPUT.PUT_LINE('DATE: ' || X.DATE_PO );
ELSIF X.STATUS = 'APPROVE' THEN
DBMS_OUTPUT.PUT_LINE('APPROVES: ' || X.QUANTITY_SUM );
DBMS_OUTPUT.PUT_LINE('VALUE: '|| X.T_VALUE);
DBMS_OUTPUT.PUT_LINE('DATE: ' || X.DATE_PO );
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('No records made in this date !');
END IF;
END LOOP;
END;
/
Try this. Hope it helps. Though its not the best solution as it can be
done without using ROW-BY-ROW processing. Bulk COLLECT option can also
be used. Let me know if this helps. Since i dont have workspace please
pardon any syntax erros if any.
DECLARE
lv_cnt PLS_INTEGER;
lv_date VARCHAR2(10):='12-2015';
lv_dt DATE;
BEGIN
BEGIN
SELECT TO_DATE(lv_date,'MM-YYYY') INTO lv_dt FROM DUAL;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Not a valid Date');
RETURN;
END;
SELECT COUNT(1)
INTO lv_cnt
FROM
(SELECT PO.STATUS,
PO.DATE_PO,
SUM(D.QUANTIY) QUANTITY_SUM,
SUM(NVL(D.QUANTIY,0) * NVL (M.COST,0)) T_VALUE
FROM PROCESS.PO,
DELETE_PROCESS,
MONEY M
WHERE D.PO = M.PO
AND PO.NUM = D.NUM
GROUP BY PO.STATUS,
PO.DATE_PO
)A;
IF lv_cnt > 0 THEN
FOR X IN
(SELECT PO.STATUS,
PO.DATE_PO,
SUM(D.QUANTIY) QUANTITY_SUM,
SUM(NVL(D.QUANTIY,0) * NVL (M.COST,0)) T_VALUE
FROM PROCESS.PO,
DELETE_PROCESS,
MONEY M
WHERE D.PO = M.PO
AND PO.NUM = D.NUM
GROUP BY PO.STATUS,
PO.DATE_PO
)
LOOP
IF X.STATUS ='CANCEL' THEN
DBMS_OUTPUT.PUT_LINE('CANCELLATIONS: ' || X.QUANTITY_SUM );
DBMS_OUTPUT.PUT_LINE('VALUE: '|| X.T_VALUE);
DBMS_OUTPUT.PUT_LINE('DATE: ' || X.DATE_PO );
ELSIF X.STATUS ='HOLD' THEN
DBMS_OUTPUT.PUT_LINE('HOLDS: ' || X.QUANTITY_SUM );
DBMS_OUTPUT.PUT_LINE('VALUE: '|| X.T_VALUE);
DBMS_OUTPUT.PUT_LINE('DATE: ' || X.DATE_PO );
ELSIF X.STATUS = 'APPROVE' THEN
DBMS_OUTPUT.PUT_LINE('APPROVES: ' || X.QUANTITY_SUM );
DBMS_OUTPUT.PUT_LINE('VALUE: '|| X.T_VALUE);
DBMS_OUTPUT.PUT_LINE('DATE: ' || X.DATE_PO );
END IF;
END LOOP;
ELSIF lv_cnt = 0 THEN
dbms_output.put_line('No records found for the user');
END IF;
END;

How to continue executing code (pl-sql), after capturing an exception

I need to continue with the code execution when exception has been captured.
But my code is exiting when the first exception appeariing, and .
I try simulate an error, for example when not exists the table from the cursor c1, and never run the second part of the code, where it opens c2.
Cursors c1 and c2 look an intermediate table with the names of the tables then processed in the procedure.
Could you give me any idea?
Thankyou in advanced.
Regards.
CREATE OR REPLACE PROCEDURE ISRREP.isr_retention
IS
v_count NUMBER ;--:= 50;
v_commit NUMBER := 50;
str_min VARCHAR2 (100);
str_del_day VARCHAR2 (150);
str_del_month VARCHAR2 (150);
str_lastdate VARCHAR2 (150);
v_lastdate DATE;
v_lastdate_fin DATE;
str_min_fin VARCHAR2 (100);
v_hay_registros NUMBER ; --:= 1;
errno NUMBER;
errmsg VARCHAR2 (255);
str_error VARCHAR2 (300);
str_upd_err VARCHAR2 (300);
v_table1 VARCHAR2 (50);
v_table2 VARCHAR2 (50);
v_table3 VARCHAR2 (50);
v_table4 VARCHAR2 (50);
v_table5 VARCHAR2 (50);
/* armo cursor */
CURSOR c1
IS
SELECT ID, activeflag, errormessage, tablename, retention,
retentionunit, lastdate
FROM isrfrequency_sacme
WHERE activeflag = 'ACTIVE'
AND retentionunit = 'Month'
ORDER BY tablename;
CURSOR c2
IS
SELECT ID, activeflag, errormessage, tablename, retention,
retentionunit, lastdate
FROM isrfrequency_sacme
WHERE activeflag = 'ACTIVE'
AND retentionunit = 'Day'
ORDER BY tablename;
r1 c1%ROWTYPE;
r2 c2%ROWTYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1
INTO r1;
EXIT WHEN c1%NOTFOUND;
str_min := 'select min(utctime) from ' || r1.tablename; --Obtengo fecha y hora mas antigua
EXECUTE IMMEDIATE str_min INTO v_lastdate;
--Tablas con retencionunit Month
BEGIN
r1.retentionunit := 'Month';
str_del_month := 'delete '|| r1.tablename
|| ' where UTCTIME < ADD_MONTHS(sysdate,-' --|| ' where UTCTIME < trunc(ADD_MONTHS(sysdate,-'
|| r1.RETENTION
|| ')'; --Delete de registros que exceden la retencion
EXECUTE IMMEDIATE str_del_month;
v_table1 := r1.tablename;
v_hay_registros := SQL%ROWCOUNT;
IF v_hay_registros != 0
THEN
COMMIT;
END IF;
str_min_fin := 'select min(utctime) from ' || r1.tablename; --Obtengo nuevamente fecha y hora mas antigua
EXECUTE IMMEDIATE str_min_fin INTO v_lastdate_fin;
str_lastdate :=
'update ISRFREQUENCY_SACME set LASTDATE = TO_DATE('''
|| v_lastdate_fin
|| ''',''DD/MM/YYYY HH24:MI:SS'') where tablename = '''
|| r1.tablename
|| ''''; --Update en tabla ISRFREQUENCY_SACME con el ultimo valor leido
--DBMS_OUTPUT.put_line (str_lastdate);
EXECUTE IMMEDIATE str_lastdate;
--
-- EXEPCIONES PARCIALES
--
EXCEPTION
WHEN OTHERS
THEN
errno := SQLCODE;
errmsg := SQLERRM;
test_debug.p_test_debug_out ('ISR_RETENTION', errmsg, 'NO');
update isrfrequency_sacme set activeflag = 'ERROR', errormessage = errmsg where tablename = r1.tablename;
commit;
DBMS_OUTPUT.put_line ('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
DBMS_OUTPUT.put_line ( 'ERROR: '|| errmsg || '. ISRFREQUENCY_SACME.MESSAGGE');
DBMS_OUTPUT.put_line ('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
DBMS_OUTPUT.PUT_LINE('Se ha producido una excepción.');
DBMS_OUTPUT.PUT_LINE('Error code: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('Error message: ' || SQLERRM);
END;
END LOOP;
CLOSE c1;
--Tablas con retencionunit Day
OPEN c2;
LOOP
FETCH c2
INTO r2;
EXIT WHEN c2%NOTFOUND;
BEGIN
r1.retentionunit := 'Day';
str_del_day :=
'delete '
|| r2.tablename
|| ' where UTCTIME < trunc(sysdate-'
|| r2.RETENTION
|| ')'; --Delete de registros que exceden la retencion
EXECUTE IMMEDIATE str_del_day;
v_table2 := r2.tablename;
v_hay_registros := SQL%ROWCOUNT;
--v_hay_registros := v_count;
IF v_hay_registros != 0
--IF v_count != 0
THEN
COMMIT;
ELSE
END IF;
str_min_fin := 'select min(utctime) from ' || r2.tablename; --Obtengo nuevamente fecha y hora mas antigua
EXECUTE IMMEDIATE str_min_fin INTO v_lastdate_fin;
str_lastdate :=
'update ISRFREQUENCY_SACME set LASTDATE = TO_DATE('''
|| v_lastdate_fin
|| ''',''DD/MM/YYYY HH24:MI:SS'') where tablename = '''
|| r2.tablename
|| ''''; --Update en tabla ISRFREQUENCY_SACME con el ultimo valor UTCTIME, luego del delete
--DBMS_OUTPUT.put_line (str_lastdate);
EXECUTE IMMEDIATE str_lastdate;
--
-- EXEPCIONES PARCIALES
--
EXCEPTION
WHEN OTHERS
THEN
errno := SQLCODE;
errmsg := SQLERRM;
test_debug.p_test_debug_out ('ISR_RETENTION', errmsg, 'NO');
update isrfrequency_sacme set activeflag = 'ERROR', errormessage = errmsg where tablename = r2.tablename;
commit;
DBMS_OUTPUT.put_line ('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
DBMS_OUTPUT.put_line ( 'ERROR: '|| errmsg || '. ISRFREQUENCY_SACME.MESSAGGE');
DBMS_OUTPUT.put_line ('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
DBMS_OUTPUT.PUT_LINE('Se ha producido una excepción.');
DBMS_OUTPUT.PUT_LINE('Error code: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('Error message: ' || SQLERRM);
--NULL;
END;
END LOOP;
CLOSE c2;
--
-- EXEPCIONES FINALES
--
EXCEPTION
WHEN OTHERS
THEN
errno := SQLCODE;
errmsg := SQLERRM;
test_debug.p_test_debug_out ('ISR_RETENTION', errmsg, 'NO');
update isrfrequency_sacme set activeflag = 'ERROR', errormessage = errmsg where tablename = r1.tablename;
commit;
DBMS_OUTPUT.put_line ('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
DBMS_OUTPUT.put_line ( 'ERROR: '|| errmsg || '. ISRFREQUENCY_SACME.MESSAGGE');
DBMS_OUTPUT.put_line ('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
DBMS_OUTPUT.PUT_LINE('Se ha producido una excepción.');
DBMS_OUTPUT.PUT_LINE('Error code: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('Error message: ' || SQLERRM);
END;
/

Resources