Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use mysql variables

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

What the editor wants to share with you this time is how to use mysql variables. The article is rich in content. Interested friends can learn about it. I hope you can get something after reading this article.

The content of this article is:

System variables user variables local variables

Launch date: 2018-04-18

System variables: system variables are variables that have been defined in advance. System variables generally have their special meaning. For example, some variables represent character sets, some variables represent certain mysql file locations, including session-level variables (variables that take effect during the current session, such as names), and global variables (variables that are always in effect) [Global variables and session variables in system variables actually use a set of variables, but session variables take effect only when the session is used. ] assignment of session variable: set variable name = value; [for example, commonly used set names = "utf8";] or set @ @ variable name = value assignment of global variable: set global variable name = value; view system variable: call of show variables; system variable: select @ @ variable name; user variable: user variable is the variable defined by the user. In order to distinguish system variables from custom variables, the system stipulates that user-defined variables must be defined as @ symbol variables: set @ variable name = 1select @ variable name: = value; select value into @ variable name; user variables can be used directly without declaring the definition, but the default is that null user variables are session-level variables and only take effect in the current connection. Local variables: because local variables are user-defined, it can be considered that local variables are also user variables [but different, local variables do not need to use @] local variables are generally used in sql statement blocks, such as stored procedure blocks, trigger blocks and other local variables: first use declare to declare local variables, where the optional default can be followed by a default value paid to the variable: [very important step Otherwise it will be set to a user variable] [Note: variable declaration statements should precede other statements such as select statements] example: declare myq int Example: declare myq int default 666; set the value of variable: set variable name = value Get the value of the variable: select variable name; create procedure myset () begin declare mya int; declare myq int default 777; select mya,myq; set myq=6; set mya=666; select mya,myq;end;call myset (); add: some people may find the direct set variable name = value; you can also define "user variable" But this is a bad behavior [this behavior ignores the function of the respective variables], because you don't know if it will conflict with the system variable, so it's best to add the user variable @ because =, there are a lot of places to judge whether it is equal or not. to avoid ambiguity, you can also use: = to assign values.

[although some other assignment methods are given above, it seems that some of them are not common, such as: = is used only for user variables, so use it with caution. After reading this article on how to use the mysql variable, if you think the article is well written, you can share it with more people.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report