Problem: when using an implicit cursor such as selectintofromtablename, if data is not found, an error in the ora-01403 is reported. Each time an explicit cursor is used,
Problem: when using an implicit cursor like select into from tablename, if no data is found, an error in the ora-01403 is reported. Each time an explicit cursor is used,
Problem: when using an implicit cursor like select into from tablename, if no data is found, an error in the ora-01403 is reported. Each time an explicit cursor is used, it is very troublesome to open the value. An experienced instructor suggested using aggregate functions like max min to avoid exceptions caused by select into and the trouble of using cursors each time.
Efficiency and feasibility tests:
① Temporary table
Create table edu. TEST
(
ID NUMBER NULL
)
TABLESPACE EDUCATION
NOLOGGING
PCTFREE 10
PCTUSED 0
INITRANS 1
MAXTRANS 255
STORAGE (BUFFER_POOL DEFAULT)
NOPARALLEL
NOCACHE
② PL/SQL block Testing
A. create or replace procedure proc_max (id varchar2)
As
Var dba_tables.table_name % type: = null;
V_err_code number (10 );
V_err_txt varchar2 (400 );
Begin
Select max (d. table_name)
Into var
From dba_tables d
Where d. OWNER = 'jf'
And d. TABLE_NAME = 'orgconnection1012' | id;
If var is not null
Then
Insert into test values (id );
Commit;
End if;
Exception
When others then
V_err_code: = sqlcode;
V_err_txt: = 'test: '| sqlerrm | DBMS_UTILITY.format_error_backtrace ();
Insert into proc_err_logs (code, message, info, occur_date)
Values (v_err_code, v_err_txt, 'exception', SYSDATE );
Commit;
End;
/
Create or replace procedure proc_cur (id varchar2)
As
Var dba_tables.table_name % type: = null;
V_err_code number (10 );
V_err_txt varchar2 (400 );
Type cursor_type is ref cursor;
Cur cursor_type;
Begin
Open cur
Select d. table_name
From dba_tables d
Where d. OWNER = 'jf'
And d. TABLE_NAME = 'orgconnection1012' | id;
Fetch cur into var;
Close cur;
If var is not null then
Insert into test
Values (id );
Commit;
End if;
Exception
When others then
V_err_code: = sqlcode;
V_err_txt: = 'test: '| sqlerrm | DBMS_UTILITY.format_error_backtrace ();
Insert into proc_err_logs (code, message, info, occur_date)
Values (v_err_code, v_err_txt, 'exception', SYSDATE );
Commit;
End;
B,
Create or replace procedure proc_test_max (var in number)
As
V_err_code number (10 );
V_err_txt varchar2 (400 );
V_begin_time timestamp;
V_end_time timestamp;
Begin
Select current_timestamp into v_begin_time from dual;
For I in 1 .. var loop
Proc_max (I );
End loop;
Select current_timestamp into v_end_time from dual;
Insert into proc_use_times (PROC_NAME,
PROC_DESC,
BEGIN_TIME,
END_TIME)
Values ('proc _ test_max ', 'test' | var, v_begin_time, v_end_time );
Commit;
Exception
When others then
V_err_code: = sqlcode;
V_err_txt: = 'test max: '| var | sqlerrm | DBMS_UTILITY.format_error_backtrace ();
Insert into proc_err_logs (code, message, info, occur_date)
Values (v_err_code, v_err_txt, 'exception', SYSDATE );
End;