MySQL function dynamically executes different SQL statements

Source: Internet
Author: User


Create procedurecps ()begin DeclareTable_uservarchar( $)default 'User'; SetstrSQL=Concat'SELECT * from', Table_user); PrepareA fromstrSQL;ExecuteA;End;

There will be errors in this process.

How do I use SQL to execute strings?

Need to use prepare to precompile SQL

Prepare  from ' SELECT * from food '  Execute

This is possible.

What if the statement is mutable? Do you need variables to hold part of the information and what are the variables required?

So, if you want to use the session level variable, you must add the @ symbol before the variable.

Of course, using prepare can also use parameters like this:

I'm looking for a problem. A collection version of the information, refer to the link:

http://bbs.csdn.net/topics/350158591

MySQL function dynamically executes different SQL statements

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.