SQL Server开发者Oracle快速入门
生活随笔
收集整理的這篇文章主要介紹了
SQL Server开发者Oracle快速入门
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? 本文參考"Beginning SQL: Differences Between SQL Server and Oracle-A Quick Intro for SQL Server Users",作者Les Kopari
? 本文比較適合剛接觸Oracle的SQL Server開發人員.? I.?????????????????? 簡單概念的介紹 1.?????? 連接數據庫 S:??? use mydatabase O:??? connect username/password@DBAlias ?????? conn username/password@DBAlias ? 2.?????? 在Oracle中使用Dual, Dual是Oracle一個特有的虛擬表, Oracle中很多系統的變量和函數都可以通過Dual中獲得 S:??? select getdate(); O:??? select sysdate from dual; ? 3.?????? Select Into和Insert 語句的使用, 在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語句,如SQL92或SQL99的定義 ? 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
轉載于:https://www.cnblogs.com/ryb/archive/2007/08/13/853694.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的SQL Server开发者Oracle快速入门的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 相对网站根目录寻址 vs 相对当前目录寻
- 下一篇: asp.net页面处理过程文章整理