SQL Server 与 ORACLE 的区别
sql server 與? oracle的區(qū)別: ?? DBMS 數(shù)據(jù)庫管理系統(tǒng)
1.數(shù)據(jù)類型不同。?? sql server 的數(shù)據(jù)類型:int ,smallint ,char,varchar,nchar,nvarchar,ntext,datetime,smalldatetime,money,decima,?? float,bit……??? oracle 的數(shù)據(jù)類型:number(p,s),char,varchar2,Date,LOB 注意:insert into table_name values('1','張三','男',date'2012-3-5'); -插入字符串日期前加date轉(zhuǎn)換類型??
2.獲得當(dāng)前系統(tǒng)時(shí)間的函數(shù)不同。?? sql server :getdate() oracle:sysdate 例如:設(shè)定日期格式的函數(shù):to_char(sysdate,'yyy-mm-dd');
3.在oracle中沒有默認(rèn)約束的說法?? sql server 中添加默認(rèn)約束:alter table talbe_name add DF_table_name default('男') for sex; oracle 中添加默認(rèn)值:alter table table_name modify(sex default('男'));
4.連接變量和字符串的方式不一樣?? sql server 中連接:使用“+”連接,例如:print ?'aaaa'+@name; oracle? 中連接:使用“||”連接,例如:dbms_output.put_line('aaa'||name); -name為變量
5.oracle沒有identity自動(dòng)增長列,而是使用序列實(shí)現(xiàn)增長?? sql server 自動(dòng)增長:在表的主鍵列中可直接使用identity(1,1)實(shí)現(xiàn)增長 oracle 使用序列自動(dòng)增長:create sequence se_id start with 1increment by 1?? 使用序列實(shí)現(xiàn)自動(dòng)增長:se_id.nextval
6.條件語句if……else……的語法不同?? sql server中: if 條件 begin? ………… end else begin?? ………… end??? oracle中: if 條件1 then …………; elsif 條件2 then …………; else?? …………; end if;
7.case語句的語法不同?? sql server中: select ....case.....(else)....end....語句 select stuno '學(xué)號(hào)',case when grade>=90 and grade<=100 then '★★★★' when grade>=80 and grade<90 then '★★★' when grade>=70 and grade<80 then '★★' when grade>=60 and grade<70? then '★' else '差' end as '等級(jí)' from score go?? oracle中: declare nums number:=&nos; &nos表示提示傳入值 begin?? case nums? when 100 then??? dbms_output.put_line('滿分也,不錯(cuò)');? when 90 then??? dbms_output.put_line('90分頁很不錯(cuò)了');? end case; end;
8.觸發(fā)器創(chuàng)建語法不同? sql server中:?? 首先判斷觸發(fā)器是否已經(jīng)存在 if exists (select * from sys.sysobjects where name='tr_delete') 如果存在先刪除 drop trigger tr_delete go?? 創(chuàng)建觸發(fā)器create trigger tr_deleteon bookInfoinstead of deleteas 定義變量 declare @bookid int? select @bookid=Bookid from deleted -deleted執(zhí)行刪除語句( delete from BookInfo where BookId=1),自動(dòng)生成的deleted表 刪除與該圖書的相關(guān)記錄(先刪除從表再刪除主表) delete from borrowinfo where? bookid=@bookid delete from backinfo where? bookid=@bookid delete from BookInfo where BookId=@bookid 判斷 if @@error<>0 begin? print '刪除失敗'? rollback transaction end else begin? print '刪除成功' endgodelete from BookInfo where BookId=1 oracle中: 創(chuàng)建觸發(fā)器create or replace trigger tri_testbefore insert or update or delete on table_name[for each row] -如果要使用 :new /:old 就必須使用行觸發(fā)器declare? nums varchar2(20);begin? select 'F'||lpad('aa',5,0) into ?nums from dual;end;? ? 9.oracle中的存儲(chǔ)過程 sql server中存儲(chǔ)過程:? 判斷存儲(chǔ)過程是否已經(jīng)存在 if exists(select * from sys.sysobjects where name='proc_name')? 如果存在先刪除? drop proc proc_name go? 創(chuàng)建存儲(chǔ)過程語句 create proc/procedure proc_name @參數(shù)名1 數(shù)據(jù)類型 [out/output], @參數(shù)名2 數(shù)據(jù)類型 [out/output] as??? ………… go? 調(diào)用存儲(chǔ)過程 如果有輸出參數(shù),則需定義變量(假設(shè)@參數(shù)2為輸出參數(shù)) declare @變量名 數(shù)據(jù)類型 exec proc_name @參數(shù)名1='aaa',@參數(shù)名2=@變量名 out?? -oracle中帶游標(biāo)及循環(huán)的存儲(chǔ)過程?? create or replace procedure proc_selCurrent? ( names varchar2? )? as cursor cursor_sel is select DepositSum,cardType,name,state from CurrentAccount where name like '%'||names||'%'; dd number; cc number; nn varchar2(20); sta number; beginopen cursor_sel;? loop??? fetch cursor_sel into dd,cc,nn,sta;??? dbms_output.put_line('存款金額:'||dd||'姓名:'||nn);? exit when cursor_sel%notfound;? end loop;close cursor_sel; end; 調(diào)用存儲(chǔ)過程?? begin? proc_selCurrent('a');?? end;
10.創(chuàng)建用戶的方式不同??? sql server中 1、創(chuàng)建登陸賬號(hào):sa 123456?? create Login 登陸名稱 with password='登陸密碼'?? 修改登陸賬戶:?? alter Login 登陸名稱 with name='新登錄名稱' and password='新登錄密碼' 禁用/啟用登陸賬號(hào)?? alter Login 登錄名稱 disable(禁用)/enable(啟用) 刪除登陸賬號(hào)?? drop Login 登錄名稱?? 2、創(chuàng)建用戶: create user 用戶名 for/from Login 登陸名稱? 修改用戶名 alter user 用戶名 with name='新用戶名'? 刪除用戶名 drop user 用戶名? -授權(quán)限 grant select/update/delete/insert on 表名 to 用戶名 -oracle中: -創(chuàng)建用戶語法:??? create user 用戶名 ??? identified by 密碼 ??? default tablespace users ??? temporary tablespace temp ??? quota 10M on users ?? 修改密碼:??? alter user 用戶名 identified by 新密碼?? 授予權(quán)限:??? grant create session to 用戶名?? 刪除用戶??? drop user 用戶名 cascade;?? 自己總結(jié)的一點(diǎn),僅供參考
? 作者:落幕年代 來源:CSDN 原文:https://blog.csdn.net/lailai186/article/details/45267959?utm_source=copy 版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請附上博文鏈接!
轉(zhuǎn)載于:https://www.cnblogs.com/bocom-zx/p/9783315.html
總結(jié)
以上是生活随笔為你收集整理的SQL Server 与 ORACLE 的区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 小动物之星安卓ios互通吗?
- 下一篇: 求一个不闻不问的个性签名。
