Using cursor in SQLRPGLE

40 pts.
Tags:
SQL statement
SQLRPGLE
Can i use single cursor for multiple SQL statements? ex:  declare c1 cursor for select * from ....... also declare c1 cursor for select * from xxx

Software/Hardware used:
AS400

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    I've never tried. I suppose that as long as one cursor was closed before you opened the other, and the two declares themselves were on different code paths, it could be done.   But it's hard to think of a reason to do it since there's a far easier alternative:  
    sql_stmt = 'SELECT * FROM ...'exec sql prepare stmt from :sql_stmt;exec sql declare C1 cursor for stmt;exec sql open C1;
      (That code looks perfect in the editor, but I suspect it will look a mess when I submit it.) Multiple assignments can be made for sql_stmt to use whatever SELECT statement you want. (Of course, you should never use "*" for the column list; but that's not what you're asking about.)   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Sorry. The four lines of code ran together.   sql_stmt = 'SELECT * FROM ...' exec sql prepare stmt from :sql_stmt; exec sql declare C1 cursor for stmt; exec sql open C1;   Those might or might not come across as readable.   Tom
    125,585 pointsBadges:
    report
  • BigKat
    yes, you can build a select statement in a variable, then exec sql prepare sql1 from :stmsql1;                         exec sql declare csr1 cursor for sql1;                       exec sql open csr1 using :fltvnd, :fltvnd, :fltdsc, :fltdsc; exec sql fetch csr1 into :fpitmmas;                          exec sql close csr1;  then re-build a new select and repeat as desired
    7,845 pointsBadges:
    report
  • BigKat
    exec sql prepare sql1 from :stmsql1; exec sql declare csr1 cursor for sql1; exec sql open csr1 using :fltvnd, :fltvnd, :fltdsc, :fltdsc; exec sql fetch csr1 into :fpitmmas; exec sql close csr1;
    7,845 pointsBadges:
    report
  • philpl1jb
    Can i use single cursor for multiple SQL statements? ex:  declare c1 cursor for select * from ....... also declare c1 cursor for select * from xxx   No.  I've forgotten if it was the precompiler or compiler that rejected this regardless of the close cursor commands.    But as BigCat pointed out you can use a single dynamic SQL command multiple times with different SQL statments, just remember to close the cursor after use.  Phil
    49,435 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following