在DB2中如何實現Oracle的相關功能 二

2022-11-23 08:45:06 字數 4244 閱讀 3543

作者﹕ccbzzp

在現實的應用中大家可能經常會遇到在db2中如何實現oracle的某些功能﹐

在此我簡單地總結一下﹐實現某一功能可能會有很多種方法﹐在此就沒有全部列出﹐

歡迎大家繼續﹐以便和大家共享﹐共同**﹐共同近步﹗(以下主要以oracle

8i,9i和db2 為例)。

1.如何檢視資料庫的版本的oracle和db2的寫法

oracle 可以這樣實現﹕

sql> connect system/manager124@test;

已連線.

sql> select * from v$version;

banner

oracle9i enterprise edition release 9.2.0.1.0 - production

pl/sql release 9.2.0.1.0 - production

core 9.2.0.1.0 production

tns for 32-bit windows: version 9.2.0.1.0 - production

nlsrtl version 9.2.0.1.0 - production

db2 可以這樣實現﹕

在命令視窗執行 db2level

d: qllib\bin>db2level

db210851 instance "db2" uses db2 code release "sql07020" with level identifier

"03010105" and informational tokens "db2 v7.1.0.40","n010415" and "wr21254".

2.如何快速清空乙個大表的oracle和db2的寫法

oracle 可以這樣實現﹕

sql>truncate table table_name;

db2 可以這樣實現﹕

alter table table_name active not logged initially with empty table;

3.如何檢視表空間的使用狀況的oracle和db2的寫法

oracle 可以這樣實現﹕

select tablespace_name, max_m, count_blocks free_blk_cnt, sum_free_m,to_char(100*sum_free_m/sum_m, '99.99as

pct_free

from ( select tablespace_name,sum(bytes)/1024/1024 as sum_m from dba_data_files group by tablespace_name),

( select tablespace_name as fs_ts_name, max(bytes)/1024/1024 as max_m, count(blocks) as count_blocks,

sum(bytes/1024/1024) as sum_free_m from dba_free_space group by tablespace_name )

where tablespace_name = fs_ts_name

db2 可以這樣實現﹕

list tablespace containers for 你的表空間號 show detail;

4.如何從一時間點取出日期的各部分的常用的oracle和db2的寫法

oracle 可以這樣實現﹕

1>.取時間點的年份的寫法:

select to_char(sysdate,'yyyy') from dual;

2>.取時間點的月份的寫法:

select to_char(sysdate,'mm') from dual;

3>.取時間點的日的寫法:

select to_char(sysdate,'dd') from dual;

4>.取時間點的時的寫法:

select to_char(sysdate,'hh24') from dual;

5>.取時間點的分的寫法:

select to_char(sysdate,'mi') from dual;

6>.取時間點的秒的寫法:

select to_char(sysdate,'ss') from dual;

7>.取時間點的毫秒的寫法:(9i以上)

select substr(systimestamp,20,6) from dual;

8>.取時間點的日期的寫法:

select trunc(sysdate) from dual;

9>.取時間點的時間的寫法:

select to_char(sysdate,'hh24:mi:ss') from dual;

10>.日期,時間形態變為字元形態

select to_char(sysdate) from dual;

11>.將字串轉換成日期或時間形態:

select to_date('2003/08/01') from dual;

12>.返回引數的星期幾的寫法:

select to_char(sysdate,'d') from dual;

13>.返回引數一年中的第幾天的寫法:

select to_char(sysdate,'ddd') from dual;

14>.返回午夜和引數中指定的時間值之間的秒數的寫法:

select to_char(sysdate,'sssss') from dual;

15>.返回引數中一年的第幾周的寫法:

select to_char(sysdate,'ww') from dual;

db2 可以這樣實現﹕

1>.取時間點的年份的寫法:

select year(current timestamp) from

2>.取時間點的月份的寫法:

select month(current timestamp) from

3>.取時間點的日的寫法:

select day(current timestamp) from

4>.取時間點的時的寫法:

select hour(current timestamp) from

5>.取時間點的分的寫法:

select minute(current timestamp) from

6>.取時間點的秒的寫法:

select second(current timestamp) from

7>.取時間點的毫秒的寫法:

select microsecond(current timestamp) from

8>.取時間點的日期的寫法:

select date(current timestamp) from

9>.取時間點的時間的寫法:

select time(current timestamp) from

10>.日期,時間形態變為字元形態:

select char(current date) from

select char(current time) from

select char(current date+12 hours) from

11>.將字串轉換成日期或時間形態:

select timestamp('2002-10-20-12.00.00.000000') from

select timestamp('2002-10-20 12:00:00') from

select date('2002-10-20') from

select date('10/20/2002') from

select time('12:00:00') from

select time ('12.00.00') from

12>.返回引數的星期幾的寫法:

select dayname(current timestamp) from

select dayofweek(current timestamp) from

select dayofweek_iso(current timestamp) from

13>.返回引數一年中的第幾天的寫法:

select dayofyear(current timestamp) from

14>.返回午夜和引數中指定的時間值之間的秒數的寫法:

select midnight_seconds(current timestamp) form

15>.返回引數中一年的第幾周的寫法:

select week(current timestamp) form

待續...

Oracle與DB2資料型別對應說明

通過下表介紹與db2 400資料型別之間的對應關係,是一對多的關係,具體採用哪種對應關係,應具體問題具體分析。注意事項 oracle中的date含有年 月 日 時 分 秒,它和db2 400中的date不相互對應,db2 400中的date只有年 月 日,time型別含有時 分 秒,因此日期和時間型...

Oracle資料庫在金保工程中的應用

摘要 本文介紹了金保工程資訊管理系統對資料儲存要求,著重闡述了oracle在金保工程資訊管理系統建設中的使用者安全策略和許可權分配功能 資料壓縮機制對金保業務資料儲存的處理 多種資料備份和恢復機制來保障金保工程正常執行 高容錯率以及oracle的分布式管理滿足金保工程統一管理和統一規劃的要求,從而論...

如何實現課堂中的「少教多學」

作者 張延敏 新課程 小學 2013年第10期 摘要 捷克教育家誇美紐斯在談到自己的教學理想時說 找出一種教育方法,使教師因此可以少教,但是學生多學 使學校因此可以少些喧囂 厭惡和無益的勞苦,獨具閒暇 快樂及堅實的進步。然而,如何才能將教師從課堂中 解脫 出來,如何才能讓學生的手 腦 口三者都調動起...