SQL Server开发者Oracle快速入门

本文参考"Beginning SQL: Differences Between SQL Server and Oracle-A Quick Intro for SQL Server Users",作者Les Kopari

 

本文比适合接触OracleSQL Server开发

I.                    简单概念的介

1.       接数据

S:    use mydatabase

O:    connect username/password@DBAlias

       conn username/password@DBAlias

 

2.       Oracle中使用Dual, DualOracle一个特有的虚, Oracle中很多系量和函数都可以通Dual

S:    select getdate();

O:    select sysdate from dual;

 

3.       Select IntoInsert 句的使用, SQL Server中的Select Into句在Oracle中一般是Insert into…select…, 另外2个数据都支持准的SQL, 写法上略有区

S:    select getdate() mycolumn into mytable;

       Insert mytable values(‘more text’);

O:    insert into mytable select getdate() mycolumn from dual

insert into mytable (mycolumn) values(sysdate);

 

4.       Update

S:    update mytable set mycolumn=myothertable.mycolumn  

from mytable,myothertable 

where mytable.mycolumn like 'MY%' and myothertable.myothercolumn='some text';

O:    update mytable set mycolumn=

(select a.mycolumn from myothertable a

where myothertable.myothercolumn='some text')

where mytable.mycolumn like 'MY%';

 

5.       Delete

S:    delete mytable where mycolumn like 'some%';

O:    delete from mytable where mycolumn like 'some%';

 

6.       使用开发管理的

S:    isql

osql: for queries developed in SQL Analyzer

SQL Server Management Studio Express     形化管理工具

O:    sqlplus

       PL/SQL Developer 形化开发管理工具

       TOAD                   形化开发管理工具

 

: 个人建基本的简单Select, Update, Delete使用准的SQL,SQL92SQL99的定

 

II.                一些细节问题: Joins, Subqueries, Deletes

1.       Outer Join

S:    select d.deptname, e.ename from dept d, emp e where d.empno *= e.enum;

O:    select d.deptname,e.ename from dept d, emp e where d.empno = e.enum (+);

 

2.       SubQueries in Place of Columns

S:    select distinct year,

q1 = (select Amount amt FROM sales where Quarter=1 AND year = s.year),

q2 = (SELECT Amount amt FROM sales where Quarter=2 AND year = s.year),

q3 = (SELECT Amount amt FROM sales where Quarter=3 AND year = s.year),

q4 = (SELECT Amount amt FROM sales where Quarter=4 AND year = s.year)

from sales s;

O:    SELECT year,

DECODE( quarter, 1, amount, 0 ) q1,

DECODE( quarter, 2, amount, 0 ) q2,

DECODE( quarter, 3, amount, 0 ) q3,

DECODE( quarter, 4, amount, 0 ) q4

FROM sales s;

 

3.       Delete with Second From Clause

S:    delete from products, product_deletes

where products.a = product_deletes.a

and products.b = product_deletes.b

and product_deletes.c = 'd';

O:    delete from products

where (a, b ) in

(select a, b from product_deletes where c = 'd' );

III.               某些概念上的区

1. The Connect Concept

S:    Multiple databases

O:    Single Database, Multiple tablespaces, schemas, users

 

2. Other Conceptual Differences

SQL Server

Oracle

Database owner, DBO

Schema

Group/Role

Role

Non-unique index

Index

T-SQL stored procedure{

PL/SQL procedure; PL/SQL function

Trigger

BEFORE trigger After trigger

Column identity property

Sequence

 

Oracle中独有的概念, SQL Server2005中也始支持了:

Clusters; Packages; Triggers for each row; Synonyms; Snapshots

 

3. Data Type Differences

SQL Server

Oracle

INTEGER

NUMBER(10)

SMALLINT

NUMBER(6)

TINYINT

NUMBER(3)

REAL

FLOAT

FLOAT

FLOAT

BIT

NUMBER(1)

VARCHAR(n)

VARCHAR2(n)

TEXT

CLOB

IMAGE

BLOB

BINARY(n)

RAW(n) or BLOB

VARBINARY

RAW(n) or BLOB

DATETIME

DATE

SMALL-DATETIME

DATE

MONEY

NUMBER(19,4)

NCHAR(n)

CHAR(n*2)

NVARCHAR(n)

VARCHAR(n*2)

SMALLMONEY

NUMBER(10,4)

TIMESTAMP

NUMBER

SYSNAME

VARCHAR2(30), VARCHAR2(128)

 

时间:

S:    Datetime: 1/300th second

O:    Date: 1 second

Timestamp: 1/100 millionth second

 

4.

S:    select a=deptid, b=deptname,c=empno   from dept;

O:    select deptid a, deptname b, empno c from dept;

 

5. 查询

S:    SELECT ename, deptname

FROM emp, dept

WHERE emp.enum = 10 AND

(SELECT security_code FROM employee_security

WHERE empno = emp.enum) =

(SELECT security_code FROM security_master

WHERE sec_level = dept.sec_level);

O:    SELECT empname, deptname

FROM emp, dept

WHERE emp.empno = 10

AND EXISTS

(SELECT security_code FROM employee_security es

WHERE es.empno = emp.empno AND es.security_code =

(SELECT security_code FROM security_master

WHERE sec_level = dept.sec_level));

 

IV.               大的新特性

表达式的支持, SQLServer2005找和替可以用正表达式

Regular Expressions: Operators & Functions

Operator: REGEXP_LIKE

Functions: REGEXP_INSTR; REGEXP_SUBSTR; REGEXP_REPLACE

 

Select zip from zipcode where regexp_like (zip, ‘[^[:digit:]]’);

 

SELECT REGEXP_INSTR(

'Joe Smith, 10045 Berry Lane , San Joseph , CA 91234-1234 ',

' [[:digit:]]{5}(-[[:digit:]]{4})?$')  

AS starts_at

FROM dual

 

V.                  总结和更深入的探

以上属于比基本的探,更深入的内容可以参考下面的内容

1.    Oracle Migration Workbench Reference Guide for SQL Server and Sybase Adaptive Server Migrations, Release 9.2.0 for Microsoft Windows 98/2000/NT and Microsoft Windows XP, Part Number B10254-01

2.    Oracle Technology Network, OTN:

http://otn.oracle.com/software/index.html

3.    Writing Better SQL Using Regular Expressions, By Alice Rischert

http://otn.oracle.com/oramag/webcolumns/2003/techarticles/rischert_regexp_pt1.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值