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 operate with sql when there are slashes or spaces in the fields of MySQL database

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

Share

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

The following mainly brings you how to operate with sql when there are slashes or spaces in MySQL database fields. I hope these contents can bring you practical use. This is also the main purpose of this article when I edit MySQL database fields with slashes or spaces. All right, don't talk too much nonsense, let's just read the following.

For this special character, we generally think of using escape characters, so we try common escape characters such as "/", quotation marks, single quotation marks, etc., and find that there are still grammatical errors, and check the official description of mysql:

Special characters must be escaped when they are in a column name, and if the column name contains\ t, (,), /,\, =, +, -, *, ^, ",', [,], ~, #, |, &,% must be enclosed in square brackets. Eg: the column name Column#, should be written as [Column#]; the column name includes square brackets and must be escaped using slashes, and eg: the column named Column [] should be written as [Column [\]] (only the second square bracket must be escaped).

Escape in the form of square parentheses, and then try the following parentheses and find that it still doesn't work.

Through the search, it is found that you need to deal with the reverse quotation mark "`" (the key to the left of the number 1 in the upper-left corner of the general keyboard).

The use of other backquotes

Backquotation marks have hardly been used before, so take this opportunity to search for and summarize the use of lower backquotes.

The role of Linux backquotes

Special assignment

In Shell, you can assign numbers or characters to variables directly, or you can assign variables the execution result of the Linux command, as follows:

(1) $count=9 # assigns the number to the variable count

(2) $name= "ming" # assigns characters to the variable name

(3) the value assigned to listc,listc by the Linux command by $listc= `ls-la` # is the result of the execution of the command

The function of backquotation marks

The function of the backquote is to execute the Linux command within the backquote first, and then assign the execution result to the variable. Although you can create variable values by entering characters or strings, you can also get values from other Linux commands. To assign the result of the Linux command to a variable, the implementation needs to execute this command. If you put the Linux command in backquotes on the command line, the command will be executed first and the result will be an argument to the command line. When assigning a value, the execution result of the command is assigned a variable by placing the command in backquotes so that it can be executed first. Backquotes can be thought of as expressions made up of commands to be executed, and the result is assigned to a variable. The characters that make up the command itself are not assigned. In the following example, the command ls. C is executed, and the result is then assigned to the variable listc. Ls .c generates a list of all files with the .c extension. The list of files is then assigned the variable listc.

Summary (http://www.2hxn.com)

The string in the backquote must be an executable command, otherwise an error will occur; its function is to replace the command, execute the string as a Shell command, and return the result of the command.

The function of backquotation marks in mysql

Symbols introduced to distinguish reserved words from ordinary characters in MYSQL

For example: SELECT `select`FROM `test`WHERE select=' field value'

In the test table, there is a select field, and if you do not use backquotes, MYSQL will treat select as a reserved word, resulting in an error, so those with MYSQL reserved words must be distinguished in backquotes.

Quotation marks are generally used in the value of a field. If the field value is a character or string, add quotation marks, such as: select=' field value'

Tables built without backquotes cannot contain MYSQL reserved words, otherwise there will be an error

Backquotation mark, the symbol to the left of the number 1

Reserved words cannot be used for table names, such as desc, which need to be distinguished by backquotation marks, but can be ignored when using table names.

Create table desc reported an error

Create table `successful`

Create table `test` succeeded

Drop table test succeeded

Reserved words cannot be used for field names, such as desc, where backquotation marks are also required, and backquotes are also required when using insert and so on.

Create table `test` (`room`varchar (255)) succeeded

Insert into test (desc) values ('fxf') failed

Insert into test (`room`) values ('fxf') succeeded

For the above MySQL database fields with slashes or spaces, how to use sql operation, we do not think it is very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.

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