Simple implementation of SQL Server and PL/SQL dynamic cursors

Source: Internet
Author: User
SQL Server Dynamic Cursor
Declare @ SQL varchar (2000 ),
@ Typefield varchar (100 ),
@ Tablename varchar (255 ),
@ Name varchar (100)
Select @ typefield = 'name', @ tablename = 'sysobjects'
Set @ SQL = 'Clare cutemp cursor'
+ 'Select distinct '+ @ typefield + 'from' + @ tablename
Exec (@ SQL)
Open cutemp
Fetch cutemp into @ name
While (@ fetch_status = 0)
Begin
Print @ name
Fetch cutemp into @ name
End
Close cutemp
Deallocate cutemp
Dynamic PL/SQL cursor
Create or replace procedure activecursor (TN varchar2)
A1 number (10): = 0;
SQL _statement varchar2 (1000 );
Type curtype is ref cursor;
Cur_jilh curtype;
Begin
Savepoint ticketcount;
SQL _statement: = 'select AA, BB from '| tn;
Open cur_jilh for SQL _statement;
Loop
Fetch cur_jilh
Into SQL _statement, A1;
Exit when cur_jilh % notfound;
End loop;
Close cur_jilh;
Commit;

Exception
When others then
Rollback to ticketcount;
End activecursor;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.