What is wrong with following stored procedure?
CREATE PROCEDURE TEST
(IN mbr VARCHAR(30),
OUT sql_state CHAR(5)
)
DYNAMIC RESULT SETS 1 LANGUAGE SQL BEGIN DECLARE SQLSTATE CHAR(5);
DECLARE rs CURSOR WITH RETURN TO CLIENT FOR
SELECT
*
FROM
A.XYZ;
OPEN rs;
SET
sql_state = SQLSTATE;
END #;
According to Info Center, SQL Code -104 means that you have an illegal symbol somewhere. In the full error message, it should give an indication to where that illegal symbol is located.
My guess is that something is confused about your statement terminators, have a look at this article.
If you are running this in command editor then you simply need to
Change your default termination character from semi-colon (;) to something
else
and it will work.
You can see the IBM TechNote here : http://www-01.ibm.com/support/docview.wss?uid=swg21224723
Related
Whenever i try to run a program consisting of user input the compiler always throws the same error of i dont know what that means. the error does not explain what the error is that i am encountering, can anyone please help regarding this problem.
Here is the error:
Unsupported Command
Unsupported Command
ORA-06550: line 6, column 4:
PLS-00103: Encountered the symbol "&" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specifi
Here is the code for plsql in which i am taking user input for temperature and returning the celcius or farenheight temp of the same.
declare
f number;
n number;
ch char;
begin
f:=&f;
ch:=&ch;
if(ch!='F') then
n:=(f-32)*5/9;
else
n:=(f*9/5)+32;
end if;
dbms_output.put_line('Temperature: '||f||' '||ch);
end;
/
I would be highly grateful for your efforts.
Thank you
The & syntax indicates the variable is a substitution variable which is processed in the client application (it is effectively a find-replace on the variable).
Substitution variables are only supported by a limited number of client applications (including SQL*Plus and SQL Developer); they are not supported in other applications such as Oracle Apex, Java, C#, Python, etc.
You are getting the error because your client application does not support substitution variables; instead, you need to use the correct syntax for the application you are using (which may be to use bind variables).
This can be run in the "SQL Commands" window in apex, but you need to use the bind variable syntax :
declare
f number;
n number;
ch char;
begin
f:=:f;
ch:=:ch;
if(ch!='F') then
n:=(f-32)*5/9;
else
n:=(f*9/5)+32;
end if;
dbms_output.put_line('Temperature: '||f||' '||ch);
end;
/
This will invoke a popup window in which you are prompted for the values of :F and :CH.
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.
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.
If I try this statement:
INSERT INTO TerminalEventChild (id,stringValue) VALUES
(64,'version123|');
MySQL fail with :
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''version123' at line 1
SQLState: 42000
ErrorCode: 1064
If I remove the | character, everything works fine. Any idea?
I found the solution on Incorrect query parsing - ID: 3091322.
Squirrel SQL is using the pipe symbol as a procedure/function separator, so you need to change the MySQL preferences to use something else (e.g. |||).
In the "File > Global Preferences > MySQL" tab, in the "Procedure/Function Separator" field,
replace | with a different string, for example |||.
On my machine, this works fine:
CREATE TABLE TerminalEventChild (id INT, stringValue VARCHAR(200));
INSERT INTO TerminalEventChild (id,stringValue) VALUES
(64,'version123|');
Probably, your client treats the pipe character specially.
What client do you use?
When i execute the below SQL command using single quotes to enter a number, i got an error
if remove the single quotes,it is successfully updated. knowing that the type of the field HEIGHT is NUMBER.
The strange thing is that i tried to use the same sql statement with single quotes on different machines, some machines execute it successfully, others do not.(same oracle version,same table structure...)
Any explanation please
SQL> UPDATE TBL_DEVICE_INFO SET HEIGHT='14.5' WHERE ID='6ujbfI';
UPDATE TBL_DEVICE_INFO SET HEIGHT='14.5' WHERE ID='6ujbfI'
*
ERREUR à la ligne 1 :
ORA-01722: invalid number
SQL> UPDATE TBL_DEVICE_INFO SET HEIGHT=14.5 WHERE ID='6ujbfI';
1 row updated.
This is most likely a locale problem.
That is, some machines have the decimal symbol "." (period), and some have "," (comma).
You can test it by putting it like this:
UPDATE TBL_DEVICE_INFO
SET HEIGHT = to_number('14.5', '99D9','NLS_NUMERIC_CHARACTERS = ''. ''')
WHERE ID='6ujbfI'
When the number is in single qoutes, oracle will do an implicit conversion to number using the characters set in the database.
You can change the default by setting the NLS_NUMERIC_CHARACTERS parameter:
alter session set NLS_NUMERIC_CHARACTERS = '. ';
but that will also reflect to data returned by the system so make sure that it doesn't break anything in your application if you change that.
Strings should be quoted using single quotes, numbers shouldn't be.
Maybe you're using a different client on the machines where the invalid syntax works?