Oracle - PLS-00103: Encountered the symbol "END" when try to create JOB - sql

i have a problem here,
i already have a Stored Procedure called "SP_DEL_TOKEN"
and i wanna make a job to run the Stored procedure automatically everyday..
this is my script to make the job
VAR jobno NUMBER;
BEGIN
DBMS_JOB.SUBMIT(:jobno, 'SP_DEL_TOKEN', SYSDATE, 'SYSDATE+1');
COMMIT;
END;
/
but when i do that script, i encountered with this error
ERROR at line 1:
ORA-06550: line 1, column 106:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
:= . ( # % ;
The symbol ";" was substituted for "END" to continue.
ORA-06512: at "SYS.DBMS_JOB", line 79
ORA-06512: at "SYS.DBMS_JOB", line 136
ORA-06512: at line 2
please help me,
and thanks for helping me :)

You need a semicolon at the end of the "what" parameter. Use 'SP_DEL_TOKEN;' instead of 'SP_DEL_TOKEN'. See the manual for some more examples.
I'm not sure why this is. With dynamic SQL you cannot have a semicolon, and with dynamic PL/SQL you need the BEGIN and END;. I guess this parameter is used in some weird context.

Related

SQL - LPX-00242: invalid use of ampersand ('&') character (use &)

I'm trying to run the below sql query.
SELECT sr.resultid, xt2.*
FROM RESULTS sr,
XMLTABLE('/extraInfo/resultsViewData'
PASSING XMLType(sr.extrainfo)
COLUMNS
docketNumber VARCHAR2(35) PATH 'docketNumber',
dateFiled VARCHAR2(35) PATH 'dateFiled',
nosDescription VARCHAR2(70) PATH 'nosDescription',
courtname VARCHAR2(100) PATH 'courtname',
chapter VARCHAR2(35) PATH 'chapter'
) xt2
WHERE sr.profileId = '7dd76222';
NOTE: sr.extrainfo has the value
'<extraInfo><resultsViewData><courtname>FL Circuit & County - Santa Rosa</courtname></resultsViewData></extraInfo>'
Even though I use '& amp ;' instead of '&', I still get the below error,
ORA-31011: XML parsing failed
ORA-19213: error occurred in XML processing at lines 1
LPX-00242: invalid use of ampersand ('&') character (use &)
ORA-06512: at "SYS.XMLTYPE", line 272
ORA-06512: at line 1
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
Sometimes I even get the error,
LPX-00242: invalid use of ampersand ('&') character (use &amp;)
Is there any way to overcome this issue?
Try:
set define off;
Then execute your query;
If you want more info on what set define off; does: When or Why to use a "SET DEFINE OFF" in Oracle Database
I am not able to reproduce your issue at first place.
But still if you are getting the issue then try to use dbms_xmlgen.convert to convert your string as following:
'<extraInfo><resultsViewData><courtname>'
|| dbms_xmlgen.convert('FL Circuit & County - Santa Rosa')
|| '</courtname></resultsViewData></extraInfo>'
db<>fiddle demo
Cheers!!

Can't run hello world in PL/SQL

I am trying to learn PL/SQL, but I cannot run a basic script. At this point I feel there is not a syntax issue, but something basic I'm missing.
BEGIN
dbms_output.put_line('Hello world');
END
When I run it I get an error saying
Error starting at line : 1 in command -
BEGIN
dbms_output.put_line('Hello world');
END
When I run the script I get an error saying:
Error report -
ORA-06550: line 4, column 3:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
; <an identifier> <a double-quoted delimited-identifier>
The symbol ";" was substituted for "end-of-file" to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
If you know what I might be missing let me know.
You just need a semicolon and "/" at the end, before you run the script.
BEGIN
dbms_output.put_line('Hello world');
END;
/
Don't forget to "set serveroutput on" to see the actual output.

What is the valid syntax for the DB2 Anonymous SQL Block?

I have DB2 v9.7 client driver to access DB2 instance which is installed on Z/OS environment. I am trying to write and execute an anonymous procedure by the help of Toad for DB2 4.7. Unfortunately, none of the given example codes on the internet hurdled the syntax errors. Whatever i try, even very simple ones, not worked properly. I am curious about is there an execution mode of Toad or something that i missed on my tries. Here are my tries and syntax errors that i have received:
DECLARE
somechr VARCHAR2(255);
BEGIN
somechr:='some value';
END;
The sample above throws these errors:
DB2 Database Error: ERROR [42601] [IBM][DB2] SQL0104N An unexpected token "VARCHAR2" was found following "". Expected tokens may include: "TABLE STATEMENT , . SCROLL INSENSITIVE SENSITIVE ASENSITIVE ". SQLSTATE=42601
DB2 Database Error: ERROR [42601] [IBM][DB2] SQL0104N An unexpected token "SOMECHR" was found following "". Expected tokens may include: "DECLARE". SQLSTATE=42601
DB2 Database Error: ERROR [42601] [IBM][DB2] SQL0104N An unexpected token "END-OF-STATEMENT" was found following "". Expected tokens may include: "DECLARE". SQLSTATE=42601
The last one vanishes when i change the 'some value'; to 'some value';--
Some examples uses following syntax:
BEGIN
DECLARE somechr VARCHAR2(255);--
somechr:='some value';
END;
However, this syntax throws exception too:
DB2 Database Error: ERROR [42601] [IBM][DB2] SQL0104N An unexpected token "SOMECHR" was found following "". Expected tokens may include: "SECTION". SQLSTATE=42601
At last i have tried this:
BEGIN
DECLARE SECTION BEGIN
somechr VARCHAR2(255);--
END;
somechr:='some value';--
END;
And got these:
DB2 Database Error: ERROR [42612] [IBM][DB2] SQL0084N An EXECUTE IMMEDIATE statement contains a SELECT or VALUES statement. SQLSTATE=42612
DB2 Database Error: ERROR [42601] [IBM][DB2] SQL0104N An unexpected token "SOMECHR" was found following "". Expected tokens may include: " GET SQL SAVEPOINT HOLD FREE ASSOCIATE". SQLSTATE=42601
Besides these tries, some noted that use of '--#SET TERMINATOR #' at the beginning of the code, nevertheless it did not help as well for all examples above. I have given tries by changing the ';' to symbol '#' for all combinations (with or without '--#SET TERMINATOR #' statement), but erros does not seem to be vanished.
I work with DB2 LUW, not z/OS. That said, you might try this:
BEGIN
DECLARE V_SOMECHR NVARCHAR(255);
SET V_SOMECHR = 'some value';
END
My experience in DB2 LUW is that the declarations have to be inside the BEGIN block, and must come first, but there is no heading stating that it is a DECLARE section. You can place your procedural code immediately after the last declaration. Not sure if this will be the case in z/OS.

Unterminated dollar-quoted string at or near "$$

I'm trying to declare some variables using DBeaver and keep hitting this error.
Unterminated dollar-quoted string at or near "$$
DO $$
DECLARE A integer; B integer;
BEGIN
END$$;
Any ideas?
DBeaver was the issue. Switched to PGAdmin and no more problems.
As of DBeaver 6, you can execute the script with ALT-X (on Windows), which does not attempt to do variable capture/interpolation involving dollar signs.
The syntax posted is fine. Your problem is that the client application or driver is mangling the query, probably because it doesn't understand dollar-quoting.
It might be trying to split it into separate statements on semicolons, running:
DO $$ DECLARE A integer;
B integer;
BEGIN END$$;
as three separate statements. This would result in the reported error, e.g.
$ psql -c 'DO $$ DECLARE A integer;'
ERROR: unterminated dollar-quoted string at or near "$$ DECLARE A integer;"
LINE 1: DO $$ DECLARE A integer;
^
This is why you must specify your client driver/application when asking questions.
Another possibility with some clients is that it might treat $ as an escaped query-parameter placeholder and replace it with a single $ or try to substitute it for a server-side placeholder like $1. That's not what's happening here, though.
DBeaver also gives this error when there is a SQL syntax error in the script.
In my case, it was a pair of mismatched parenthesis in a select calculated column.

ORA-12728: invalid range in regular expression

I want to check if valid phone number is inserting in table, so my trigger code is here:
select start_index
into mob_index
from gmarg_mobile_operators
where START_INDEX = substr(:new.contact_info,0,3);
if (REGEXP_LIKE (:NEW.CONTACT_INFO,'^(?:'|| mob_index ||')[\-,\:]{0,1}[0-9][0-9][\-,\:]{0,1}[0-9][0-9][\-,\:]{0,1}[0-9][0-9]')) then
found := 1;
end if;
I've checked my regex: "^(?:555)[-,:]{0,1}[0-9][0-9][-,:]{0,1}[0-9][0-9][-,:]{0,1}[0-9][0-9]" on several online tools and it is correct.
When I run my trigger, it compiles successfully, but during inserting a row following error is shown:
insert into GMARG_CONTACTS
(CLINET_ID,CONTACT_INFO,contact_type_id)
values
(0,'555194117','Mobile')
Error report -
SQL Error: ORA-12728: invalid range in regular expression
ORA-06512: at "HR.GMARG_TRIGGER_CONTACT", line 12
ORA-04088: error during execution of trigger 'HR.GMARG_TRIGGER_CONTACT'
12728. 00000 - "invalid range in regular expression"
*Cause: An invalid range was found in the regular expression.
*Action: Ensure a valid range is being used.
So, if my regex is correct, why does oracle shows error?
I tried to find answer, or redifine my regex, but no forward steps...
thank you in advance
Regexp don't use \ to protect - in a bracket expression. You only have to put - as the first character, just after the opening bracket:
IF REGEXP_LIKE('--,,::', '[\-,:]*')
...
=> ORA-12728: invalid range in regular expression
If you're curious, when encountering [\-,:] Oracle understand: "any character in the range from \ to , or the character :". The reason why this raises an exception is \ appears to be after , according to their ASCII value. And Oracle don't accept range having a starting value after the ending one.
On the other hand:
IF REGEXP_LIKE('--,,::', '[-,:]*')
Works as expected.
As a side note, [-,:]{0,1} meaning "zero or one occurrence of - or , or :" could be written [-,:]?.