How to execute dynamic SQL statements in MySQL stored procedures

Source: Internet
Author: User

How to execute dynamic SQL statements in MySQL stored procedures

Drop PROCEDURE if exists my_procedure; create PROCEDURE my_procedure () BEGIN declare my_sqll varchar (500); set my_sqll = 'select * from aa_list '; set @ ms = my_sqll; PREPARE s1 from @ ms; EXECUTE s1; deallocate prepare s1; end;

In MySQL, how does one write SQL statements to call stored procedures?

Call sp_add ();
Is there a problem with the process you defined, and the returned results are not pointed out?
Like me:

Create procedure sp_add (a int, B int, out c int)
Begin

Set c = a + B;

End;
Call process:
Call sp_add (1, 2, @ );
Select @;

How can I write multiple dynamic SQL statements in the mysql stored procedure and call the value of the first dynamic statement for the Second Dynamic statement?

Declare @ d1 datetime
Set @ d1 = '2017-12-31'
Select dateadd (year,-1, @ d1) as date of the same day of the previous year

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.