stored procedures - Using a parameter as a table name in a DB2 SQL cursor and adding two cursors -
i trying parameterise stored procedure , utilize parameter table name. sec part add together returning numbers , assign them variable:
create or replace procedure test (in tab1 char(20), in tab2 char(20), out msg integer) result sets 1 language sql begin declare c1 cursor homecoming select count(*) tab1; declare c2 cursor homecoming select count(*) tab2; open c1; open c2; set msg= c1 + c2; phone call dbms_output.put_line( msg ); end @
the problem is, parameters not set table name resulting in error tab1 not known table. don't know if adding works, didn't far yet, maybe can see error in already.
i hope can help me since driving me crazy.
thanks in advance.
thevagabond
the table name 1 place can't utilize parameters.
you'll need utilize dynamic sql along prepare/execute or execute immediate. note opens door sql injection attacks.
additionally, you're confusing cursors , host variables. can't add together cursors together, can fetch them or homecoming them results sets.
take @ select instead.
sql stored-procedures parameters cursor db2
No comments:
Post a Comment