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