SQL Server 与 ORACLE 的区别

sql server 与  oracle的区别:    DBMS 数据库管理系统

1.数据类型不同。   sql server 的数据类型:int ,smallint ,char,varchar,nchar,nvarchar,ntext,datetime,smalldatetime,money,decima,   float,bit……    oracle 的数据类型:number(p,s),char,varchar2,Date,LOB 注意:insert into table_name values('1','张三','男',date'2012-3-5'); -插入字符串日期前加date转换类型  

2.获得当前系统时间的函数不同。   sql server :getdate() oracle:sysdate 例如:设定日期格式的函数:to_char(sysdate,'yyy-mm-dd');

3.在oracle中没有默认约束的说法   sql server 中添加默认约束:alter table talbe_name add DF_table_name default('男') for sex; oracle 中添加默认值:alter table table_name modify(sex default('男'));

4.连接变量和字符串的方式不一样   sql server 中连接:使用“+”连接,例如:print  'aaaa'+@name; oracle  中连接:使用“||”连接,例如:dbms_output.put_line('aaa'||name); -name为变量

5.oracle没有identity自动增长列,而是使用序列实现增长   sql server 自动增长:在表的主键列中可直接使用identity(1,1)实现增长 oracle 使用序列自动增长:create sequence se_id start with 1increment by 1   使用序列实现自动增长: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 '学号',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 '等级' from score go   oracle中: declare nums number:=&nos; &nos表示提示传入值 begin   case nums  when 100 then    dbms_output.put_line('满分也,不错');  when 90 then    dbms_output.put_line('90分页很不错了');  end case; end;

8.触发器创建语法不同  sql server中:   首先判断触发器是否已经存在 if exists (select * from sys.sysobjects where name='tr_delete') 如果存在先删除 drop trigger tr_delete go   创建触发器create trigger tr_deleteon bookInfoinstead of deleteas 定义变量 declare @bookid int  select @bookid=Bookid from deleted -deleted执行删除语句( delete from BookInfo where BookId=1),自动生成的deleted表 删除与该图书的相关记录(先删除从表再删除主表) 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中: 创建触发器create or replace trigger tri_testbefore insert or update or delete on table_name[for each row] -如果要使用 :new /:old 就必须使用行触发器declare  nums varchar2(20);begin  select 'F'||lpad('aa',5,0) into  nums from dual;end;    9.oracle中的存储过程 sql server中存储过程:  判断存储过程是否已经存在 if exists(select * from sys.sysobjects where name='proc_name')  如果存在先删除  drop proc proc_name go  创建存储过程语句 create proc/procedure proc_name @参数名1 数据类型 [out/output], @参数名2 数据类型 [out/output] as    ………… go  调用存储过程 如果有输出参数,则需定义变量(假设@参数2为输出参数) declare @变量名 数据类型 exec proc_name @参数名1='aaa',@参数名2=@变量名 out   -oracle中带游标及循环的存储过程   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; 调用存储过程   begin  proc_selCurrent('a');   end;

10.创建用户的方式不同    sql server中 1、创建登陆账号:sa 123456   create Login 登陆名称 with password='登陆密码'   修改登陆账户:   alter Login 登陆名称 with name='新登录名称' and password='新登录密码' 禁用/启用登陆账号   alter Login 登录名称 disable(禁用)/enable(启用) 删除登陆账号   drop Login 登录名称   2、创建用户: create user 用户名 for/from Login 登陆名称  修改用户名 alter user 用户名 with name='新用户名'  删除用户名 drop user 用户名  -授权限 grant select/update/delete/insert on 表名 to 用户名 -oracle中: -创建用户语法:    create user 用户名     identified by 密码     default tablespace users     temporary tablespace temp     quota 10M on users    修改密码:    alter user 用户名 identified by 新密码   授予权限:    grant create session to 用户名   删除用户    drop user 用户名 cascade;   自己总结的一点,仅供参考

  作者:落幕年代 来源:CSDN 原文:https://blog.csdn.net/lailai186/article/details/45267959?utm_source=copy 版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自www.cnblogs.com/bocom-zx/p/9783315.html