oracle跟mysql的區別和聯絡

來源:互聯網
上載者:User

標籤:

一、主鍵自增長:

1) oracle:

使用序列實現,比如建立序列,起點是1000,步進是1:

  create sequence myseq increment by 1 start with 1000 

增加記錄:

  insert into student(stuId,stuName) values(myseq.nextval,‘peter‘) 

2) mysql:

在建表時指定主鍵自增長

  create table student(stuId int auto_increment primary key,stuName char(20)) 

增加記錄:

  insert into student(stuName) values (‘peter‘) 

二、命令列工具:

Oracle 的官方命令列工具是SQLPlus

 

mysql 的命令列工具是mysql:

 

三、關於使用者的概念:

1)Oracle

在Oracle中有一個使用者的概念,用來登入到資料庫,比如openlab使用者。使用者擁有一定的許可權,可以建立表、視圖等。使用者名稱下的資料表,視圖等對象的集合叫Schema。

資料庫安裝好後。建立的預設使用者是:sys.system.scott。

建立使用者:create user 使用者名稱 identified by 密碼(一般是DBA來建立,普通使用者沒有建立使用者的許可權)

在SQLPLus工具中切換使用者:conn 使用者名稱/密碼@主機字串

查看目前使用者:show  user

顯示所有的使用者:select  *  from  all_users

顯示使用者下的表:select  *  from  tab

2) mysql

mysql中對應於oracle中使用者的概念是database。登陸後要先建立database,才能建表。預設建立的database是mysql , test。

建立資料庫:create  databases 庫名

切換使用者:use  database 庫名

查看目前使用者:connect

顯示所有資料庫:show  databases

顯示使用者下的表:show  tables

四、假設有外部指令檔 C:\script.sql,執行外部指令檔的方式:

1)Oracle:

@  script.sql

2) mysql:

source  script.sql

五、Sql語句中的運算式:

1)Oracle:

 select 12 * 10 from dual 

2) mysql:

 select 12 * 10 

六、取系統時間

1)Oracle:

 select sysdate from dual 

2) mysql:

select now()select sysdate()select curdate()select select current_dateselect curtime()select current_time

 

七、日期格式轉換:

1)Oracle:

select to_char(sysdate,‘yyyy-mm-dd‘) from dual;select to_char(sysdate,‘hh24-mi-ss‘) from dual;

 

2) mysql:

 select date_format(now(),‘%Y-%m-%d‘)

 select time_format(now(),‘%H-%i-%S‘) 

 

1、直接在資料庫 用sql語句就把 日期時間處理好

2、Java代碼裡 把日期處理好(架構)

3、頁面 用JavaScript代碼 處理好

4、標籤(C S)

八、日期函數:6個月以後

1)Oracle:

 select add_months(sysdate,6) from dual 

2) mysql:

 select date_add(now(),interval 6 month) 

九、字元函數:從‘helloworld’中截取hello

1)Oracle:

 select substr(‘helloworld‘,1,5) from dual; 

2) mysql:

 select substring(‘helloworld‘,1,5) 

十、修改表名:

1)Oracle:

 rename oldname to newname 

也可以用來修改各種對象名稱

2) mysql:

 alter table oldname to newname 

十一、關於組函數

 select deptno,count(*) from emp 

這種文法,在mysql中是正常的,而在oracle中是會報錯的,select列表中的deptno列必須跟在group by 短語後:

 select deptno,count(*) from emp group by deptno 

 

十二、分頁語句

 

1)Oracle:

select * from (select t.*,rownum rn from (select * from emp) t where rownum < 11) where rn > 5

 

查到的是第6~10條記錄

2) mysql:

 select * from emp limit 5,5 

查到的是第6~10條記錄

十三、計算每個員工的年薪:工資 * 12 + 獎金 * 12

 select ename,sal*12 + nvl(comm,0)*12 from emp 

nvl :單行函數,如果為空白,返回0

Oracle : nvl

Mysql : ifnull

Sqlserver  :  isnull

 

oracle跟mysql的區別和聯絡

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.