oracle,db2,mysql類比之一常用類似知識點

junnyblog發表於2009-10-14

《oracle,db2,mysql類比》作為三種資料庫一個類比,目的在於透過類比,瞭解現在資料庫相似點與異同點,同時可以幫助大家在瞭解一種資料庫,能夠迅速地學會其他資料庫。初步定義為oracle,db2,mysql三種資料庫,以後可能還是追加informix,sysbase,sql server等資料庫。

本篇作為首篇,目的是讓大家對這三種資料庫常用的知識點有一個感知的認識。

[@more@]

一、常用知識點
1、檢視可以登陸的資料庫:
oracle:檢視tnsname.ora 或者 echo $ORACLE_SID
db2:
mysql:show databases --檢視當前資料庫:select database()

2、檢視使用者表,檢視,表索引,表列,
oracle:
select table_name from user_tables;
select view_name from user_views;
select constraint_name,constraint_type from user_constraints where table_name='';
select column_name from all_tab_columns where table_name='';
db2:
list tables or select tabname from syscat.tables;
select view_name from syscat.views;
describe indexes for table table_name;
select tabname from syscat.columns where tabname='';
mysql:information_schema
select table_name from information_schema.tables where table_schema='USER'; or show tables;
select table_name from information_schema.views where table_schema='USER'; or show table status where comment='view';
select constraint_name,constraint_type from information_schedma.table_constraints where table_name='';
select index_name,table_name from information_schema.statistics where table_name='';
select column_name from information_schedma.columns where table_name='' and table_schema='USER';
3、檢視錶空間
oracle:select name from v$tablespace
db2: list tablespaces
mysql:
4、檢視錶結構
oracle:describe table_name
db2:describe table table_name
mysql:describe table_name
5、取前n行資料
oracle:select * from table_name where rownumdb2:select * from table_name fetch first n rows only
mysql:select * from table_name limit n
6、load資料
oracle: sqlldr username/passwd control=ctr.ctl data=data.txt
db2:load from data.txt of del insert into table_name --db2 前提需要有load許可權,grant load on database to user user_name
mysql:load data local infile 'e:Mysqlmysql.txt' into table test lines terminated by 'rn'
7、運用sql語句
oracle:@file.sql
db2:db2 -tvf file.sql
mysql:
8、檢視使用者
oracle:select user_name from all_users;
db2:
mysql:select schema_name from schemata;
9、insert date型別
oracle:insert into table_name (time_id) values (to_date('2009-09-01','YYYY-MM-DD'));
db2:insert into table_name (time_id) values ('2009-09-01');
mysql:insert into table_name (time_id) values ('2009-09-01');
10、char to int
oracle:select to_number('300')+200 from dual;
db2:select cast(char_id as integer)+200 from table_name;
mysql:
11、把表的資料匯出到文字
oracle:spool data.txt ->select * from table_name
db2:db2" export to "/test.sql" of del select * from test"
mysql:
12、檢視當前資料庫
oracle:show parameter db_name
db2:list active databases
mysql:show databases;
13、檢視資料庫目錄
oracle:echo $ORACLE_HOME
db2:list database derictory
mysql:
14、檢視資料庫系統引數資訊
oracle:show parameter or v$parameter
db2:get dbm cfg
mysql:
15、修改表結構
oracle:alter table table_name add column_name number
db2:alter table table_name alter column column_name set data type varchar(12)
mysql:
16、匯出建表語句
oracle: select dbms_metadata.get_ddl('TABLE',u.table_name) from user_tables u;
db2:db2look -d database_name -e -z schedma [-t table_name] -o outfile.sql
mysql:show create table table_nameG (--檢視檢視:show create view view_name)
17、如何恢復已提交的資料

18、模式,OWNER的區別
模式 :一組物件的集合,如表、檢視、和序列號等。
oracle:
SQL> SHOW USER
USER is "WGWH"
SQL> create table etl.wgwh ( id number);
Table created.
檢視wgwh所屬的OWNER:
SQL> select owner from all_tables where table_name = 'WGWH';
OWNER
------------------------------
ETL
備註:oracle模式由資料庫的使用者所擁有並且與使用者具有相同的名字。其實,在實際使用中模式和使用者是一回事。
oracle檢視當前模式與切換模式,相當簡單,只需要檢視使用者或者切換使用者。
db2:
db2 => select tabschema,owner from syscat.tables where tabname='WGWH' with ur

TABSCHEMA OWNER
-------------------------------------------------------------------- -----------------------------------------------------------------------------------
ETL ETL
WGWH ETL
備註:db2的OWNER區別於oracle的OWNER,即oracle同一個OWNER下,不能存在相同的object,但db2可以,同時增加模式以區分。
檢視當前模式:
select current schema from sysibm.sysdummy1
select current schema from sysibm.dual

select current sqlid from sysibm.sysdummy1
select current sqlid from sysibm.dual

values current schema
values current sqlid 
切換模式:
set current schema schedma_name
mysql:
19、顯示資料庫版本
oracle:select * from product_component_version
db2: db2level 顯示db2的版本號
mysql:select version()
20、檢視應用程式的埠號:
oracle--em,isqlplus:$ORACLE_HOME/../../install/protlist.ini
db2:
mysql:
21、應用程式服務:
oracle:啟動EM--emctl start dbconsole
db2:
mysql:
22、重新配置應用程式
oracle:配置em-- emca -config dbcontrol db
db2:
mysql:
23、檢視當前時間
oracle:select sysdate from dual
db2:
mysql:select now()

24、connect database

oracle:sqlplus

db2:db2 connect to dbname user user_name using passwd

mysql:use database

25、create table as

oracle:create table A as select * from B;

db2:create table A as (select * from B) definition only;

insert into A select * from B;

mysql:

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22630256/viewspace-1027863/,如需轉載,請註明出處,否則將追究法律責任。

相關文章