PL/SQL procedure stuck - oracle

I have the following scenario:
Java servlet calls PL/SQL procedure and waits for return value.
The PL/SQL procedure calls other PL/SQL procedures that do a series of updates, inserts and commits. When everything completes the initial PL/SQL procedure writes a log using pragma and returns 1 if successful.
The problem is that on one environment everything works fine and on another environment the PL/SQL procedure remains stuck(same code and data on both environments).
PL/SQL procedure ex:
PROCEDURE Export_1511_PDH_Physic ( o_ErrorCode OUT NUMBER,
o_ErrorText OUT VARCHAR2,
o_Resultat OUT NUMBER) is
GlobalExportID NUMBER;
BEGIN
ASYNCLOG ('Export_1511_PDH_Physic', 'Started');--Pragma writing logs
GlobalExportID :=0;
o_Resultat := 0;
select nvl(max(exportid),0) into GlobalExportID from async.MaxNodeList;
GlobalExportID := GlobalExportID + 1;
upd_JRLExport('1511Max Export', GlobalExportID, 0);--Pragma writing logs
pkggato.MaxIRM_DoExport(GlobalExportID); ---more pl/sql procedures(update, insert...)
o_Resultat := o_Resultat+1;
Everithing printed ok below.
pkgdebug.writelog('o_ErrorCode - ' || o_ErrorCode,'Info');
pkgdebug.writelog('o_ErrorTex - ' || o_ErrorText,'Info');
pkgdebug.writelog('o_Resultat - ' || o_Resultat,'Info');
The below logs are printed fine.
ASYNCLOG ('Export_1511_PDH_Physic', 'Finished'); --Pragma writing logs
upd_JRLExport('1511Max Export', GlobalExportID, 1); --Pragma writing logs
END;
If a do a DB restart everything works fine on the 1st run.
Any idea on how to debug this?
PROCEDURE upd_JRLExport(pis_export_type ASYNC_JRLEXPORT.EXPORTTYPE%TYPE,
pin_export_no ASYNC_JRLEXPORT.NO_EXPORT%TYPE,
pin_start_end_flg NUMBER, --0: Start / 1: End
pin_status ASYNC_JRLEXPORT.STATUS%TYPE DEFAULT NULL)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
ld_now DATE;
BEGIN
SELECT SYSDATE
INTO ld_now
FROM DUAL;
UPDATE ASYNC_JRLEXPORT
SET START_DATE = DECODE(pin_start_end_flg, 0, ld_now, START_DATE),
END_DATE = DECODE(pin_start_end_flg, 1, ld_now, END_DATE),
NO_EXPORT = NVL(pin_export_no, NO_EXPORT),
STATUS = NVL(pin_status, STATUS)
WHERE EXPORTTYPE = pis_export_type;
COMMIT;
END upd_JRLExport;
Thanks,
Catalin.

PROCEDURE upd_JRLExport(pis_export_type ASYNC_JRLEXPORT.EXPORTTYPE%TYPE,
pin_export_no ASYNC_JRLEXPORT.NO_EXPORT%TYPE,
pin_start_end_flg NUMBER, --0: Start / 1: End
pin_status ASYNC_JRLEXPORT.STATUS%TYPE DEFAULT NULL)
IS
V_ERRORMESSAGE varchar2(2000);
PRAGMA AUTONOMOUS_TRANSACTION;
ld_now DATE;
BEGIN
SELECT SYSDATE
INTO ld_now
FROM DUAL;
UPDATE ASYNC_JRLEXPORT
SET START_DATE = DECODE(pin_start_end_flg, 0, ld_now, START_DATE),
END_DATE = DECODE(pin_start_end_flg, 1, ld_now, END_DATE),
NO_EXPORT = NVL(pin_export_no, NO_EXPORT),
STATUS = NVL(pin_status, STATUS)
WHERE EXPORTTYPE = pis_export_type;
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
V_ERRORMESSAGE := SQLERRM;
dbms_output.put_line('NO DATA FOUND :' || V_ERRORMESSAGE);
RAISE;
WHEN OTHERS
THEN
V_ERRORMESSAGE := SQLERRM;
dbms_output.put_line('OTHER ERROR :' || V_ERRORMESSAGE);
RAISE;
END upd_JRLExport;

Related

PL/SQL exception handling - log errors

How do I record the oracle error in a pl/sql script? I have been to the oracle error handling documentation and I see the built in exceptions, but what if I do not know what the exception is? How can I log this in an exception block?
I want to do something like the below.
exception
when others then DBMS_OUTPUT.PUT_LINE(the error)
It's easier to create error logging database trigger with conditional logging, for example my actual error_logging trigger: https://github.com/xtender/xt_scripts/blob/master/error_logging/on_database.sql
create table ERROR_LOG
(
id NUMBER,
username VARCHAR2(30),
errcode INTEGER,
seq INTEGER,
tmstmp TIMESTAMP(6),
msg VARCHAR2(4000),
sql_text CLOB
)
/
create sequence err_seq
/
create or replace trigger trg_error_logging
after servererror
on database
disable
declare
v_id number := err_seq.nextval();
v_tmstmp timestamp:= systimestamp;
n int;
sql_text dbms_standard.ora_name_list_t;
v_sql_text clob;
begin
-- only if plsql_debug is set to TRUE:
for r in (select * from v$parameter p where p.name='plsql_debug' and upper(p.value)='TRUE') loop
v_sql_text:=null;
n := ora_sql_txt(sql_text);
for i in 1..n loop
v_sql_text := v_sql_text || sql_text(i);
end loop;
for i in 1.. ora_server_error_depth
loop
if i=1 then
insert into error_log(id,seq,tmstmp,username,errcode,msg,sql_text)
values( v_id, i, v_tmstmp, user, ora_server_error(i), ora_server_error_msg(i), v_sql_text);
else
insert into error_log(id,seq,tmstmp,username,errcode,msg)
values( v_id, i, v_tmstmp, user, ora_server_error(i), ora_server_error_msg(i) );
end if;
end loop;
commit;
end loop;
END;
/
select object_name,object_type,status from user_objects o where object_name='TRG_ERROR_LOGGING'
/
alter trigger trg_error_logging enable
/
As you can see it logs all errors into the table ERROR_LOG, but only if session parameter plsql_debug is set to true. Obviously, you can change it to own parameters or conditions.

ORA-24344: success with compilation error when trying to implement holt winter procedure

I'm getting the ORA-24344: success with compilation error whenever i try to import an application(that works on my database) to the oracle apex cloud or any other local cloud, the same error appears ORA-24344: success with compilation but when i run the application it runs but this procedure (holt_winters) does not run, no errors it just doesn't do anything.
here is my code. its a holt winters prediction method for those of you who're interested.
any help would be apperciated
create or replace PROCEDURE "HOLT_WINTERS" (report_id_in IN INTEGER
, alpha IN VARCHAR2
, beta IN VARCHAR2
, gamma IN VARCHAR2
, prediction_step IN VARCHAR2
, seasonality IN VARCHAR2
, from_date IN varchar2
, to_date IN varchar2
, FDEW_ID IN integer) AS
BEGIN
begin
-- delete previous settings
delete from demo_ts_settings where report_id_in > 0;
-- select ESM as the algorithm
insert into demo_ts_settings
values (dbms_data_mining.algo_name,
dbms_data_mining.algo_exponential_smoothing);
-- set ESM model to be Holt-Winters Seasonal Adjusted
insert into demo_ts_settings
values (dbms_data_mining.exsm_model,
dbms_data_mining.exsm_HW_ADDSEA);
-- set interval to be month
insert into demo_ts_settings
values (dbms_data_mining.exsm_interval,
dbms_data_mining.exsm_interval_month);
-- set prediction to 4 steps ahead
insert into demo_ts_settings
values (dbms_data_mining.exsm_prediction_step,
prediction_step);
-- set seasonal cycle to be 5 quarters
insert into demo_ts_settings
values (dbms_data_mining.exsm_seasonality,
seasonality);
BEGIN
dbms_data_mining.drop_model('DEMO_TS_MODEL_' || report_id_in);
EXCEPTION
WHEN others THEN null;
END;
EXECUTE IMMEDIATE 'create view holt_winters_temp_table_'||report_id_in|| ' as select RATES.*
from RATES
where (DATE_OF_RECORD between to_date('''|| from_date ||''', ''YYYY-MM-DD'') ' ||
'and to_date('''||to_date||''', ''YYYY-MM-DD'') )
and STATUS = ''FALSE''
and report_id ='|| report_id_in;
dbms_data_mining.create_model(model_name => 'DEMO_TS_MODEL_' || report_id_in,
mining_function => 'TIME_SERIES',
data_table_name => 'holt_winters_temp_table_' || report_id_in,
case_id_column_name => 'date_of_record',
target_column_name => 'VAL',
settings_table_name => 'DEMO_TS_SETTINGS');
BEGIN
FOR i IN 1..5
LOOP
BEGIN
sys.DBMS_SESSION.sleep(20);
INSERT_HOLT_HISTORY('DM$PPDEMO_TS_MODEL_' || report_id_in);
COMMIT;
EXIT;
EXCEPTION
WHEN others THEN null;
DBMS_OUTPUT.PUT_LINE (SQLCODE || ' ' || SQLERRM);
END; -- sub-block ends
END LOOP;
END;
end;
END HOLT_WINTERS;

Cannot insert Third column of data

I am noob in PL/SQL I just start learning and I want to create small peace of software that insert data from .CVS file to Oracle database.
And I stuck in part where I grab data from .CVS file.
I my CVS there are three column: Number_Policy,Contact, Agency
Number_Policy,Contact is catch success, but Agency can not be catched and I dont know why
declare
import_file text_io.file_type;
export_file text_io.file_type;
import_file_name varchar2(1000);
export_file_name varchar2(1000);
import_log_file text_io.file_type;
import_log_file_name varchar2(1000);
vec_importovano number;
brojac number;
brojac_redova number;
linebuf varchar2(10000);
p_rbr varchar2(20);
p_polica varchar2(20);
p_banka VARCHAR2(50);
p_kontakt varchar2(20);
kraj_fajla number;
begin
brojac_redova:=0;
import_file_name := :Global.Lokacija_prenosa||:import.naziv_fajla||:Global.Ekstenzija_prenosa;
import_file := text_io.fopen(import_file_name,'r');
delete from zivot_trajni_nalog_ponude where banka is not null;
commit;
kraj_fajla := 0;
while kraj_fajla = 0 loop
begin
brojac_redova:=brojac_redova+1;
text_io.get_line(import_file, linebuf);
if brojac_redova >= 2 then
p_polica:=substr(linebuf, 1, instr(linebuf,';',1,1)-1);
-- message(p_polica);
p_kontakt:=substr(linebuf, instr(linebuf,';',1,1)+1, instr(linebuf,';',1,2) - instr(linebuf,';',1,1)-1);
p_banka:=substr(linebuf, instr(linebuf,';',1,2)+1, instr(linebuf,';',1,3) - instr(linebuf,';',1,2)-1);
-- message(p_banka);
--p_kontakt:=substr(linebuf, instr(linebuf,';',1,1)+1, instr(linebuf,';',1,2) - instr(linebuf,';',1,1)-1);
-- message(p_kontakt);
/*
p_rbr:=substr(linebuf, 1, instr(linebuf,';',1,1)-1);
-- message(p_rbr);
p_polica:=substr(linebuf, instr(linebuf,';',1,1)+1, instr(linebuf,';',1,2) - instr(linebuf,';',1,1)-1);
-- message(p_polica);
p_banka:=substr(linebuf, instr(linebuf,';',1,2)+1, instr(linebuf,';',1,3) - instr(linebuf,';',1,2)-1);
message(p_banka);
p_kontakt:=substr(linebuf, instr(linebuf,';',1,3)+1, instr(linebuf,';',1,4) - instr(linebuf,';',1,3)-1);
message(p_kontakt);
*/
if vec_importovano = 0 then
insert into ZIVOT_TRAJNI_NALOG_PONUDE
(BROJ_POLICE,BROJ_PONUDE)
values(
p_polica,
--p_rbr,
p_kontakt);
-- p_banka);
commit;
end if;
end if;
EXCEPTION WHEN NO_DATA_FOUND THEN kraj_fajla := 1;
end;
end loop;
IF p_polica IS NOT NULL
THEN
update zivot_trajni_nalog_ponude set BROJ_POLICE=rownum;
commit;
END IF;
text_io.fclose(import_file);
message ('Uspjesno zavrseno');
end;
As you can see from code there is error somewhere here
p_banka:=substr(linebuf, instr(linebuf,';',1,2)+1, instr(linebuf,';',1,3) - instr(linebuf,';',1,2)-1);
-- message(p_banka);
After I disable this column the problem is that column p_polica and p_kontakt can't be inserted into database.
If anyone know where I made mistake I would be very thankful for any help.
Looks like linebuf has only two semicolons. This piece of code worked in my short test:
if instr(linebuf,';',1,3) > 0 then
p_banka := substr(linebuf,
instr(linebuf,';',1, 2) + 1,
instr(linebuf,';',1,3) - instr(linebuf,';',1,2)-1);
else
p_banka := substr(linebuf,
instr(linebuf,';',1, 2) + 1);
end if;

WHEN-BUTTON-PRESSED trigger raise unhendled exception ORA-01407

I am new in PL SQL and I am trying to resolve problem with copy-past data from .CVS file to database
I create a small application which will take data from .CVS and past it to database.
I create a method, but after I compile it's writtend Successfully compiled
But when I run form I get error
WHEN-BUTTON-PRESSED trigger raise unhendled exception ORA-01407
Does anyone know what this means since I google it and could not find anything ?
I would be very thankfull
declare
import_file text_io.file_type;
import_file_name varchar2(1000);
import_log_file text_io.file_type;
import_log_file_name varchar2(1000);
vec_importovano number;
brojac number;
brojac_redova number;
linebuf varchar2(5000);
p_rbr varchar2(4);
p_polica varchar2(20);
p_banka varchar2 (20);
p_kontakt varchar2(20);
kraj_fajla number;
begin
import_file_name := :Global.Lokacija_prenosa||:import.naziv_fajla||:Global.Ekstenzija_prenosa;
import_file := text_io.fopen(import_file_name,'r');
--p_rbr := 100000;
delete from zivot_trajni_nalog_ponude where banka is not null;
commit;
kraj_fajla := 0;
while kraj_fajla = 0 loop
begin
text_io.get_line(import_file, linebuf);
if brojac_redova>=2 then
if length(linebuf)>100 then
p_rbr:=substr(linebuf, 1, instr(linebuf,';',1,1)-1);
p_polica:=substr(linebuf, instr(linebuf,';',1,1)+1, instr(linebuf,';',1,2) - instr(linebuf,';',1,1)-1);
p_banka:=substr(linebuf, instr(linebuf,';',1,2)+1, instr(linebuf,';',1,3) - instr(linebuf,';',1,2)-1);
p_kontakt:=substr(linebuf, instr(linebuf,';',1,3)+1, instr(linebuf,';',1,4) - instr(linebuf,';',1,3)-1);
select count(*)
into vec_importovano
from ZIVOT_TRAJNI_NALOG_PONUDE
where broj_police=p_polica and p_rbr=redni_broj;
if vec_importovano=0 then
insert into ZIVOT_TRAJNI_NALOG_PONUDE values(p_rbr, p_polica, p_banka, p_kontakt);
commit;
end if;
end if;
end if;
EXCEPTION WHEN NO_DATA_FOUND THEN kraj_fajla := 1;
end;
end loop;
update zivot_trajni_nalog_ponude set redni_broj = p_rbr;
commit;
text_io.fclose(import_file);
message('Zavrseno prepisivanje fajla');
end;
The error you got (ORA-01407) means that you are trying to update a column (which is set to NOT NULL) with a NULL value. That won't work. For example:
SQL> create table test (id number not null);
Table created.
SQL> insert into test (id) values (100);
1 row created.
SQL> update test set id = null;
update test set id = null
*
ERROR at line 1:
ORA-01407: cannot update ("SCOTT"."TEST"."ID") to NULL
SQL>
The only UPDATE in your code is this:
UPDATE zivot_trajni_nalog_ponude SET redni_broj = p_rbr;
Apparently, p_rbr is NULL, redni_broj won't accept it and you got the error.
What to do? Debug your code and see why p_rbr doesn't have a value. A simple "solution" might be
IF p_rbr IS NOT NULL
THEN
UPDATE zivot_trajni_nalog_ponude
SET redni_broj = p_rbr;
END IF;
Also, although not related to your problem: don't COMMIT within a loop.
ORA-01407 occurs as you are trying to update/Insert a column to NULL
when the column does not accept NULL values.
To find all the "not null" columns in table ZIVOT_TRAJNI_NALOG_PONUDE, Please check the DDL of the table.

plsql stored procedure syntax error

when I try the following code, I get a procedure completed with 0 compilation errors.. message instead of procedure successfully completed message.
what's wrong with this? and help me in correcting this error
CREATE OR REPLACE PROCEDURE omar_manager_report1 (
pi_co_id IN VARCHAR2, -- Company ID
pi_cntr_nbr IN NUMBER DEFAULT 0,
-- if Contract number is passed then Case 1: will be executed
pi_overdue_days IN NUMBER DEFAULT 0,
--No of days related to Over due of application passed.
po_var_ref OUT sys_refcursor
)
IS
lv_query VARCHAR2(400) ;
lv_co_id VARCHAR2 (200);
BEGIN
lv_co_id := REPLACE (pi_co_id, ',', ''',''');
--Default option for all group office
lv_query :=
'select distinct gue.co_id,
(SELECT event_descp FROM get_event WHERE co_id = gue.co_id AND event_cd = gue.event_cd) AS event_desc
FROM get_uwtg_event gue';
DBMS_OUTPUT.put_line ('lv_query');
OPEN po_var_ref FOR lv_query;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (SQLCODE);
END;
/
Executing a CREATE OR REPLACE PROCEDURE... statement compiles the procedure, but it does not call the procedure. You'll need to write a PL/SQL block similar to the following to invoke your procedure:
DECLARE
csrOut SYS_REFCURSOR;
BEGIN
omar_manager_report1(pi_co_id => '123456',
pi_cntr_nbr => 0,
pi_overdue_days => 0,
po_var_ref => csrOut);
-- Add code here to fetch from csrOut and use the results appropriately
-- Close the cursor opened by omar_manager_report1
CLOSE csrOut;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Exception: ' || SQLCODE || ' : ' || SQLERRM);
END;
Best of luck.

Resources