Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use quotation marks written by dynamic statements in mysql

Shulou Source: shulou.com Published: 2022-05-31 15:46:17 10月26日 Update

This article mainly shows you the "mysql dynamic statements written in quotation marks how to use", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "mysql dynamic statements written in quotation marks how to use" this article.

When we write the dynamic SQL of MYSQL stored procedures, we often write the SQL prototype first, and then write it in a dynamic form according to our needs.

But often this process is very painful, because you can deal with a lot of single quotes and some special characters.

When we write the dynamic SQL of MYSQL stored procedures, we often write the SQL prototype first, and then write it in a dynamic form according to our needs.

But often this process is very painful, because you can deal with a lot of single quotes and some special characters. If you have written about ORACLE PL/SQL, you will have the experience of meeting.

Fortunately, however, double quotation marks are supported in MYSQL. That is to say, if you basically don't change the SQL prototype, MYSQL will move here as is.

For example, the SQL prototype we want is as follows:

Select * from mysql.user where user='root' limit 10

If written as dynamic SQL:

Set @ sql = "select user,host from mysql.user where user='root'"

Set @ sql = concat (@ sql, "

Limit 10 ")

Prepare sql1 from @ sql

Execute sql1

Deallocate PREPARE sql1

The above is all the contents of the article "how to use quotation marks in dynamic statements in mysql". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Dynamic quotation marks prototypes procedures statements content articles special painful characters forms processing storage learning help luck that is as is easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology macOS Redmi Linux