PLS-00103: Encountered the symbol "CREATE" when expecting one of the following: - sql

Facing error on the code execution :-
ERROR at line 16: ORA-06550: line 16, column 5: PLS-00103: Encountered
the symbol "CREATE" when expecting one of the following: ( begin case
declare exit for goto if loop mod null pragma raise return select
update while with << continue close current
delete fetch lock insert open rollback savepoint set sql execute
commit forall merge pipe purge
Executed sql script with the below code as part of the script and facing error like below
BEGIN
CREATE TABLE orphansInconsistenDelProgress (currentTable VARCHAR(100), deletedCount INT, totalToDelete INT);
INSERT INTO orphansInconsistenDelProgress (currentTable, deletedCount,totalToDelete) values ('',0,0);
ALTER SESSION SET parallel_degree_policy = AUTO;
ALTER SESSION FORCE PARALLEL DML;
COMMIT;

Related

Why am I getting this error? PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:

I am getting this error
Compilation failed, line 2 (11:52:47) The line numbers associated with compilation errors are relative to the first BEGIN statement. This only affects the compilation of database triggers.
PLS-00103: Encountered the symbol "CREATE" when expecting one of the
following: ( begin case declare exit for goto if loop mod null pragma
raise return select update while with << continue close current
delete fetch lock insert open rollback savepoint set sql execute
commit forall merge pipe purge json_exists json_value json_query
json_object json_array
Code:
create or replace trigger "GDS_CLIENT_T1"
BEFORE
insert or update or delete on GDS_CLIENT
for each row
begin
create or replace trigger "client insert"
before
insert on "Identify Client"
for each row
begin
select nv1(max(id),0)+1 into :NEW_ID FROM IDENTIFY CLIENT
end;
CREATE OR REPLACE TRIGGER is a DDL command that requires a full specification of the trigger to create; in your case, your first command has not ended:
create or replace trigger "GDS_CLIENT_T1"
BEFORE
insert or update or delete on GDS_CLIENT
for each row
begin
At this point it is expected that you will finish the definition of the GDS_CLIENT_T1 trigger; but instead, you have create or replace trigger which is not valid PL/SQL.

Script Error in Oracle SQL

I have a sql file which has the following statments:
BEGIN
if (&&masterKey = 1) then
shutdown immediate;
startup restrict;
end if;
END;
/
In a different SQL file (defineVariables.sql) I have declared the variable masterKey.
DEFINE masterKey = 0;
and imported that sql here using
#defineVariables.sql
While I execute the script I get the following error. I am not sure if its because I use the shutdown statement? Can someone please help me with this query?
Error Message:
SQL> BEGIN
2 if (&&masterKey = 1) then
3 shutdown immediate;
4 startup restrict;
5 end if;
6 END;
7 /
old 2: if (&&masterKey = 1) then
new 2: if (0 = 1) then
shutdown immediate;
*
ERROR at line 3:
ORA-06550: line 3, column 10:
PLS-00103: Encountered the symbol "IMMEDIATE" when expecting one of the
following:
:= . ( # % ;
ORA-06550: line 5, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
You cannot do this in PLSQL since "shutdown immediate" is not a PLSQL or SQL command but a SQLplus command. One way of achieving a conditional execution of scripts is described in the answer to this question:
SQLplus decode to execute scripts
Basically, depending on the value of your masterkey you select one of two script names and subsequently execute the script with that name.
Based on the code from previous example.
sql> variable flag varchar2(7);
sql> exec :flag := '&&masterKey';
sql> column our_script new_value script noprint;
sql> select decode(:flag, '1',
'c:\sqlplus\shutdown_script.sql',
'c:\sqlplus\do_not_shutdown.sql'
) our_script
from dual;
Execution
sql> #&script;
shutdown_script would be
prompt shutting down
shutdown immediate;
do_not_shutdown script would be
prompt Not shutting down

PLS-00103: Encountered the symbol "end-of-file"

just trying to make a simple trigger in oracle SQL to log data when a row in a table is inserted updated or deleted. but am coming up with an error.
here is my code
create or replace trigger "APP_LOG_INSERT"
BEFORE
insert on "APPLICATIONS"
for each row
begin
INSERT INTO APP_LOG (APPLICATION_ID, SRN, APPLICATION_STATUS)
SELECT APPLICATION_ID, SRN, STATUS_ID
FROM INSERTED
end;
and the error i am getting is
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: (
begin case declare end exception exit for goto if loop mod null pragma raise return select
update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable>
<< continue close current delete fetch lock insert open rollback savepoint set sql execute
commit forall merge pipe purge`
any help would be much appreciated, i am quite new to oracle so i may have just overlooked something simple
Presumably, you want something like this:
create or replace trigger "APP_LOG_INSERT"
BEFORE insert on "APPLICATIONS"
for each row
begin
INSERT INTO APP_LOG(APPLICATION_ID, SRN, APPLICATION_STATUS)
SELECT :new.APPLICATION_ID, :new.SRN, :new.STATUS_ID
FROM dual;
end;

Can't alter password

I am trying to alter the password of a user in plsql:
DECLARE
BEGIN
ALTER USER BOB IDENTIFIED BY PASS123;
END;
I keep getting the error when I create it and cannot make it out what it wrong:
ORA-06550: line 4, column 1: PLS-00103: Encountered the symbol "ALTER"
when expecting one of the following: ( begin case declare exit for
goto if loop mod null pragma raise return select update while with
<< continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
According to doc
Only dynamic SQL can execute the following types of statements within
PL/SQL program units:
Data definition language (DDL) statements such as CREATE, DROP, GRANT,
and REVOKE
Session control language (SCL) statements such as ALTER SESSION and
SET ROLE
The TABLE clause in the SELECT statem
DECLARE
BEGIN
EXECUTE IMMEDIATE 'ALTER USER BOB IDENTIFIED BY PASS123';
END;
You can use DDL statements (alter, create, grant etc) without begin-end block.
ALTER USER BOB IDENTIFIED BY PASS123;

Oracle Create trigger statement fails with internal error code ORA-00600

Trying to execute a dumpfile created from Oracle. Everything gets created and altered fine until this block:
CREATE OR REPLACE TRIGGER "LABS"."CHANNEL_CHANNEL_ID_TRG" BEFORE INSERT ON channel
FOR EACH ROW
DECLARE
v_newVal NUMBER(12) := 0;
v_incval NUMBER(12) := 0;
BEGIN
IF INSERTING AND :new.CHANNEL_ID IS NULL THEN
SELECT channel_CHANNEL_ID_SEQ.NEXTVAL INTO v_newVal FROM DUAL;
-- If this is the first time this table have been inserted into (sequence == 1)
IF v_newVal = 1 THEN
--get the max indentity value from the table
SELECT NVL(max(CHANNEL_ID),0) INTO v_newVal FROM channel;
v_newVal := v_newVal + 1;
--set the sequence to that value
LOOP
EXIT WHEN v_incval>=v_newVal;
SELECT channel_CHANNEL_ID_SEQ.nextval INTO v_incval FROM dual;
END LOOP;
END IF;
--used to emulate LAST_INSERT_ID()
--mysql_utilities.identity := v_newVal;
-- assign the value from the sequence to emulate the identity column
:new.CHANNEL_ID := v_newVal;
END IF;
END;
This fails and severs the connection, giving the following rather cryptic error:
ORA-00603: ORACLE server session terminated by fatal error
ORA-00600: internal error code, arguments: [kqlidchg1], [], [], [], [], [], [], [], [], [], [], []
ORA-00604: error occurred at recursive SQL level 1
ORA-00001: unique constraint (SYS.I_PLSCOPE_SIG_IDENTIFIER$) violated
00603. 00000 - "ORACLE server session terminated by fatal error"
*Cause: An ORACLE server session is in an unrecoverable state.
*Action: Login to ORACLE again so a new server session will be create
Found a solution that worked. Surround the block of code with the following ALTER statements:
ALTER SESSION SET PLSCOPE_SETTINGS = 'IDENTIFIERS:NONE';
... sql statements here ...
ALTER SESSION SET PLSCOPE_SETTINGS = 'IDENTIFIERS:ALL';
For some reason, the Oracle database dump does not include these commands, but this fixed the problem.