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

For some reason this wont work. I have got it down to the most basic operation to try and troubleshoot.
BEGIN
FOR rec IN (
select REGISTRATION_UID from DIM_REGISTRATION_SET
) 
   LOOP
dbms_output.put_line('Testing 123');
  END LOOP; 
end;
/
My error is as below:
Error starting at line 1 in command:
BEGIN
FOR rec IN (
select REGISTRATION_UID from DIM_REGISTRATION_SET
) 
   LOOP
dbms_output.put_line('Testing 123');
  END LOOP; 
end;
Error report:
ORA-06550: line 4, column 6:
PLS-00103: Encountered the symbol " " when expecting one of the following:
loop
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

You seem to have an unexpected character in your code. If you copy and paste the rendered output from this question then it runs fine. If you copy the question source code (from the edit dialogue) then it gets that error.
Dumping the code (again copied from the source, not the rendering) shows:
select dump('(
select REGISTRATION_UID from DIM_REGISTRATION_SET
) ', 16)
from dual; 
DUMP('(SELECTREGISTRATION_UIDFROMDIM_REGISTRATION_SET) ',16)
--------------------------------------------------------------------------------
Typ=96 Len=73: 28,a,20,20,20,20,20,20,20,20,20,20,73,65,6c,65,63,74,20,52,45,47,
49,53,54,52,41,54,49,4f,4e,5f,55,49,44,20,66,72,6f,6d,20,44,49,4d,5f,52,45,47,49
,53,54,52,41,54,49,4f,4e,5f,53,45,54,a,20,20,20,20,20,20,20,20,29,c2,a0
So the space after the closing parenthesis isn't actually a space, it's Unicode character c2a0, which is a non-breaking space.
The error message shows that too, if you dump that:
select dump ('Encountered the symbol " "', 16) from dual;
DUMP('ENCOUNTEREDTHESYMBOL" "',16)
--------------------------------------------------------------------------------
Typ=96 Len=27: 45,6e,63,6f,75,6e,74,65,72,65,64,20,74,68,65,20,73,79,6d,62,6f,6c
,20,22,c2,a0,22
I would guess you copied that code from somewhere (Word?) and it picked up that character, and it hasn't been translated to a normal space. Just replace it with a space, or remove it as it's redundant whitespace anyway.
Actually, there are several others; two at the start of the LOOP line (followed by two normal spaces), and two immediately before END LOOP; (preceded by two normal spaces), and one after that statement; so those all need to be replaced too. (I'd be tempted to retype the whole thing, but that might not be practical for your full code).

Related

oracle plsql error while compiling package spec

create or replace
PACKAGE test_pkg
IS
PROCEDURE abc_requests (p_xys IN NUMBER);
end test_pkg;
Hello my procedure name is abc_requests with just one parameter.
Below is my error message, please help.
Error message:
Error(4,11): PLS-00103: Encountered the symbol " "
when expecting one of the following:
<an identifier>
<a double-quoted delimited-identifier>
current delete exists prior
You have used non-breaking spaces in your statement, instead of plain spaces. If you copy and paste the code from the page as it is displayed above it will work. If you edit the question and copy the original code it will not.
You can use the dump() function (or a decent text editor) to see what the code actually contains:
select dump('PROCEDURE abc_requests (p_xys IN NUMBER);',16) from dual;
DUMP('PROCEDURE ABC_REQUESTS(P_XYS IN NUMBER);',16)
--------------------------------------------------------------------------------------------------------------------------------------------------
Typ=96 Len=44: 50,52,4f,43,45,44,55,52,45,c2,a0,61,62,63,5f,72,65,71,75,65,73,74,73,20,28,70,5f,78,79,73,c2,a0,49,4e,c2,a0,4e,55,4d,42,45,52,29,3b
^^^^^ ^^^^^ ^^^^^
I've highlighted the two problem characters, which are the multibye non-break space (in UTF-8).
Retype your code, or copy and paste from the question, or just change the non-breaking spaces to normal ones.

Trivial PL/SQL block generating frustrating PLS-00103 error

I may be going a bit insane, but I keep getting a PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following... error. I have pared my program down to the following:
BEGIN
NULL;
END;
/
Which I am running within AquaData Studio.
This produces:
[Error] Script lines 1-2 ... ORA-06550: line 2, column 8:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following...; Script line 2, statement line 2, column 8
I write a decent amount of PL/SQL and normally the above trivial block runs just fine. What the heck is wrong with what I'm doing?
It turns out the solution was as suggested by #a_horse_with_no_name in his comment. In ADS, you need to open File → Options Ctrl + , (that's a comma!) and set the following options on the General tab:
';' Statement separator (make sure it is not ticked)
'/' at End of Line Terminates Statement (make sure it is ticked)
See screenshot below. Do this, and it all works:

Error when trying to load data from Unix script

when i am trying to execute the SQL script from Unix server its showing error but the same SQL i am running from sql navigator its working fine .. kindly help me on it..
INSERT INTO t_csocstudent_course_local
(SELECT tsct.student_id,
tsct.object_lookup_id,
tsct.course_id,
tsct.xcourse_id,
clt.NAME,
tsct.course_type,
FROM temp_stud_course tsct join course_local clt
on tsct.COURSE_ID = clt.COURSE_ID
WHERE TO_CHAR (sc_timestamp, 'YYYYMMDDHH24MISS') >
(SELECT TO_CHAR (MAX (sc_timestamp), 'YYYYMMDDHH24MISS')
FROM t_student_course_local)
AND tsct.xcourse_id IN
('EX1','EX2'));
Error :
Error in loading main table
Enter password:
SP2-0734: unknown command beginning "WHERE TO..." - rest of line ignored.
AND tsct.xcourse_id IN
*
ERROR at line 3:
ORA-00933: SQL command not properly ended
Thanks in advance !!
I can't remember if the Oracle command line client permits extra whitespace linebreaks. Remove the extra linebreak before the WHERE clause.
Update
From the documentation, an empty line terminates a SQL statement by default in SQLplus.
SQLT[ERMINATOR] {;|c|OFF|ON}|
Set the char used to end and execute SQL commands to c.
OFF disables the command terminator - use an empty line instead.
ON resets the terminator to the default semicolon (;).
You can change the behavior to use semicolons instead of empty lines:
SET SQLTERMINATOR ON

Oracle Pl/SQL trigger compilation error via SQL*PLUS

I have a problem with compiling an Oracle trigger via SQL*PLUS - I don't think I'm being dumb but I can't see what the problem is.
We have an installer script which is essentially a batch file which creates/refreshes all the objects in the database by calling SQLPLUS on multiple scripts, each containing one view, trigger, etc. The tables and views are created first, then then triggers. The V_BS_GRIDFIELDS view below may or may not be created at this point, or may be created later by a different process. The view is an updatable view, so we have a trigger placed on it to push updates to different tables, as below:
CREATE OR REPLACE FORCE TRIGGER TR_INSTUPD_BS
INSTEAD OF INSERT OR UPDATE OR DELETE
ON V_BS_GRIDFIELDS
FOR EACH ROW
BEGIN
IF INSERTING OR DELETING THEN
NULL;
END IF;
IF UPDATING THEN
-- Can only change these fields
IF (:OLD.VISIBLE <> :NEW.VISIBLE) OR (:OLD.COMPULSORY <> :NEW.COMPULSORY) THEN
-- Source Table = BS_GRIDFIELDS
IF (:OLD.SOURCE_TYPE = 0) THEN
UPDATE BS_GRIDFIELDS BS_GF
SET BS_GF.VISIBLE = :NEW.VISIBLE,
BS_GF.COMPULSORY = :NEW.COMPULSORY
WHERE BS_GF.FIELD_NAME = :OLD.FIELD_NAME;
END IF;
END IF;
END IF;
END;
The issue is that oracle SQL*PLUS seems to stop compiling the trigger after the first blank line, on line 6:
SQL> #"TR_INSTUPD_BS.sql";
SP2-0734: unknown command beginning "IF INSERTI..." - rest of line ignored.
SP2-0042: unknown command "NULL" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0734: unknown command beginning "IF UPDATIN..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0734: unknown command beginning "IF (:OLD.V..." - rest of line ignored.
SP2-0734: unknown command beginning "IF (:OLD.S..." - rest of line ignored.
SP2-0552: Bind variable "OLD" not declared.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END" - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
If you remove the blank line on line 6, it seems to stop compiling at the first semicolon, on line 7:
SQL> #"TR_INSTUPD_BS.sql";
Warning: Trigger created with compilation errors.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0734: unknown command beginning "IF UPDATIN..." - rest of line ignored.
SP2-0734: unknown command beginning "IF (:OLD.V..." - rest of line ignored.
SP2-0734: unknown command beginning "IF (:OLD.S..." - rest of line ignored.
SP2-0552: Bind variable "OLD" not declared.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END" - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SQL>
We have lots of triggers created in this way, and all of them have spaces, semicolons, etc, and get created OK. I've tested and seen the same issue on Oracle 9, 10, 11. Can anyone shed light on this?
Thanks.
in its default setting SQL*Plus won't deal properly with blank lines, you need to issue the following command:
SQL> SET SQLBLANKLINES on
See this other SO.
Update: I answered too fast, the blank line doesn't seem to be the problem here. I tried your code on my database and the issue seems to come from the FORCE keyword. The 10gR2 documentation doesn't mention this keyword. The trigger compiles when you remove it.

Incorrect syntax near ')'

I have a BasicMSI project (Installshield 2009) that runs a SQL script during the installation process.
During the installation I receive the following error.
Error 27506.Error executing SQL script {SCRIPTNAME}. Line 352. Incorrect syntax near ')'. (102)
The problem is that I don't have any ')' at line 352 of the script and also the script works without any problems if I run it with SQL Management Studio Express.
Can anyone tell me what is the problem and how can I fix it?
Thanks.
PS. I cannot set the script error handling option to "On Error, Goto Next Statement" because therefor it will not create some of my foreign keys.
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRIGGER_NAME]'))
EXEC dbo.sp_executesql #statement = N'
CREATE TRIGGER [dbo].[TRIGGER_NAME]
ON [dbo].[TABLE_NAME] -- LINE: 352
INSTEAD OF INSERT
AS
BEGIN
DECLARE #Count INT;
SET #Count = (SELECT COUNT([Name])
FROM TABLE_NAME
WHERE IsDeleted = 0 AND [Name] IN (SELECT [Name] FROM INSERTED));
IF #Count > 0
BEGIN
RAISERROR (''Error Message.'', 16, 1);
Rollback;
END
ELSE
BEGIN
INSERT INTO dbo.TABLE_NAME SELECT {Columns} FROM INSERTED;
SELECT CONVERT(BigInt,SCOPE_IDENTITY()) AS [value]
END
END
'
GO
I was getting similar errors (one with ')' as the offending character, one with ';' as the offending character). Then I noticed that when InstallShield imported my scripts, it had changed ">" to ">" and "<" to "<" and "&" to "&". Doing search-and-replace across the imported scripts in the InstallShield script editor for these three substitutions fixed the issue for me.
It seems reasonable that this error might occur if you've written an IN statement, which you populate programmatically, only at runtime some values are missing, resulting in a statement saying "... WHERE x IN()", which is invalid.
This would generate that error, and also, it is an error that could easily appear in one environment but not another. It is hard to give more detail than that without actually seeing the script.

Resources