In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is a detailed introduction to "how to use single quotation marks and double quotation marks of SQL statements". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to use single quotation marks and double quotation marks of SQL statements" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.
1. If there is the following table
mytabe
Field 1 username String type (name)
Field 2 age Numeric (Age)
Field 3 birthday date type (birthday)
Field 4 Marry Boolean (Married or not, True for married, False for unmarried)
Field 5 leixing String type (type)
2. insert string type
If you want to insert a person named Zhang Hong, because it is a character string, so the name in the Insert statement should be added to both sides of the apostrophe, numerical type can not be added single quotes such as:
strsql="Insert into mytable(username) values ('Zhang Hong')"
If the name is now a variable named, write
strsql="Insert into mytable(username) values('" & thename & "')"
Note: & can also be changed to +, string connection
As follows:
Insert into mytable(username) values ('is the part before Zhang Hong, thename is a string variable')
It's the part behind Zhang Hong.
Replace the name variable with Zhang Hong, and then connect the three paragraphs with &, and it becomes
strsql="Insert into mytable(username) values ('Zhang Hong')"
If you want to insert two fields, such as name "Zhang Hong" and type "Student"
strsql="Insert into mytable(username,leixing) values ('Zhang Hong','student')"
If the name is now a variable thename and the type is also a variable thetype, then write:
strsql="Insert into mytable(username,leixing) values('" & thename & "','" & thetype & "')"
As in the first example, replace thename with thetype and concatenate them with the same string as above.
3. insert digit type
If you insert an age 12 record, note that the number does not have a single apostrophe
strsql="Insert into mytable(age) values(12)"
If present age is a variable theage, then
strsql="Insert into mytable(age) values(" & theage & ")"
as follows:
Insert into mytable(age) values
(is the part before 12, theage is the age variable,) is the part after 12.
Replace theage and connect the three parts with the & hyphen to get the same character.
4. insert date type
The date type is similar to the string type, but you replace the apostrophe with a #sign. (However, single apostrophes can also be used in access databases)
strsql="Insert into mytable(birthday) values(#1980-10-1#)"
If you change it to the date variable thedate
strsql="Insert into mytable(birthday) values(#" & thedate & "#)"
Boolean and numeric are similar, except that they have only two values, True and False, such as:
strsql="Insert into mytable(marry) values(True)"
If you change it to the Boolean variable themarry
strsql="Insert into mytable(birthday) values(" & themarry& ")"6. Synthesis Examples
Insert a record with the name Zhang Hong and age 12
strsql="Insert into mytable(username,age) values ('Zhang Hong', 12)"
Pay close attention to the above formula: because the name is a character string, Zhang Hong has a single apostrophe on both sides; age is a number, so there is no single apostrophe. If replaced by the string variable thename and the numeric variable theage, it becomes:
strsql="Insert into mytable(username,age) values('" & thename & "'," & theage & ")"
Note the above formula, in short, replace variables, and then connect to complete the same string as above.
7. tips
To replace the following sentence with variable writing:
strsql="Insert into mytable(username) values ('Zhang Hong')"
Step 1: erase Zhang Hong first and add two quotation marks in the original position.
strsql="Insert into mytable(username) values('" "')"
Step 2: Add two connectors & in the middle
strsql="Insert into mytable(username) values('" & & "')"
Step 3: Write variables between two connectors
strsql="Insert into mytable(username) values('" & thename & "')"
Let's go out of our way to include single quotes when writing SQL queries. It doesn't seem to hurt. Because for query statements with string type as primary key, the performance of adding single quotation marks or not is 100 times different.
Read here, this article "SQL statement single quotation marks and double quotation marks how to use" article has been introduced, want to master the knowledge points of this article also need to practice to understand, if you want to know more related content of the article, welcome to pay attention to the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.