標籤:blog http io strong for ar cti log
1、ORA-00942: table or view does not exist 指的你要操作的表尚未存在,需要先create出來先。
2、ORA-00922: missing or invalid option 指的是有語法錯誤。遺漏了分號什麼的
3、Warning: Procedure created with compilation errors
比如 create or replace procedure p_test_pro1 is begin insert into loginuser(username,passwd) values(‘admin‘,‘123‘); end -------這裡遺漏了分號 / Warning: Procedure created with compilation errors SQL> show error --顯示出具體的錯誤所在 Errors for PROCEDURE SCOTT.P_TEST_PRO1: LINE/COL ERROR -------- ---------------------------------------------------------------------------------------------------- 6/0 PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ; <an identifier> <a double-quoted delimited-identifier> delete exists prior <a single-quoted SQL string> The symbol ";" was substituted for "end-of-file" to continue.
4、ORA-06576: not a valid function or procedure name 預存程序p_test_pro1尚未建立
call p_test_pro1 ORA-06576: not a valid function or procedure name
5、ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at "SCOTT.P_TEST_PRO1", line 6 ORA-06512: at line 2
create or replace procedure p_test_pro1 IS v_pass varchar2(20); begin select passwd into v_pass from loginuser where rownum=1; dbms_output.put_line(‘密碼是:‘+v_pass); end;
當調用p_test_pro1的時候報以上錯誤,把輸出語句中的+改為||
在談預存程序書寫中的一些規則時,先看一下執行它的規則,在命令視窗執行預存程序sp_get_product_prompt set serveroutput on var ret1 varchar2(200); var ret2 varchar2(200); exec sp_get_product_prompt(83,:ret1,:ret2); --或execute print ret1; print ret2; 或 set serveroutput on declare ret1 varchar2(200); ret2 varchar2(200); begin sp_get_product_prompt(83,ret1,ret2); dbms_output.put_line(ret1); dbms_output.put_line(ret2); end;
預存程序入參,不論類型,預設情況下值都為null,入參和出參不能有長度,其中關鍵字as可以替換成is,預存程序中變數聲明在as和begin之間,同時,預存程序中可以再調用其它的預存程序,如果要保證預存程序之間的交易處理不受影響,可以定義為自治事務。 create or replace procedure say_hello( v_name in varchar2, v_flag number, o_ret out number ) as begin if v_name is null and v_flag is null then --v_name和v_flag都等於null o_ret := 10; else o_ret := 100; end if; end;
對於入參為null情況下給予預設值 create or replace procedure say_hello( i_name in varchar2, i_flag number, o_ret out number ) as v_name varchar2(100); begin if i_name is null then v_name := ‘0‘; else v_name := i_name; end if; insert into phone(..,wname..,) values(..,v_name,..); end; 或直接在insert語句中調用nvl函數賦預設值 insert into phone(..,wname..,) values(..,nvl(v_name,‘ ‘),..); ----如果將‘ ‘寫成‘‘,則insert進來的v_name值還是為‘‘等價於null值
帶一個參數的預存程序 輸入參數in,輸入參數不能進行:=賦值,但可以將它賦給as後面定義的變數; 輸入參數in,可以作為變數進行條件判斷; 預設不寫就是in; 預存程序沒有重載,這個有參的say_hello會替代已經存在的無參say_hello。
create or replace procedure say_hello(v_name in varchar2) as begin --v_name:=‘a‘; --預存程序入參v_name不能做為賦值目標 dbms_output.put_line(‘hello ‘||v_name); end;
預存程序輸入參數作為變數進行條件判斷 create or replace procedure say_hello( i_opFlag in number ) as v_name varchar2(100); begin if i_opFlag = 1 then v_name :=‘0‘; else v_name :=‘haha‘; end if; dbms_output.put_line(‘hello ‘||v_name); end;
利用預存程序中定義的變數對入參的空值處理: create or replace procedure say_hello( i_name in varchar2 ) as v_name varchar2(100); begin if i_name is null then v_name :=‘0‘; else v_name :=i_name;--將入賦值給定義變數 end if; dbms_output.put_line(‘hello ‘||v_name); end;
多個參數的預存程序 create or replace procedure say_hello( v_first_name in varchar2, v_last_name in varchar2) as begin dbms_output.put_line(‘hello ‘||v_first_name||‘.‘||v_last_name); end;
out輸出參數,用於利用預存程序給一個或多個變數賦值,類似於傳回值 create or replace procedure say_hello( v_name in varchar2, v_content out varchar2 ) begin v_content:=‘hello‘||v_name; end;
調用: declare v_con varchar2(200); v_in varchar2(20):=‘wang‘; begin say_hello(v_in,v_con); dbms_output.put_line(v_con); end;
in out參數,既賦值又取值 create or replace procedure say_hello(v_name in out varchar2) as begin v_name:=‘hi ‘||v_name; end;
調用: declare v_inout varchar2(20):=‘wangsu‘; begin say_hello(v_inout); dbms_output.put_line(v_inout); end;
對預存程序入參賦預設值 create or replace procedure say_hello( v_name varchar2 default ‘susu‘, v_content varchar2 default ‘hello‘ ) as begin dbms_output.put_line(v_name||‘ ‘||v_content); end;
調用:(用指明形參名的方式調用更好) begin say_hello(); end; 或 begin say_hello(‘cheng‘); end; 或 begin say_hello(v_name=>‘cheng‘); end;
http://regedit-123.iteye.com/blog/1075151