I´ve been trying to call a Package from a Stored Procedure, but I'm not able to.
I tried to create it as below:
CREATE PROCEDURE DGOWNDB.ZHG0002I
(IN col1 CHAR (03) FOR SBCS DATA CCSID EBCDIC,
IN col2 CHAR (20) FOR SBCS DATA CCSID EBCDIC,
IN col3 CHAR (03) FOR SBCS DATA CCSID EBCDIC)
DYNAMIC RESULT SETS 1
NOT DETERMINISTIC
LANGUAGE COBOL
FENCED
WLM ENVIRONMENT ENVWLM
BEGIN
EXTERNAL NAME 'PHGS222E'
;
I'm getting the Db2 error code -444, saying that it's not able to found the package
DSNT408I SQLCODE = -444, ERROR: USER PROGRAM PHGS222E COULD NOT BE FOUND
DSNT418I SQLSTATE = 42724 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNX9CAC SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = 0 0 0 -1 0 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'00000000' X'00000000' X'00000000' X'FFFFFFFF'
X'00000000' X'00000000' SQL DIAGNOSTIC INFORMATION
I've tried to use both SET CURRENT PACKAGESET and CURRENT PACKAGE PATH special register but had no success.
I've tried to search but didn't find anything that helped. Insight from others is welcome.
Regards
Related
I was wondering if someone could help me with the error message I am getting from Snowflake. I am trying to create a stored procedure that will loop through 125 files in S3 and copy into the corresponding tables in Snowflake. The names of the tables are the same names as the csv files. In the example I only have 2 file names set up (if someone knows a better way than having to liste all 125, that will be extremely. helpful) .
The error message I am getting is the following:
syntax error line 5 at position 11 unexpected '1'.
syntax error line 6 at position 22 unexpected '='. (line 4)
CREATE OR REPLACE PROCEDURE load_data_S3(file_name VARCHAR,table_name VARCHAR)
RETURNS VARCHAR
LANGUAGE SQL
AS
$$
BEGIN
FOR i IN 1 to 2 LOOP
CASE i
WHEN 1 THEN
SET file_name = 'file1.csv';
SET table_name = 'FILE1';
WHEN 2 THEN
SET file_name = 'file2.csv';
SET table_name = 'FILE2';
--WILL LIST THE REMAINING 123 WHEN STATEMENTS
ELSE
-- Do nothing
END CASE;
COPY INTO table_name
FROM #externalstg/file_name
FILE_FORMAT = (type='csv');
END LOOP;
RETURN 'Data loaded successfully';
END;
$$;
There are various ways to list the files in a stage (see the post here). You can loop through the resultset and run COPY INTO on each record
I have a db2 stored procedure like below. This proc is calling a CL to invoke an RPG program.
CREATE PROCEDURE bsm4obj/TXCL4055
(
INOUT POCNO CHAR (10),
INOUT POCRN DEC ( 2 , 0 ),
INOUT PSPNO CHAR (10),
INOUT PMTAD CHAR (1),
INOUT PYREX CHAR (1),
INOUT PMTYR CHAR (1),
INOUT PKMLK CHAR (10),
INOUT HATVR CHAR (1)
)
LANGUAGE CL NOT DETERMINISTIC NO SQL EXTERNAL
NAME bsm4obj/txCL4055 PARAMETER STYLE GENERAL
I call this proc from the server. (ODBC language ID Turkish);
OdbcCommand cmd = new OdbcCommand("{CALL BSM4OBJ.TXCL4055(?,?,?,?,?,?,?,?)}", as400con);
cmd.CommandType = CommandType.Text;
When executing the RPG program (in step like below) variable 'ŞŞ' is not recognizing by compiler like it is but '##'.
TSDEPR IFEQ 'ŞŞ'
//Reading like TSDEPR IFEQ '##'
The program is executing perfectly in QPADEV session on As400 but on SQL call does not behave like this.
I replaced turkish static chars with equivalent char for temporary in RPG.
But i want to find exact solution.
I will be very pleased if you suggest
By default, RPG doesn't always handle character literals correctly. It saves the hex value of the literal in the compile-time CCSID, but it interprets the hex value in the job CCSID.
Starting in 7.2, you can code H spec keyword CCSID(*EXACT), and that will cause RPG to remember the true CCSID of character literals.
Another workaround is to code the literal with %UCS2.
if TSDEPR = %ucs2('ŞŞ');
Does anybody know, if there is a command string size limitation in Firebird?
When executing a small "insert" script it works perfectly, but when the script has a lot of lines it returns the following errer: "Unexpected end of command - line X, column Y".
Interessting, the line and column number varies dependanding on the actual script size.
I'm using Firebird 2.5
Here is the executing script:
set term ^ ;
EXECUTE BLOCK AS BEGIN
insert into TABLE (COLUMNA) values (13);
...
insert into TABLE (COLUMNA) values (14);
END^
set term ; ^
Firebird 2.5 and earlier have a limitation of 64 kilobytes for the query text, for Firebird 3.0 this limit was increased to 10 MB when the new API is used. An EXECUTE BLOCK is one query, so it should not exceed 64 kilobyte.
DB2 V9 Z/Os
CREATE PROCEDURE SERDB.I21MMSNOUPD ()
RESULT SETS 1
LANGUAGE SQL
FENCED
COLLID SER
WLM ENVIRONMENT DDSNSPENV
RUN OPTIONS 'NOTEST(NONE,*,*,*)'
P1: BEGIN
--Declare variables
DECLARE CONSUMER INTEGER;
DECLARE NEW_MMS_NO INTEGER;
DECLARE END_TABLE INT DEFAULT 0;
DECLARE C1 CURSOR FOR
SELECT I20_CONSUMER_ID,
NEW_MMS_NO
FROM SERDB.I20_TEMP
-- WHERE I20_CONSUMER_ID = 164921;
ORDER BY I20_CONSUMER_ID;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET END_TABLE = 1;
OPEN C1;
FETCH C1 INTO CONSUMER,
NEW_MMS_NO;
WHILE END_TABLE = 0 DO
UPDATE SERDB.I20_CONSUMER_T
SET I20_MMS_NO = NEW_MMS_NO
WHERE I20_CONSUMER_ID = CONSUMER;
END WHILE;
CLOSE C1;
END P1
The above stored procedure builds with a cond code 0, but fails to execute even when a specific consumer_id. Does anyone see something wrong?
Individual sql statements run exactly as they're supposed to.
I've followed the examples for Cursors in SQL Procedures from IBM.
Thank you
I agree 100% with #X-Zero, this seems like a huge amount of work defining cursors and what-not, when you could do a simple set-based operation (likely with better performance). Here are two examples of how you can do it with a single operation:
Normal UPDATE:
UPDATE SESSION.I20_CONSUMER_T A
SET I20_MMS_NO = (
SELECT NEW_MMS_NO
FROM SESSION.I20_TEMP B
WHERE A.I20_CONSUMER_ID = B.CONSUMER
)
WHERE EXISTS (
SELECT 1
FROM SESSION.I20_TEMP C
WHERE A.I20_CONSUMER_ID = C.CONSUMER
)
New MERGE hotness:
MERGE INTO SESSION.I20_CONSUMER_T AS T
USING SESSION.I20_TEMP AS M
ON T.I20_CONSUMER_ID = M.CONSUMER
WHEN MATCHED THEN
UPDATE SET T.I20_MMS_NO = M.NEW_MMS_NO
ELSE IGNORE
These were tested on DB2 for Linux/Unix/Windows v9.7, but should work on any version of DB2 newer than 9.1 (DB2 for iSeries is a wildcard, I never remember what that platform does or doesn't support :) )
The FETCH command must be inside the WHILE, so that each time it is invoked, it fetches a row.
I have the following code:
delimiter ;
DROP PROCEDURE IF EXISTS ufk_test;
delimiter //
CREATE PROCEDURE ufk_test(IN highscoreChallengeId INT UNSIGNED)
BEGIN
DECLARE vLoopOrder INT UNSIGNED DEFAULT 5;
DECLARE vLoopLimit INT UNSIGNED DEFAULT 10;
select * from fb_user LIMIT vLoopOrder,vLoopLimit;
END//
delimiter ;
Mysql returns the following error:
ERROR 1064 (42000): 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 'vLoopOrder,vLoopLimit;
END' at line 11
it seems that I cannot use declared variables in a LIMIT statement. is there any other way to overcome this ?
of course this is a simple example, here i could just put static numbers but I need to know if it's possible in any way to use any kind of variables with LIMIT.
Thanks
i use something like:
SET #s = CONCAT('SELECT * FROM table limit ', vLoopOrder ', ', vLoopLimit);
PREPARE stmt1 FROM #s;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;