SQL 語法
Posted leme
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL 語法相关的知识,希望对你有一定的参考价值。
查詢
Sql = ("SELECT A1, A2, A5, A4 FROM Table1 ")
筆數
Sql = ("Select COUNT(*) From TW01.VW_DECA_oea WHERE (oeb04 = ‘TEST‘)")
更新
Sql1 = ("update Table1 set A5 = ‘TEST1‘ where (A1 = ‘TEST2‘) ")
Sql = (Sql1)
新增
Sql1 = "insert into Table4 (A1,A2,A3,A4) values (‘TEST1‘,‘TEST2‘,‘TEST3‘,‘TEST4‘)"
Sql = (Sql1)
刪除
Sql1 = ("delete from Table1 where (A1 = ‘TEST1‘)")
Sql = (Sql1)
排序
SELECT A1, A2 FROM T1 ORDER BY A1
降序排序
SELECT A1, A2 FROM T1 ORDER BY A1 DESC
A1降序排序,A2升序排序
SELECT A1, A2 FROM T1 ORDER BY A1 DESC, A2 ASC
空值取代
ISNULL((IMA25, ‘空值‘) AS IMA25 ‘FOR SQL SERVER
NVL(IMA25, ‘空值‘) AS IMA25 ‘FOR Oracle
IIF ( a.IMA25 IS NULL, ‘空值‘, a.field1) AS IMA25 ‘FOR ACCESS
‘建表
sqlStr = "CREATE TABLE ecb(ecb01 int ,ecb02 int,ecb03 int)"
‘新增欄位
sqlStr = "ALTER TABLE oga ADD oga101 varchar(50),oga102 varchar(50),oga103 varchar(50)"
‘修改欄位
sqlStr = "ALTER TABLE ecb alter column ecb03 varchar(50)"
‘刪除欄位
sqlStr = "ALTER TABLE ogb DROP COLUMN ogb08"
LIKE 操作符
SELECT A1, A2, A5, A4 FROM Table1 WHERE A1 LIKE ‘N%‘
SELECT A1, A2, A5, A4 FROM Table1 WHERE A1 LIKE ‘N_‘
SELECT A1, A2, A5, A4 FROM Table1 WHERE LIKE ‘[!ALN]%‘
Oracle
日期格式
select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss‘) as nowTime from dual; //日期转化为字符串
select to_char(sysdate,‘yyyy‘) as nowYear from dual; //获取时间的年
select to_char(sysdate,‘mm‘) as nowMonth from dual; //获取时间的月
select to_char(sysdate,‘dd‘) as nowDay from dual; //获取时间的日
select to_char(sysdate,‘hh24‘) as nowHour from dual; //获取时间的时
select to_char(sysdate,‘mi‘) as nowMinute from dual; //获取时间的分
select to_char(sysdate,‘ss‘) as nowSecond from dual; //获取时间的秒
以上是关于SQL 語法的主要内容,如果未能解决你的问题,请参考以下文章