Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please let me know how I create a c

Status
Not open for further replies.

DEBUINFO4GL

Programmer
Nov 12, 2003
3
SG
Please let me know how I create a cursor in store procedure?

see the below SQL.

SELECT cust_code,cust_name INTO m_code,m_desc
FROM customer WHERE ..............
UNION
SELECT order_no,order_desc INTO m_code,m_desc
FROM order WHERE ...............

The above select are giving error in store procedure, because I am using two time INTO statement.

If I want to avoid INTO statement than I need a cursor in store procedure.

Please can any one help me (How I create a cursor in store procedure).

Thanks
Debu
 
Hi:

If tab1 and tab2 are a the same structure, this should work:

DROP PROCEDURE x_proc;
CREATE PROCEDURE x_proc()
RETURNING CHAR(10), CHAR(40);
DEFINE p_1 CHAR(10);
DEFINE p_2 CHAR(40);

FOREACH
SELECT *
INTO p_1, p_2
FROM tab1
UNION
SELECT *
FROM tab2

RETURN p_1, p_2 WITH RESUME;

END FOREACH
END PROCEDURE
# end proc

The trick is to only have the "into" on the first select.

Regards,

Ed

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top