Oracle查询如下所示:Select ‘Name’ || ‘Last Name’ From tableName
SQL Server查询如下:Select ‘Name’ + ‘Last Name’
Oracle数据库内有一个TRUNC函数,该函数返回m位十进制数的n位;如果省略m则n就是0位。m的值可以为负,表示截去小数点左边m位数字。
在SQL Server下可以用Round或者Floor。
Oracle查询如下所示:SELECT TRUNC(15.79,1) "Truncate" FROM DUAL;
SQL Server查询如下:SELECT ROUND(15.79, 0) rounded , ROUND(15.79, 0,1) truncated
SELECT FLOOR(ROUND(15.79, 0)), FLOOR(ROUND(15.79, 0,1) )
Oracle的TO_CHAR函数可以把n位NUMBER数据类型转换为VARCHAR2 数据类型,同时采用可选的数字格式。
SQL Server则通过STR函数返回数字转换之后的字符数据。不过,该函数不具方便的Format参数。
Oracle查询如下所示:SELECT to_char(123.45 ,99999999999999) from tab
SELECT to_char(EXPIRY_DATE,'DDMONYYYY') from tab
SQL Server查询如下:SELECT STR(123.45, 14)
SELECT STR(round(123.455 , 2),12,2)
SELECT CAST(REPLACE((CONVERT(varchar(12) , EXPIRYDATE, 106 )),' ' , '') as varchar(9))
Oracle查询如下所示:SELECT LENGTH('SQLMAG') "Length in characters" FROM DUAL;
SQL Server查询如下:SELECT LEN('SQLMAG') "Length in characters"
两种系统都具有各自的当前日期和时间格式。
Oracle取得日期和采用如下方式:SYSDATE
SQL Server则是这样的:GETDATE()
你可以用各种语法操作日期。
SQL Server则是如下完成同等功能的:Select dateadd(mm,12,getdate())
数据的减法也不同。
SQL Server则是这样做的:SELECT datediff(dd, GetDate(),dateadd(mm,12,getdate()))
PLSQL执行查询的时候,FROM子句是必须的,而SQL SERVER不一定
如ORACLE中select 2*5 from dual
而SQL SERVER中select 2*5
SQLserver与Oralce中的两表关联更新是区别的。
在T-SQL中更新相对简单些,直接用下面的语句都是可以:
Update b
Set b.processflag = a.processflag
From temp_1 a Join temp_2 b
On a.msgid_db = b.msgid
Update temp_2
Set Usertime = b.Usertime
From temp_2 a Join temp_1 b
On a.msgid = b.msgid_db
Update temp_2
Set Usertime = b.Usertime
From temp_1 b
where msgid = b.msgid_db
而在Oracle中这样写是不对的,应该更改如下:
Update Temp_2 a
Set a.Usertime = (Select b.Usertime
From Temp_1 b
Where b.Msgid_Db = a.Msgid)
Where Exists (Select 1 From Temp_1 b Where b.Msgid_Db = a.Msgid);
更新多个字段:
Update Temp_2 a
Set a.Usertime = (Select b.Usertime
From Temp_1 b
Where b.Msgid_Db = a.Msgid),
a.processflag = (Select b.processflag
From Temp_1 b
Where b.Msgid_Db = a.Msgid)
Where Exists (Select 1 From Temp_1 b Where b.Msgid_Db = a.Msgid);
多表关系更新:
Update Temp_2 a
Set a.Usertime = (Select b.Usertime
From Temp_1 b
Where b.Msgid_Db = a.Msgid),
a.processflag = (Select c.processflag
From Temp_3 c
Where c.Msgid = a.Msgid)
Where Exists (Select 1 From Temp_1 b Where b.Msgid_Db = a.Msgid)
And Exists (Select 1 From Temp_3 c Where c.Msgid = a.Msgid);
感觉这点没sqlserver理简单易用~~~