Oracle 儲存過程建立 執行 排錯

2021-08-20 05:02:31 字數 1909 閱讀 9271

1、建立儲存過程

create or replace procedure p_desk_info(v_desk_name in varchar2,v_desk_type in varchar2,v_desk_no in varchar2,v_org_name in varchar2) is 

begin

declare

org_id number;

desk_type_id number;

desk_num number;

global_ex exception;

begin

begin

select id into desk_type_id from t_base_desk_type where deleted='n' and desk_type=v_desk_type;

exception

when no_data_found then

dbms_output.put_line('錯誤:請檢查臺席型別【'||v_desk_type||'】是否存在,並重新匯入該台席資訊');

end;

begin

select id into org_id from t_sys_organization where deleted='n' and type=8 and org_name=v_org_name;

exception

when no_data_found then

dbms_output.put_line('錯誤:請檢查使用單位【'||v_org_name||'】是否存在,並重新匯入該台席資訊');

end;

--臺席不存在或使用單位不存在丟擲異常

if desk_type_id is null or org_id is null then

raise global_ex;

end if;

select count(*) into desk_num from t_base_desk_info t where t.deleted='n' and t.name=v_desk_name and t.type_id=desk_type_id and t.serial_number=v_desk_no and t.org_id=org_id;

--已存在臺席資訊丟擲異常

if desk_num is not null then

dbms_output.put_line('錯誤:請臺席【'||v_desk_name||'】資訊已存在');

raise global_ex;

end if;

insert into t_base_desk_info (id,name,type_id,serial_number,org_id,deleted,create_user_name,create_user_id,create_date)

values (seq_t_base_desk_info.nextval, v_desk_name,desk_type_id,v_desk_no,org_id,'n','小明',1,sysdate);

commit;

exception

when others then

dbms_output.put_line('錯誤:新增臺席【'||v_desk_name||'】資訊失敗');

end;

end p_desk_info;

/

2、排錯命令

show errors
3、檢視執行結果

set serveroutput on;

exec p_desk_info('臺席','高櫃','09','支局');

oracle 賦值儲存過程的建立和執行

建立儲存過程 create or replace procedure insert student asstudent id number student name varchar2 20 student varchar2 20 student age number student departme...

ORACLE 儲存過程動態執行SQL建立表備份

1.需求 定時將資料庫中某個表的資料 進行備份 類似 create table bak as select from table name 這樣的建立表的語句 是不允許直接在儲存過程中填寫的。解決 execute immediate create or replace procedure psn b...

oracle儲存過程 建立儲存過程語句

一 建立儲存過程語句 語法 create or replace procedure testname argument1 type1,as begin end testname 例子 create orreplace procedure test name arg1 varchar2,arg2 nu...