我正在尝试在 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 列
block 引用>
最佳答案
根据它的运行方式(作为脚本?),您可能需要用正斜杠结束 PLSQL block :
declare
--...
begin
--...
end;
/
并向您展示您的代码应该完全按原样运行(在 Oracle 11GR2 上;SQL Developer 的脚本输出显然不会在 create
或 select< 之后显示分号
语句或 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/