码迷,mamicode.com
首页 > 数据库 > 详细

SQL 語法

时间:2018-07-10 21:33:15      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:table   var   rop   wmi   排序   asc   rom   操作符   order by   

查詢

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

标签:table   var   rop   wmi   排序   asc   rom   操作符   order by   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!