qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          Oracle 與 MySQL 的區別

          Oracle 與 MySQL 的區別

          1、在ORACLE中用select * from all_users顯示所有的用戶,而在MYSQL中顯示所有數據庫的命令是show databases。對于我的理解,ORACLE項目來說一個項目就應該有一個用戶和其對應的表空間,而MYSQL項目中也應該有個用戶和一個庫。在ORACLE(db2也一樣)中表空間是文件系統中的物理容器的邏輯表示,視圖、觸發器和存儲過程也可以保存在表空間中。而MYSQL并沒有使用表空間來進行管理。

            2、查詢當前所有的表。ORACLE: select * from tab,MYSQL:show tables。

            3、改變連接用戶(庫)。ORACLE:conn 用戶名/密碼@主機字符串,MYSQL:use 庫名。

            4、顯示當前連接用戶(庫)。ORACLE:show user,MYSQL:connect。

            5、執行外部腳本命令。ORACLE:@a.sql,MYSQL:source a.sql。

          比版本Personal Oracle 10 mysql 5.1
             

          默認安裝目錄

          可選擇

          C:/program files/MYSQL

          各種實用程序所在目錄

          可選擇

          C:/program files//BIN

          控制臺工具

          SVRMGR.EXE
          SVRMGR23.EXE

          mysqladmin.exe

          數據庫啟動程序

          0start73.exe screen

          mysqld-shareware.exe

          關閉數據庫命令

          ostop73.exe

          mysqladmin.exe -u root shutdown

          客戶程序

          SQL*Plus

          mysql

          啟動命令

          c:/orawin95/bin/sqlplus.exe

          c:/mysql/bin/mysql.exe

          帶用戶啟動方式
          (直接連庫方式)

          c:/orawin95/bin/sqlplus.exe system/manager@TNS

          c:/mysql/bin/mysql.exe test
          c:/mysql/bin/mysql.exe -u root test

          安裝后系統默認用戶(庫)

          sys
          system
          scott

          mysql
          test

          顯示所有用戶(庫)

          SQL >select * from all_users;

          C:/mysql/bin>mysqlshow
          C:/mysql/bin>mysqlshow --status
          mysql> show databases;

          退出命令

          SQL> exit
          SQL> quit

          mysql> exit
          mysql> quit

          改變連接用戶(庫)

          SQL> conn 用戶名/密碼@主機字符串

          mysql> use 庫名

          查詢當前所有的表

          SQL> select * from tab;
          SQL> select * from cat;

          mysql> show tables;
          c:/mysql/bin>mysqlshow 庫名

          顯示當前連接用戶(庫)

          SQL> show user

          mysql> connect

          查看幫助

          SQL> ?

          mysql> help

          顯示表結構

          SQL> desc 表名
          SQL> describe 表名

          mysql> desc 表名;
          mysql> describe 表名;
          mysql> show columns from 表名;
          c:/mysql/bin>mysqlshow 庫名 表名

          日期函數

          SQL> select sysdate from dual;

          mysql> select now();
          mysql> select sysdate();
          mysql> select curdate();
          mysql> select current_date;
          mysql> select curtime();
          mysql> select current_time;

          日期格式化

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

          mysql> select date_format(now(),'%Y-%m-%d');
          mysql> select time_format(now(),'%H-%i-%S');

          日期函數
          (增加一個月)

          SQL> select to_char(add_months(to_date('20000101','yyyymmdd'),1),'yyyy-mm-dd') from dual;
          結果:2000-02-01
          SQL> select to_char(add_months(to_date('20000101','yyyymmdd'),5),'yyyy-mm-dd') from dual;
          結果:2000-06-01

          mysql> select date_add('2000-01-01',interval 1 month);
          結果:2000-02-01
          mysql> select date_add('2000-01-01',interval 5 month);
          結果:2000-06-01

          別名

          SQL> select 1 a from dual;

          mysql> select 1 as a;

          字符串截取函數

          SQL> select substr('abcdefg',1,5) from dual;
          SQL> select substrb('abcdefg',1,5) from dual;
          結果:abcde

          mysql> select substring('abcdefg',2,3);
          結果:bcd
          mysql> select mid('abcdefg',2,3);
          結果:bcd
          mysql> select substring('abcdefg',2);
          結果:bcdefg
          mysql> select substring('abcdefg' from 2);
          結果:bcdefg
          另有SUBSTRING_INDEX(str,delim,count)函數
          返回從字符串str的第count個出現的分隔符delim之后的子串。
          如果count是正數,返回最后的分隔符到左邊(從左邊數) 的所有字符。
          如果count是負數,返回最后的分隔符到右邊的所有字符(從右邊數)。

          執行外部腳本命令

          SQL >@a.sql

          1:mysql> source a.sql
          2:c:/mysql/bin>mysql <a.sql
          3:c:/mysql/bin>mysql 庫名 <a.sql

          導入、導出工具

          exp.exe
          exp73.exe
          imp.exe
          imp73.exe

          mysqldump.exe
          mysqlimport.exe

          改表名

          SQL> rename a to b;

          mysql> alter table a rename b;

          執行命令

          ;<回車>
          /
          r
          run

          ;<回車>
          go
          ego

          distinct用法

          SQL> select distinct 列1 from 表1;
          SQL> select distinct 列1,列2 from 表1;

          mysql> select distinct 列1 from 表1;
          mysql> select distinct 列1,列2 from 表1;

          注釋

          --
          /*與*/

          #
          --
          /*與*/

          當作計算器

          SQL> select 1+1 from dual;

          mysql> select 1+1;

          限制返回記錄條數

          SQL> select * from 表名 where rownum<5;

          mysql> select * from 表名 limit 5;

          新建用戶(庫)

          SQL> create user 用戶名 identified by 密碼;

          mysql> create database 庫名;

          刪用戶(庫)

          SQL> drop user 用戶名;

          mysql> drop database 庫名;

          外連接

          使用(+)

          使用left join

          查詢索引

          SQL> select index_name,table_name from user_indexes;

          mysql> show index from 表名 [FROM 庫名];

          通配符

          “%”

          “%”和“_”

          SQL語法

          SELECT selection_list 選擇哪些列
          FROM table_list 從何處選擇行
          WHERE primary_constraint 行必須滿足什么條件
          GROUP BY grouping_columns 怎樣對結果分組
          HAVING secondary_constraint 行必須滿足的第二條件
          ORDER BY sorting_columns 怎樣對結果排序

          SELECT selection_list 選擇哪些列
          FROM table_list 從何處選擇行
          WHERE primary_constraint 行必須滿足什么條件
          GROUP BY grouping_columns 怎樣對結果分組
          HAVING secondary_constraint 行必須滿足的第二條件
          ORDER BY sorting_columns 怎樣對結果排序
          LIMIT count 結果限定


          posted on 2012-09-25 10:46 順其自然EVO 閱讀(304) 評論(0)  編輯  收藏 所屬分類: 數據庫

          <2012年9月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 沁源县| 宁武县| 珲春市| 时尚| 洛阳市| 迁西县| 彰化县| 富宁县| 嘉禾县| 唐海县| 邵武市| 得荣县| 大同县| 茌平县| 错那县| 太原市| 安徽省| 麻江县| 拜城县| 泾川县| 紫云| 莆田市| 凌海市| 阳原县| 柳河县| 寿宁县| 麦盖提县| 甘南县| 保定市| 镇巴县| 荥经县| 玉林市| 肥西县| 松潘县| 寻乌县| 镇康县| 修水县| 蒙山县| 吉木乃县| 阜阳市| 西充县|