ORA-06550:第 6 行,第 31 列:PLS-00103:遇到符號“)”
預期以下情況之一時:(
我不知道如何管理錯誤
create or replace PROCEDURE Get_StarInfo(Stars in out starsin.starname%type, cnt out integer, avg out float)
is
begin
select starname, count(title), avg(length) into Stars, cnt, avg
from starsin, movie
where movietitle=title
and movieyear=year
and starname=Stars
group by starname;
exception
when others then
cnt := -1;
avg := -1;
end;
declare
Stars starsin.starname%type := 'harrison ford';
cnt integer:=3;
avg float:=3.1;
begin
get_starinfo(Stars,cnt,avg);
end;
uj5u.com熱心網友回復:
正如 Alex 評論的那樣,呼叫與內置函式相同的變數或引數是一個壞主意。雖然,你可以讓它作業,但是 - 你寧愿不那樣做。
我沒有你的表,所以我使用 Scott 的示例模式,emp根據部門編號(那是你的“星星”)從它的表中計算一些值。
SQL> create or replace PROCEDURE Get_StarInfo(Stars in out number, cnt out integer, avg out float)
2 is
3 begin
4 select deptno, count(*), avg(sal)/20 into Stars, cnt, avg
5 from emp
6 where deptno = stars
7 group by deptno;
8 exception
9 when others then
10 cnt := -1;
11 avg := -1;
12 end;
13 /
Procedure created.
這就是您呼叫它并得到錯誤的方式:
SQL> set serveroutput on;
SQL> declare
2 Stars number := 10;
3 cnt integer; -- :=3;
4 avg float; -- :=3.1;
5 begin
6 get_starinfo(Stars,cnt,avg);
7 dbms_output.put_line('count = ' || cnt ||', average = ' || "AVG");
8 end;
9 /
get_starinfo(Stars,cnt,avg);
* --> see where the asterisk points to? That's where the error is!
ERROR at line 6:
ORA-06550: line 6, column 31:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
(
ORA-06550: line 8, column 4:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the
following:
end not pragma final instantiable persistable order
overriding static member constructor map
SQL>
現在,如何使用你的“平均”:
- 附注:區域變數(第 3 行
cnt和avg第 4 行)應該接受程序回傳的值,因此設定它們的初始值沒有意義 - 默認情況下,Oracle 對物件名、列名等使用大寫,所以 - 如果你
avg用雙引號括起來并切換到大寫(第 6 行),就不會再出現錯誤了
所以:
SQL> set serveroutput on;
SQL> declare
2 Stars number := 10;
3 cnt integer; -- :=3;
4 avg float; -- :=3.1;
5 begin
6 get_starinfo(Stars,cnt,"AVG");
7 dbms_output.put_line('count = ' || cnt ||', average = ' || "AVG");
8 end;
9 /
count = 3, average = 145.835
PL/SQL procedure successfully completed.
SQL>
再一次:按照建議,不要那樣做。我們通常做的,就是使用前綴(比如v_for " variable " or for l_" local variable" or p_for " parameter "等)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/516040.html
標籤:sql甲骨文
