Trivial PL/SQL block generating frustrating PLS-00103 error - oracle

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:

Related

Hive error when declaring hivevar

Trying to declare a variable in Hive using Hue online. Using the following code:
SET hivevar:TABLE1=location.tablename;
I am getting the following error message:
Error while compiling statement: FAILED: ParseException line 1:12 missing KW_ROLE at 'hivevar' near 'hivevar' line 1:19 missing EOF at ':' near 'hivevar'.
Can anyone tell me what this error message means or even what the KW_ROLE statement means?
Do you by any chance have a comment above that instruction ? Are you running that line and that line only ?
For example, the following will raise a similar Exception :
--This is a comment
SET hivevar:TABLE1=location.tablename;
But it works fine without the comment.
I guess you are making changes in MAC/Windows and moving the script to the server, Double dash "--" in MAC is a different from double dash "--" on Linux server, make changes on server itself and run the script...

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

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).

"unknown command" for dbms_lob.open command in Sql+

I am a total beginner when it comes to PL/SQL and Sql+. I am trying to write a function that will extract the contents of a text file into a CLOB (following this as an example). When I issue the following command in Sql+:
dbms_lob.open( 'c:\temp\test.txt', dbms_lob.lob_readonly );
I get the following error message:
SP2-0734: unknown command beginning "dbms_lob.o..." - rest of line ignored.
Is there something wrong with the syntax of the command, or something else entirely?
Thanks much!
I'm not an expert in oracle. For me the problem is that for launch this command in sqlplus you may declare an anonymous block like this:
DECLARE
-- variables
BEGIN
--- your commands here
dbms_lob.open......
END;
To launch the execution you have to digit / and then return

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