I am new to DB2 and am stuck in altering a stored procedure.
I am on DB2 9.1 version, AIX.
I wrote following SQL in Toad (free version):
ALTER PROCEDURE THE_USER.BONUS_MAIN ( )
REPLACE VERSION V1 ( )
MODIFIES SQL DATA
CALLED ON NULL INPUT
INHERIT SPECIAL REGISTERS
OLD SAVEPOINT LEVEL
BEGIN
...
END
I got error message immediately:
ERROR [42601] [IBM][DB2/AIX64] SQL0104N An unexpected token "ALTER PROCEDURE THE_USER.BONUS_MAIN" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "".
Any tip?
There is no ALTER PROCEDURE statement, you'll need to drop and recreate the procedure. Additionally, you're on such an old version (DB2 9.1 went out of support in April, 2012), you don't even have an option to use CREATE OR REPLACE PROCEDURE....
Related
I have an Oracle stored procedure within the package and I'm successfully run this stored procedure from Oracle SQL DEVELOPER and TOAD.
When I do call in iReport and Jasper Studio - no errors at all but report is blank, no records.
Is any idea?
Here is what I'm doing:
Query Language Executor is PLSQL;
{call DA.PLZ0018_UNION_PR_PKG.UNION_PR_REPORT($P{ORACLE_REF_CURSOR}, $P{P_COMP_CODE}, $P{P_PAY_DATE})}
Stor proc in Oracle screen is attached:
Screen shot is attached
Simply reference the cursor fields by name. For example, to get your first field, 'COMPANY_CODE', create a report field by the same name, then add it to your report. I'm not sure if case matters.
As simple as this sounds, I had to work backwards from a simple test. Try this if you are stuck:
Create a procedure in your existing package:
1) PROCEDURE get_test (p_refcur OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_refcur FOR
SELECT 'Testing' as test from dual;
END;
2) Create a field named 'test'.
3) Add field to detail pane.
I'm trying to create a stored procedure in a DB2 database using RazorSQL Client but I'm getting this error:
Blockquote
ERROR: A character, token, or clause is invalid or missing.
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=SELECT
The stored procedure code is:
CREATE PROCEDURE GENERAL.sp_checkemp
(IN emp_code VARCHAR(20))
LANGUAGE SQL
READS SQL DATA
BEGIN
SELECT "name_emp" FROM GENERAL."employee" WHERE "code_emp" = 'abc';
END
SELECT statements in the SQL PL context must have an INTO clause -- you have to put the query results somewhere. If your query returns more than one row, which I suspect it is, you must use a cursor instead.
I am trying to create a simple stored procedure in DB2 that performs the following actions:
Drop table "DELETE_ME"
Create table "DELETE_ME"
Insert into table "DELETE_ME"
Basically, if the table DELETE_ME already exists, the stored procedure executes fine. If it does not exist, then the Stored Procedure fails with the following error:
Lookup Error - DB2 Database Error: ERROR [42704] [IBM][DB2/LINUXX8664] SQL0204N "SARTS02T.DELETE_ME" is an undefined name.
I completely understand this. However, I was hoping to set the procedure up to ignore this error (and all errors) that way the procedure can work as a deployment script as well. On the first deployment, it will ignore the drop table line and jump right to building the table.
I found a CREATE PROCEDURE option called CONTINUE AFTER FAILURE however I am receiving an error. Please see my code and error below. Thanks for your help!!!
CODE:
CREATE OR REPLACE PROCEDURE TEST_PROC LANGUAGE SQL CONTINUE AFTER FAILURE
BEGIN
DROP TABLE DELETE_ME;
CREATE TABLE DELETE_ME (
COLUMN_A DECIMAL(5)
);
INSERT INTO DELETE_ME (COLUMN_A) VALUES (69);
COMMIT;
END;
ERROR:
Lookup Error - DB2 Database Error: ERROR [42601] [IBM][DB2/LINUXX8664] SQL0104N An unexpected token "CONTINUE AFTER FAILURE" was found following "ST_PROC LANGUAGE SQL". Expected tokens may include: "<space>".
The BEGIN ... END section is called a compound statement which allows various declarations and other statements, including other compound statements, to be included inside it.
You'll want to declare a condition handler. You could do it something like this.
CREATE OR REPLACE PROCEDURE TEST_PROC
LANGUAGE SQL
COMMIT ON RETURN YES
BEGIN
DECLARE CONTINUE HANDLER FOR SQLSTATE '42704' -- or SQLEXCEPTION
BEGIN
-- insert any code here when DROP fails
END;
DROP TABLE DELETE_ME;
CREATE TABLE DELETE_ME
( COLUMN_A DECIMAL(5)
);
INSERT INTO DELETE_ME (COLUMN_A)
VALUES (69);
END;
using IBM DB2 i would like to create a procedure that in case a table does not exist goes to file and start with create and insert statements written in that file. I cannot put all statements inside a procedure because there is just too many of them
my semi-pseudo code so far is
CREATE PROCEDURE KLEMENTEST.create_table
()
LANGUAGE SQL
begin atomic
if (not exists(select 'A' from syscat.tables where tabschema = 'TESTSCHEMA' and tabname='TESTTABLE')) then
--- run queries from file located in "c:\path\to\file.txt"
end if
end ;
any suggestions ??
thank you
There are several options:
1) Create an external stored procedure in Java or C that will execute the command that you want. For example
db2 -tf file.sql
Remember to execute DB2 with a profile (. db2profile). You will call this stored procedure after having test that the table does not exist.
2) Create the stored procedure, and read the content of the file that contains the ddl, then with the content, you create a dynamic SQL. You can read files via UTL_FILE module. However, this module is not available in Express-C edition. http://publib.boulder.ibm.com/infocenter/db2luw/v10r1/topic/com.ibm.db2.luw.apdv.sqlpl.doc/doc/r0053689.html
The general problem of this approach is the location of the file to "execute" in the file system, and also the stored procedure becomes platform dependent.
I am trying to write a simple Oracle Stored Procedure:
CREATE OR REPLACE PROCEDURE act.skeleton
IS
DECLARE
v_rowCount NUMBER;
BEGIN
SELECT COUNT(1) INTO v_rowCount FROM ex.emp;
DBMS_OUTPUT.PUT_LINE(v_rowCount);
END;
However, when I try & run the procedure by issuing execute act.skeleton in PL/SQL Developer command window, I get the following error message:
ORA-06550: line 1, column 11:
PLS-00905: object ACT.SKELETON is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
I tried to just run the code without the create procedure statement & it runs successfully with the output being displayed. I have tried both CREATE OR REPLACE PROCEDURE IS & CREATE OR REPLACE PROCEDURE AS options but I still get the same error.
I am not sure if this has anything to do with authorization or visibility of the procedure when I try and execute it or what is causing the act.skeleton object to be invalid. I looked into what the error means & it seems it usually refers to compilation error in the procedure but since I can run the code sans the procedure declaration, I am guessing the declaration piece is the culprit. I just don't know enough to figure out what is causing this and I was hoping that someone will be able to shed some more light on it and point me in the right direction
Thanks,
Ashish
Other Details:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
Don't use the DECLARE keyword in a stored procedure declaration. Remove that and it should compile.