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