2

我正在尝试在 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;

但不幸的是,我遇到了一些错误,首先是:

[错误] 脚本行:1-3 -------------- ORA-06550:第 3 行,第 41 列:PLS-00103:遇到预期以下之一时的符号“文件结尾”:

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

4

2 回答 2

2

Depending on how this is being run (as a script?), you may need to end the PLSQL block with a forward slash:

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

And to show you that your code should work exactly as-is (on Oracle 11GR2; the script output from SQL Developer apparently doesn't show the semicolons after the create or select statements or the slash on the line after the end; but all were present in the original buffer):

> 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 
于 2012-05-30T19:02:34.273 回答
0

尝试删除引号。不知道你为什么把它们放在那里

于 2012-05-30T18:52:49.310 回答