sql - PLS-00103:在期待以下之一时遇到符号“END”::=。( % ; 符号 ";" 代替 "END" 继续
问题描述
嗨,我刚刚开始学习 PLSQL,我目前遇到了这个错误,但我不确定是什么导致了这个问题。
对于我的任务,我应该创建一个 PLSQL 过程,该过程接受用户输入 x 以返回国家及其各自地区的列表。
R_NAME | N_NAME | COUNT(S_NATIONKEY) |
---|---|---|
亚洲 | 印度尼西亚 | 131 |
亚洲 | 中国 | 145 |
中东 | 沙特阿拉伯 | 132 |
欧洲 | 德国 | 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.
因为我的桌子是空的,所以没有输出,但是 - 你可能应该看到一些东西(使用你的桌子)。
推荐阅读
- c++ - 使用函数查找数组中的最大元素
- javascript - 如何避免多次调用useEffect
- django - Django通过信号保存在另一个表中
- python - postgresql 中的查询转换为 Django orm
- amazon-web-services - 在 AWS 控制台中编辑 AWS Glue 驱动程序脚本时出现奇怪的行为
- html - 将 api 中的项目放入反应列表中
- android-studio - 无法将 Android Studio 4.1.2 更新到 Android Studio 2020.3.1 arctic fox
- r - 与 grand_summary_rows() 函数无关的错误:`mutate()` 输入 `...` 有问题。x 输入 `...` 不能被回收到大小 1
- python - fake_useragent 模块连接不正确 - IndexError: list index out of range
- android - 安装启动失败后 Android Studio 无法启动