MySQL plsql Demo-004. Simulating dynamic cursors

Source: Internet
Author: User

Reference: Write a MySQL stored procedure for dynamic execution of SQL, or you can use temporary tables instead of views.

Drop procedure if existsP_simulate_dynamic_cursor;Create procedurep_simulate_dynamic_cursor ()begin    DeclareV_sqlvarchar(4000); DeclareV_fieldvarchar(4000); DeclareV_resultvarchar(4000)default "'; DeclareCur_tempcursor  for SelectV.*  fromview_temp_20150701 v; Declare ContinueHandler for  notFoundSetV_field= NULL; SetV_sql= 'CREATE View view_temp_20150701 as select T.id from T_user t'; Set @v_sql =V_sql; PrepareStatement from @v_sql; Executestatement; deallocate Preparestatement; Opencur_temp; FetchCur_temp intoV_field;  while(V_field is  not NULL) doSetV_result=Concat (V_result, V_field,','); FetchCur_temp intoV_field; End  while; Closecur_temp; SelectV_result; Drop View if existsview_temp_20150701;End; call P_simulate_dynamic_cursor (); 

MySQL plsql Demo-004. Simulate dynamic cursors

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.