数据库中的单引号双引号和&符号的用法和区别

在sql语句中经常会用到单引号双引号和&,下面以insert语句为例,select,update,delete语句都是一样的

1.插入字符串型
插入名字为张红的人,是字符串,所以insert语句当中名字两边要加单引号

strsql=“insert into mytable(username) values('张红') ”

如果名字变成了一个变量 thename,语句要写成:
strsql=“insert into mytable(username) values('“ & thename & ”') ”注意所有的连接符前后需要有空格
如果插入的是两个字段:

strsql=“insert into mytable(username,type) values('张红',‘学生’) ”
strsql=“insert into mytable(username,type) values('“ & thename&”','“ & thetype & ”') ”   

这时候插入了两个变量thename和thetype

2.插入数字型
插入数字型数据不用添加单引号
插入年龄18,语句:

strsql=“insert into mytable(age) values(18) ”

如果年龄变成一个the age的变量,
语句:strsql=“insert into mytable(age) values(“ & theage & ”) ” 这时候因为是数字所以不需要用单引号了

3.插入日期型数据,日期型数据和单引号类似,但是要将单引号换为#

Strsql="insert into mytabel (birthday) values (# 2019-5-2 #)"

将日期换为the table,strsql=“insert into mytable(birthday) values (#“ & thedate & ”#)”

4.插入布尔型,布尔型和数字类型类似,只不过是有两个值true 和false

strsql=“Insert into mytable(marry) values(True)”

如果换成布尔变量themarry

strsql=“Insert into mytable(birthday) values(“ & themarry &  ”)”

总结:字符串变量需要用单引号,数字和布尔型变量不需要单引号,日期需要用#,access数据库中用单引号也可以
替换变量:要加双引号,双引号中间需要有连接符& &
在敲学生的时候,会看到下面这样的语句:

txtsql = "select * from user_info where user_id='" & Username & "'"

在这里username就是一个变量需要用双引号和连接符&

原文链接:http://www.knowsky.com/555140.html

评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值