首页 > 数据库技术 > 详细

SQL 語法

时间:2018-07-10 21:16:50      阅读:172      评论:0      收藏:0      [点我收藏+]

查詢

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 語法

原文:https://www.cnblogs.com/leme-chen/p/9291280.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!