Stored procedure on AIX environment and DYNAMICRULES BIND - sql

I'm writing a stored procedure (on AIX environment) and I need to activate "DYNAMICRULES BIND" selected.
CREATE OR REPLACE PROCEDURE jjjjjj_PROVA
( IN p_input1 CHAR(2) )
LANGUAGE SQL
SPECIFIC jjjjjj_PROVA
DYNAMICRULES BIND
P1: BEGIN
...
...
END P1
In the distribution phase I get the following error.
xxxxx.jjjjjj_PROVA - Distribuzione avviata.
Creazione di procedura memorizzata restituzioni SQLCODE: -104, SQLSTATE: 42601.
xxxxx.jjjjjj_PROVA: 12: An unexpected token "BIND
P1" was found following "DYNAMICRULES". Expected tokens may include: "<space>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.19.56
An unexpected token "BIND
P1" was found following "DYNAMICRULES". Expected tokens may include: "<space>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.19.56
xxxxx.jjjjjj_PROVA - Distribuzione non riuscita.
xxxxx.jjjjjj_PROVA - Rollback completato correttamente.
The same statement in the DB2 Z / OS environment is correct.
Tips?
Thank you!!

Use CALL SET_ROUTINE_OPTS('DYNAMICRULES BIND') statement before CREATE PROCEDURE in the same session.
Customizing precompile and bind options for compiled SQL objects

Related

SQL 2019 : Invalid data for UTF8-encoded characters

When attempting to run the following statement :
sp_change_users_login 'auto_fix','ELC',NULL,'CLE'
I get the following error :
sp_change_users_login, Line 218 [Batch Start Line 2]
Invalid data for UTF8-encoded characters
The number of orphaned users fixed by updating users was 0.
This is a SQL 2019 with UTF8 enabled.
as it has been mentioned in the comment that proc has been deprecated, you can use modern command alter user:
ALTER USER JEANC
WITH PASSWORD = 'cnaej'

DB2 - AUTONOMOUS Stored Procedure

I would like to write an AUTONOMOUS stored procedure (native). I'm using the DB2 database (V11.01)
CREATE PROCEDURE SP_LOG (IN p_field1 char(2)
,IN p_field2 varchar(50)
,IN p_field3 varchar(50)
,IN p_field4 varchar(3926) )
VERSION V1
ISOLATION LEVEL CS
WLM ENVIRONMENT FOR DEBUG MODE WLMENV1
RESULT SETS 0
LANGUAGE SQL
ALLOW DEBUG MODE
AUTONOMOUS
BEGIN
...
...
END
I'm using IBM DATA STUDIO 4.1.1 and I get the following error:
Creazione di procedura memorizzata restituzioni
SQLCODE: -104, SQLSTATE: 42601. XXXXX.SP_LOG: 11: ILLEGAL SYMBOL
"". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: FOR.
SQLCODE=-104, SQLSTATE=42601, DRIVER=4.18.60 XXXXX.SP_LOG -
Distribuzione per il debug non riuscita. XXXXX.SP_LOG - Rollback
completato correttamente.
If you have any recommendations, I'd love to hear them!
Thanks :)
Good news, I found the issue.
This is a bug of IBM Data Studio (IT26018 - AUTONOMOUS KEYWORD IS NOT CONSIDERED AS A VALID KEYWORD FOR DB2 ZOSV11 AND V12 IN DS.4.1.3 - For more information click here.
Here's how I solved it:
I downloaded the new version (IBM DATA STUDIO 4.1.3) - Link
Installed the new version using IBM INSTALLATION MANAGER
I downloaded the FIX - Link
Installed the FIX (Instructions are included in the .ZIP file (open the "Hotfix Guide.pdf" file)

Db2: How to deploy an Oracle PL/SQL package in db2?

I tried to create an Oracle PL/SQL package in Db2, but ran into errors.
CREATE OR REPLACE PACKAGE ARITHMETIC AS
function add (
first number,
second number)
return number;
END ARITHMETIC;
CREATE OR REPLACE PACKAGE BODY ARITHMETIC AS
function add(
first number,
second number)
return number AS
BEGIN
return first + second;
END add;
END ARITHMETIC;
When I run the above code, it results in the following error:
Deploy [tnbdr]DB2INST1.ARITHMETIC Running
DB2INST1.ARITHMETIC - Deploy for debug started.
Create PL/SQL Package Specification returns SQLCODE: -104, SQLSTATE: 42601.
DB2INST1.ARITHMETIC: 1: An unexpected token "PACKAGE" was found
following "CREATE OR REPLACE ". Expected tokens may include:
"VIEW".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.18.60
An unexpected token "PACKAGE" was found following "CREATE OR REPLACE ". Expected tokens may include: "VIEW".. SQLCODE=-104,
SQLSTATE=42601, DRIVER=4.18.60
DB2INST1.ARITHMETIC - Deploy for debug failed.
DB2INST1.ARITHMETIC - Roll back completed successfully.
How can I deploy the package, why is it failing?
Db2 supports the compilation / creation of PL/SQL packages when the database is set up for Oracle compatibility:
db2set DB2_COMPATIBILITY_VECTOR=ORA
db2stop
db2start
Bit 12 in the DB2_COMPATIBILITY_VECTOR enables PL/SQL compilation.

Netezza Stored procedure DB_NAME as an argument

HI everyone I wrote a kind of a simple procedure in Aginity(Netezza). The stored procedure basically has to load data from one db.table1 to db2.table2. Simple right? Then then the procedure - procedure 1 takes in an argument, which is the name of the database(db).
This is the error message I get whenever I try to run my procedure:
/*
ERROR [HY000] ERROR: syntax error, unexpected VARIABLE, expecting BEGIN at or near "db_arg"
*/
The procedure looks like something like this:
CREATE OR REPLACE PROCEDURE LOAD_data_proc(CHARACTER VARYING(15))
RETURNS INTEGER
LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
db_arg CHARACTER VARYING(15);
/* if I remove above declaration I get the following error message: ERROR [HY000] ERROR: ResolveCatalog: error retrieving database 'STG_DB_NAME' */
db_arg ALIAS FOR $1;
/* and bunch of other arguments and declarations */
BEGIN
/* logic here if then else statements */
END;
END_PROC;
Did anyone encounter this problem before?
It's not 100% clear from your description what the actual NZPLSQL code is, but I can reproduce your first error using:
CREATE OR REPLACE PROCEDURE LOAD_DATA_PROC(CHARACTER VARYING(15))
RETURNS INTEGER
LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
db_arg CHARACTER VARYING(15);
db_arg alias for $1;
BEGIN
db_arg := 'SYSTEM';
RAISE NOTICE '%', db_arg;
RETURN 0;
END;
END_PROC;
Note there is a double declaration of the same variable name in the DECLARE block. This is not allowed, and this causes:
ERROR [HY000] ERROR: syntax error, unexpected VARIABLE, expecting BEGIN at or near "db_arg"
Removing one of the declarations will allow the procedure to complete.
IBM docs on NZPLSQL regarding parameter passing to stored procedures is available here: https://www.ibm.com/support/knowledgecenter/SSULQD_7.2.0/com.ibm.nz.sproc.doc/c_sproc_parameter_passing.html
and here:
https://www.ibm.com/support/knowledgecenter/SSULQD_7.2.0/com.ibm.nz.sproc.doc/c_sproc_arg_list.html
As for:
ERROR [HY000] ERROR: ResolveCatalog: error retrieving database 'STG_DB_NAME'
This occurs when I attempt to call a non-existent stored procedure, in a non-existent schema of a non-existent database such as:
CREATE OR REPLACE PROCEDURE LOAD_DATA_PROC(CHARACTER VARYING(15))
RETURNS INTEGER
LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
db_arg alias for $1;
BEGIN
CALL UNKNOWNDB.UNKNOWN_SCHEMA.UNKNOWN_STORED_PROC(1234,5678,7890,123456,1234567);
END;
END_PROC;
which gives me:
ERROR [HY000] ERROR: ResolveCatalog: error retrieving database 'UNKNOWNDB'
Hopefully this helps to explain the errors and how to avoid them.
ok I figured it out... you can pass db_names as arguments to the netezza stored procedure but every time you use the argument inside the procedure, you have to use a dynamic query...
Hope this helps somebody, someday.

Token unknown in SQLCODE

CREATE DATABASE test.fdb -user ZZZZZ -password *******;
I am using above command to create a database for my project in windows 7. I am new to Firebird SQL, I used my system credentials for log in but it is showing some error. So, How can I reset my password?
SQL error code = -104
Token unknown.
I don't even know the significance of SQLCODE = -104.
The error shown is not caused by not knowing the database password, you have a syntax error in the CREATE DATABASE statement. The error Token unknown means that the statement parser read something it didn't expect; the error is usually followed by the offending token.
If I execute your statement using ISQL on Firebird 3.0, I get the following full error:
SQL> CREATE DATABASE test.fdb -user SYSDBA -password *******;
Statement failed, SQLSTATE = 42000
SQL error code = -104
-Token unknown
-test
Which means that at (or before) test something in your query is wrong.
The right syntax for CREATE DATABASE is:
CREATE {DATABASE | SCHEMA} '<filespec>'
[USER 'username' [PASSWORD 'password']]
[PAGE_SIZE [=] size]
[LENGTH [=] num [PAGE[S]]
[SET NAMES 'charset']
[DEFAULT CHARACTER SET default_charset
[COLLATION collation]] -- not supported in ESQL
[<sec_file> [<sec_file> ...]]
[DIFFERENCE FILE 'diff_file']; -- not supported in ESQL
<filespec> ::= [<server_spec>]{filepath | db_alias}
<server_spec> ::= servername [/{port|service}]: | \\servername\
<sec_file> ::= FILE 'filepath'
[LENGTH [=] num [PAGE[S]] [STARTING [AT [PAGE]] pagenum]
In other words your statement should be:
create database 'test.fdb' user SYSDBA password '*******';
So:
Quotes around the path to the database file (or alias)
No - before the user and password clause
Quotes around the password (contrary to the syntax shown, quotes are optional around the user name)
As an aside, the SQL error code is usually not very interesting (as some of them can cover several different errors).