PLS-00103:在期望以下之一时遇到符号 "END"::= 。 ( % ; 符号“;”被替换为 "END" 以继续
PLS-00103: Encountered the symbol "END" when expecting one of the following: := . ( % ; The symbol ";" was substituted for "END" to continue
您好,我刚开始学习 PLSQL,目前遇到此错误,但我不确定是什么导致了这个问题。
对于我的作业,我应该创建一个 PLSQL 过程,该过程接受用户输入 x 到 return 国家及其各自地区的列表。
R_NAME
N_NAME
COUNT(S_NATIONKEY)
ASIA
INDONESIA
131
ASIA
CHINA
145
MIDDLE EAST
SAUDI ARABIA
132
EUROPE
GERMANY
132
SQL> DECLARE
2 userInput number;
3
4 PROCEDURE numberOfSupplier(x IN number) IS
5 -- Declaring variables to be used
6 r_name region.r_name%type;
7 n_name nation.n_name%type;
8
9
10 BEGIN
11 -- Print header
12 dbms_output.put_line(lpad('R_name',25) || lpad('N_Name',25) || lpad('Count(s_nationkey)',25));
13 dbms_output.put_line('-------------------' || '-------------------' || '-------------------');
14
15 -- Create an implicit cursor to bring in the data
16
17 for Qrow in (
18 select r_name, n_name, count(s_nationkey) AS cnt
19 from region , nation, supplier
20 where r_regionkey = n_regionkey
21 and n_nationkey = s_nationkey
22 group by r_name, n_name
23 having count(s_nationkey) > x
24 order by r_name)
25
26 -- Loop through query to print to terminal
27
28 loop
29 dbms_output.put_line(Qrow.r_name || Qrow.n_name || Qrow.cnt);
30 end loop;
31
32
33 END;
34
35 -- Executes Procedure
36
37 BEGIN
38 userInput := (&MinNumberofsupplier);
39 numberOfSupplier(userInput);
40 END;
41
42 /
这是终端中的错误信息
SQL> show errors;
Errors for PROCEDURE NUMBEROFSUPPLIER:
LINE/COL ERROR
-------- -----------------------------------------------------------------
31/2 PLS-00103: Encountered the symbol "END" when expecting one of the
following:
:= . ( % ;
The symbol ";" was substituted for "END" to continue.
我建议您创建一个存储过程(而不是匿名 PL/SQL 块),然后从您想要的任何地方调用该过程。
我删除了不必要的局部变量声明(因为您从未使用过它们)。
SQL> create or replace procedure numberofsupplier(x in number) is
2 begin
3 -- Print header
4 dbms_output.put_line(lpad('R_name',25) || lpad('N_Name',25) || lpad('Count(s_nationkey)',25));
5 dbms_output.put_line('-------------------' || '-------------------' || '-------------------');
6
7 -- Create an implicit cursor to bring in the data
8 for qrow in (
9 select r_name, n_name, count(s_nationkey) as cnt
10 from region , nation, supplier
11 where r_regionkey = n_regionkey
12 and n_nationkey = s_nationkey
13 group by r_name, n_name
14 having count(s_nationkey) > x
15 order by r_name)
16 -- Loop through query to print to terminal
17 loop
18 dbms_output.put_line(qrow.r_name || qrow.n_name || qrow.cnt);
19 end loop;
20 end;
21 /
Procedure created.
我们称它为:
SQL> -- Executes Procedure
SQL> set serveroutput on
SQL> begin
2 numberofsupplier(&userinput);
3 end;
4 /
Enter value for userinput: 1
R_name N_Name Count(s_nationkey)
---------------------------------------------------------
PL/SQL procedure successfully completed.
没有输出,因为我的表是空的,但是 - 您可能应该看到一些东西(使用您的表)。
您好,我刚开始学习 PLSQL,目前遇到此错误,但我不确定是什么导致了这个问题。
对于我的作业,我应该创建一个 PLSQL 过程,该过程接受用户输入 x 到 return 国家及其各自地区的列表。
R_NAME | N_NAME | COUNT(S_NATIONKEY) |
---|---|---|
ASIA | INDONESIA | 131 |
ASIA | CHINA | 145 |
MIDDLE EAST | SAUDI ARABIA | 132 |
EUROPE | GERMANY | 132 |
SQL> DECLARE
2 userInput number;
3
4 PROCEDURE numberOfSupplier(x IN number) IS
5 -- Declaring variables to be used
6 r_name region.r_name%type;
7 n_name nation.n_name%type;
8
9
10 BEGIN
11 -- Print header
12 dbms_output.put_line(lpad('R_name',25) || lpad('N_Name',25) || lpad('Count(s_nationkey)',25));
13 dbms_output.put_line('-------------------' || '-------------------' || '-------------------');
14
15 -- Create an implicit cursor to bring in the data
16
17 for Qrow in (
18 select r_name, n_name, count(s_nationkey) AS cnt
19 from region , nation, supplier
20 where r_regionkey = n_regionkey
21 and n_nationkey = s_nationkey
22 group by r_name, n_name
23 having count(s_nationkey) > x
24 order by r_name)
25
26 -- Loop through query to print to terminal
27
28 loop
29 dbms_output.put_line(Qrow.r_name || Qrow.n_name || Qrow.cnt);
30 end loop;
31
32
33 END;
34
35 -- Executes Procedure
36
37 BEGIN
38 userInput := (&MinNumberofsupplier);
39 numberOfSupplier(userInput);
40 END;
41
42 /
这是终端中的错误信息
SQL> show errors;
Errors for PROCEDURE NUMBEROFSUPPLIER:
LINE/COL ERROR
-------- -----------------------------------------------------------------
31/2 PLS-00103: Encountered the symbol "END" when expecting one of the
following:
:= . ( % ;
The symbol ";" was substituted for "END" to continue.
我建议您创建一个存储过程(而不是匿名 PL/SQL 块),然后从您想要的任何地方调用该过程。
我删除了不必要的局部变量声明(因为您从未使用过它们)。
SQL> create or replace procedure numberofsupplier(x in number) is
2 begin
3 -- Print header
4 dbms_output.put_line(lpad('R_name',25) || lpad('N_Name',25) || lpad('Count(s_nationkey)',25));
5 dbms_output.put_line('-------------------' || '-------------------' || '-------------------');
6
7 -- Create an implicit cursor to bring in the data
8 for qrow in (
9 select r_name, n_name, count(s_nationkey) as cnt
10 from region , nation, supplier
11 where r_regionkey = n_regionkey
12 and n_nationkey = s_nationkey
13 group by r_name, n_name
14 having count(s_nationkey) > x
15 order by r_name)
16 -- Loop through query to print to terminal
17 loop
18 dbms_output.put_line(qrow.r_name || qrow.n_name || qrow.cnt);
19 end loop;
20 end;
21 /
Procedure created.
我们称它为:
SQL> -- Executes Procedure
SQL> set serveroutput on
SQL> begin
2 numberofsupplier(&userinput);
3 end;
4 /
Enter value for userinput: 1
R_name N_Name Count(s_nationkey)
---------------------------------------------------------
PL/SQL procedure successfully completed.
没有输出,因为我的表是空的,但是 - 您可能应该看到一些东西(使用您的表)。