oracle - Aqua Data Studio 中的 PL/SQL 错误

标签 oracle plsql

我正在尝试在 Aqua Data Studio 8.0.22 中执行下一个代码:

--  Add a new role for cashier.
declare 
    roleEntityID "Entity"."EntityID"%type;
begin
    select "EntityID_SEQ".NEXTVAL into roleEntityID from dual;
    insert into "Entity" ("EntityID") values(roleEntityID);
    insert into "Role" ("RoleID", "Name", "DisplayName") values (roleEntityID, 'Cashier', 'Cashier');
end;

但不幸的是我有一些错误,首先是:

[Error] Script lines: 1-3 -------------------------- ORA-06550: line 3, column 41: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

:= ( ; 非空范围默认字符 脚本第 3 行,语句 第 3 行,第 41 列

最佳答案

根据它的运行方式(作为脚本?),您可能需要用正斜杠结束 PLSQL block :

declare
--...
begin
--...
end;
/

并向您展示您的代码应该完全按原样运行(在 Oracle 11GR2 上;SQL Developer 的脚本输出显然不会在 createselect< 之后显示分号 语句或 end; 之后的行上的斜杠,但所有内容都存在于原始缓冲区中):

> create sequence "EntityID_SEQ"
sequence "EntityID_SEQ" created.
> create table "Entity"("EntityID" number)
table "Entity" created.
> create table "Role"("RoleID" number, "Name" varchar2(30), "DisplayName" varchar2(30))
table "Role" created.
> declare 
    roleEntityID "Entity"."EntityID"%type;
begin
    select "EntityID_SEQ".NEXTVAL into roleEntityID from dual;
    insert into "Entity" ("EntityID") values(roleEntityID);
    insert into "Role" ("RoleID", "Name", "DisplayName") values (roleEntityID, 'Cashier', 'Cashier');
end;
anonymous block completed
> select * from "Entity"
EntityID               
---------------------- 
1                      

 1 rows selected 

> select * from "Role"
RoleID                 Name                           DisplayName                    
---------------------- ------------------------------ ------------------------------ 
1                      Cashier                        Cashier                        

 1 rows selected 

关于oracle - Aqua Data Studio 中的 PL/SQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10814108/

相关文章:

REGEXP_LIKE 奇怪的行为

sql - 在 oracle 中存储日期

Oracle构建顺序和PL/SQL软件包依赖关系

sql - 如何从pl sql过程运行sql脚本

sql - 如何在Oracle中将表中的所有列从null设置为not null

python - 如何使用 sqlalchemy 和 python 调用 refcursor 返回类型的 Oracle 函数

mysql - 用于测试连接性的通用 SELECT 查询

Oracle ADF 12 项目结构

sql - 具有分组依据的oracle滞后函数

oracle - PlSql Translate函数问题