59
DB2 Information Management Software © 2008 IBM Corporation DB2 Migration 절차, 방법 및 MTK 소개 - 타 DBMS와 연계 - SQL의 호환성 IBM Korea Software Group IM 사업부

DB2Migration 절차, 방법및MTK 소개 -타DBMS와연계 -SQL ... migration 절차및방법 DB2 Migration 단계7. Test 및검증 -기존운영환경데이터의손실없이application이동일하게동작되는지검사합니다

Embed Size (px)

Citation preview

  • DB2 Information Management Software

    2008 IBM Corporation

    DB2 Migration , MTK

    - DBMS

    - SQL

    IBM KoreaSoftware GroupIM

  • 2 2008 IBM Corporation

    IBM DB2

    1. DB2 Migration

    2. DB2 Migration

    3. MTK

    4. SQL Conversion

    5. MTK Migration

    6. Access Guidelines

    7. User Defined Function

    8. DBMS

    9. SQL

  • 3 2008 IBM Corporation

    IBM DB2

    1. DB2 Migration 1. DB2 Migration

    TCO : 5 (TCO:Total cost of Ownership) DBMS

    49%-70% .

    Migration offering , Migration tool kit,

    POC .

    IBM Know-how

    DB2 .

    Application DB

    .

    DB2 IBM , TPC-C, TPC-H

    SAP , DB2 Autonomic computing

    Grid .

  • 4 2008 IBM Corporation

    IBM DB2

    2. DB2 migration 2. DB2 migration

    DB2 Migration

    Assessment & PlanningAssessment & Planning

    Database object migrationDatabase object migration

    Application conversionApplication conversion

    Data MigrationData Migration

    Performance tuningPerformance tuning

    Test Test

    MigrationMigration databasedatabase migration migration , ,

    migrationmigration tooltool

    Database structure Database structure DatabaseDatabase objectobject migration migration

    ApplicationApplication conversion conversion

    Data Data

    performance tuning performance tuning

    Migration Migration database, application database, application

    HA HA , , replication, backup toolreplication, backup tool

  • 5 2008 IBM Corporation

    IBM DB2

    2. DB2 migration 2. DB2 migration

    DB2 Migration 1. Assessment & Planning

    - migration

    Assessment item Assessment item

    DB2 porting guideDB2 porting guideIBM IBM

    MigrationMigration tooltool Migration Migration tooltool

    Application architectureApplication architecture

    Application sizeApplication size

    Application SQL Application SQL

    ApplicationApplication

    Database sizeDatabase size

    Table Table , , row size, indexrow size, index

    Stored procedure, User defined functionStored procedure, User defined function

    TriggerTrigger

    Database structureDatabase structure

    ((Middleware, Tool, Compiler, etc.)Middleware, Tool, Compiler, etc.)

    PlatformsPlatforms

    MigrationMigration

  • 6 2008 IBM Corporation

    IBM DB2

    2. DB2 migration 2. DB2 migration

    DB2 Migration 2.

    -

    DB2 DB2

    DB2 DB2

    DB2 DB2 Tool Tool

    IBM IBM

    ToolTool

    , ,

    Client Client

    Application Application

    Application Application

    DB2 DB2

    DB2 DB2

    DB2 DB2

    DB2 DB2

    OS OS

    Disk Disk

  • 7 2008 IBM Corporation

    IBM DB2

    2. DB2 migration 2. DB2 migration

    DB2 Migration 3. Database object migration

    - database object migration

    DB2 Migration tool kitDB2 Migration tool kit

    DB2 UDB conversion guide (from Oracle/Sybase/SQL server )DB2 UDB conversion guide (from Oracle/Sybase/SQL server )

    IBM IBM

    ToolTool

    Stored procedureStored procedure user defined functionuser defined function Stored procedure,Stored procedure,

    User defined functionUser defined function

    Column typeColumn type

    IndexIndex

    ConstraintsConstraints

    Table Table

    Database typeDatabase type

    PartitioningPartitioning

    TablespaceTablespace

    LogsLogs

    Database logical / Database logical /

    physical layout physical layout

    DatabaseDatabase

    Object Object

    MigrationMigration

  • 8 2008 IBM Corporation

    IBM DB2

    2. DB2 migration 2. DB2 migration

    DB2 Migration 4. Application Migration

    - DB2 application source conversion

    DB2 Migration tool kitDB2 Migration tool kit

    DB2 Development centerDB2 Development center

    DB2 UDB conversion guide (from Oracle/Sybase/SQL server )DB2 UDB conversion guide (from Oracle/Sybase/SQL server )

    IBM IBM

    ToolTool

    IBMIBM MTKMTK on the flyon the fly SQL translatorSQL translator SQL conversion SQL conversion

    SQL SQL

    conversion toolconversion tool

    SQLSQL SQL SQL

    SQLSQL

    Isolation level, lockIsolation level, lock

    Error Error

    Application source Application source

    Source Source

    ConversionConversion

  • 9 2008 IBM Corporation

    IBM DB2

    2. DB2 migration 2. DB2 migration

    DB2 Migration 5. Data Migration

    - DB2 .

    DB2DB2 loadload datadata

    TypeType conversionconversion

    programprogram script script

    Data Data

    DB2 Migration tool kitDB2 Migration tool kit

    DB2 Admin clientDB2 Admin client

    DB2 Load toolDB2 Load tool

    IBM IBM ToolTool

    DB2 Load toolDB2 Load tool data loaddata load

    Referential constraintReferential constraint Data Data

    Type Type migration migration

    --NumericNumeric

    --Date, Date, datetimedatetime

    Source dataSource data target datatarget data sample sample

    Table Data Table Data

    Data migration Data migration

  • 10 2008 IBM Corporation

    IBM DB2

    2. DB2 migration 2. DB2 migration

    DB2 Migration 6. Performance tuning

    - database application

    DB2 Performance Tuning GuideDB2 Performance Tuning Guide

    DB2 Health centerDB2 Health center

    DB2 AdvisorDB2 Advisor

    IBM IBM

    ToolTool

    DB2 databaseDB2 database

    DB2 applicationDB2 application

    monitoringmonitoring

    DB2DB2 advisoradvisor health centerhealth center

    Migration Migration

    Performance Performance

    tuningtuning

  • 11 2008 IBM Corporation

    IBM DB2

    2. DB2 migration 2. DB2 migration

    DB2 Migration 7. Test

    - application

    DB2 Migration tool kitDB2 Migration tool kitIBM IBM ToolTool

    Migration Migration

    Data Data

    Application Application

    Migration Migration test test

    Test Test

  • 12 2008 IBM Corporation

    IBM DB2

    2. DB2 migration 2. DB2 migration

    DB2 Migration 8.

    - Migration DB2

    backup toolbackup tool Backup Backup

    DB2 Migration tool kitDB2 Migration tool kit

    DB2 admin guideDB2 admin guide

    DB2 HA DB2 HA

    IBM IBM ToolTool

    Table, indexTable, index REORGREORG

    Database Database

    HA HA

  • 13 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 3. DB2 MTK

    DB2 MTK (DB2 Migration Tool Kit)?- DB(Oracle, Sybase) DB2 migration tool- migration , .

    - DB2 .

    - Source DB DDL

    ODBC/JDBC , migration source DB DDL .- DB Object

    Table, index, trigger, sequence, procedure- Data

    script , data tool .- Migration report

    Migration HTML report .- SQL translator

    DB2 SQL , sql tool.

    - Function conversion library

    DB DB2 library .

  • 14 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 3. DB2 MTK

    1. Project ( )

    2. Source

    - MTK source DB Metadata(DDL) import

    3. Convert

    - Source DB DDL

    4. Refine

    -

    5. Data script

    - Data script

    6. DB2 deploy

    - DB2 DB migration

  • 15 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 0) DB2 MTK 3. DB2 MTK 0) DB2 MTK

    - PC : Xwindows GUI

    tool, Xterminal S/W .

    - Server : JRE 1.3

    -DISPLAY=:0.0

    -CLASSPATH=$CLASSPATH:${ORACLE_HOME}/j

    dbc/lib/classes12.zip

    Oracle source DB .

    MTK MTKMain >./MTKMain

  • 16 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 1) Project 3. DB2 MTK 1) Project

    Migration project

    -Project Name

    Project -Project Path

    ( Project

    )

    -Source DB

    Oracle, Sybase,MS SQL Server -DB2 target

    Target DB2

  • 17 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 2) source 3. DB2 MTK 2) source

    source DDL SQL file , Import sql file import.

    DB metadata ,Extract .

    Extract , popup , DB ., Database, Service name, , OK .

  • 18 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 2) source 3. DB2 MTK 2) source

    Source DB , source DB objecttree ., Migration check

    DDL file . . .

    Extract .

  • 19 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 2) source 3. DB2 MTK 2) source

    , .src file .View, delete .

    Source , tab Convert .

  • 20 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 3) Convert3. DB2 MTK 3) Convert

    , Convert .

    Schema conversion data type mapping .Type .

  • 21 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 3) Convert3. DB2 MTK 3) Convert

    type target type , , .

  • 22 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 4) Refine3. DB2 MTK 4) Refine

    Convert refine .

  • 23 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK 5) Generate Data Transfer scripts3. DB2 MTK 5) Generate Data Transfer scripts

    Data .

    script file

    IMPORT / LOAD ( LOAD)

    Data (INSERT/ REPLACE)

    File format

    Create Script script file .

  • 24 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK SQL Translator 3. DB2 MTK SQL Translator

    Conversion sql ., , table .

    SQL .

    Tools SQL Translator

  • 25 2008 IBM Corporation

    IBM DB2

    3. DB2 MTK Reporting 3. DB2 MTK Reporting

    HTML reporting.

    /projects//Reports/ .

    - Conversion_asset.html : project report

    - object

    Database, Schema,Package,User type,Table,View,Column,Index,Foreign Key,Proc & Function,Trigger

    - report

    , report - Tablespace table rowsize report

    - data .

    table , target table . Table key table toggle, click .

  • 26 2008 IBM Corporation

    IBM DB2

    4. SQL conversion SQL Syntax : Sequence4. SQL conversion SQL Syntax : Sequence

    .

    NEXTVAL(CURRVAL) for Sequence_nameSequence_name.NEXTVAL(CURRVAL)

    DB2Oracle

  • 27 2008 IBM Corporation

    IBM DB2

    4. SQL conversion SQL Syntax : rownum4. SQL conversion SQL Syntax : rownum

    Rownum select, insert, update ,

    - row_number() over() .

    Rownum row ,

    - row_number() over() , fetch first n rows only

    Update ( select c1 from tab1 where c2=v2 fetch first 10 rows only)set c1=v1;

    Update tab1 set c1=v1

    where c2=v2 and rownum

  • 28 2008 IBM Corporation

    IBM DB2

    4. SQL conversion SQL Syntax : outer join4. SQL conversion SQL Syntax : outer join

    Oracle (+) outer join

    Oracle outer join table (+)

    , DB2 .

    Select a.last_name , a.id, b.name

    From emp a left outer join customer b

    on a.id=b.sales_rep_id

    Where b.name like K%;

    Select a.last_name , a.id, b.name

    From emp a , customer b

    Where a.id = b.sales_rep_id (+)

    and b.name(+) like K% ;

    Select a.last_name , a.id, b.name

    From emp a full outer join customer b

    on a.id=b.sales_rep_id ;

    Select a.last_name , a.id, b.name

    From emp a , customer b

    Where a.id(+) = b.sales_rep_id(+) ;

    Select a.last_name , a.id, b.name

    From emp a left outer join customer b

    on a.id=b.sales_rep_id ;

    Select a.last_name , a.id, b.name

    From emp a , customer b

    Where a.id = b.sales_rep_id(+) ;

    Select a.last_name , a.id, b.name

    From emp a right outer join customer b

    on a.id=b.sales_rep_id ;

    Select a.last_name , a.id, b.name

    From emp a , customer b

    Where a.id(+) = b.sales_rep_id ;

    DB2Oracle

  • 29 2008 IBM Corporation

    IBM DB2

    4. SQL conversion SQL Syntax : dual table4. SQL conversion SQL Syntax : dual table

    Oracle system information dual table ,

    - DB2

    SYSIBM.SYSDUMMY1 select VALUES

    VALUES(current timestamp) into ;

    Or

    Select current timestamp

    From sysibm.sysdummy1;

    Select SYSDATE from DUAL;

    DB2Oracle

  • 30 2008 IBM Corporation

    IBM DB2

    4. SQL conversion SQL Syntax : decode4. SQL conversion SQL Syntax : decode

    Oracle decode DB2 CASE

    Select avg (

    case grade when A then 1 when B then 2 when C then 3 when D then 4 END)

    From students;

    Select avg ( decode ( grade, A,1,B,2,C,3,D,4))From students;

    DB2Oracle

  • 31 2008 IBM Corporation

    IBM DB2

    4. SQL conversion SQL Syntax : nvl4. SQL conversion SQL Syntax : nvl

    Oracle nvl DB2 COALESCE

    Select coalesce(manager_id , No Manager)From employee;

    Select Nvl(manager_id , No Manager)From employee;

    DB2Oracle

  • 32 2008 IBM Corporation

    IBM DB2

    4. SQL conversion SQL Syntax : 4. SQL conversion SQL Syntax :

    to_char UDF ora8.to_char

    to_number int, decimal casting ora8.to_number

    lpad, rpad UDF ora8.lpad(rpad)

    trim ltrim / rtrim .

    nvl COALESCE

    - MTK ora8.*** , .

    - UDF (user defined function) Logic ,

    .

    )

    CREATE FUNCTION RPAD (C1 VarChar(4000), N integer, C2 VarChar(4000))RETURNS VARCHAR(4000) LANGUAGE SQLSPECIFIC RPADBaseDETERMINISTICCONTAINS SQLNO EXTERNAL ACTIONRETURN substr(C1 || repeat(C2,((sign(N-length(C1))+1)/2)*(N-length(C1)+length(C2))/(length(C2)+1-sign(length(C2)))),1,N) ;

  • 33 2008 IBM Corporation

    IBM DB2

    5. MTK Migration 5. MTK Migration

    DB

    IBM MTK DB migration .

    Migration Migration DB tuning, .

    Migration

    SQL Oracle , .

    SQL MTK SQL Translator .

    IBM tool DB2 .

  • 34 2008 IBM Corporation

    IBM DB2

    5. MTK References5. MTK References

    MTK Web Site

    -http://www.ibm.com/db2/migration/mkt

    Migration Station

    -http://www.ibm.com/developerworks/ondemand/migrate/db.html

    MTK Support, Mailbox : [email protected]

  • 35 2008 IBM Corporation

    IBM DB2

    MTK DemoMTK Demo

    DEMO

  • 36 2008 IBM Corporation

    IBM DB2

    6. Access Guidelines: TBSCAN6. Access Guidelines: TBSCAN

    Query: SELECT C1 FROM T1 /* */

    Plan:

    RETURN

    |

    TBSCAN

    |

    TABLE: DDEACONU

    T1

  • 37 2008 IBM Corporation

    IBM DB2

    6. Access Guidelines: IXSCAN6. Access Guidelines: IXSCAN

    Query: SELECT C1 FROM T1 /* */

    Plan:

    RETURN

    |

    IXSCAN

    ( 2)

    |

    INDEX: DDEACONU

    T1_I1

  • 38 2008 IBM Corporation

    IBM DB2

    Query: SELECT C1 FROM T1 /* */

    Plan:

    RETURN

    |

    FETCH

    /------------------+-----------------\

    RIDSCN TABLE: DDEACONU T1

    |

    SORT

    |

    IXSCAN

    |

    INDEX: DDEACONU T1_I1

    6. Access Guidelines: LPREFETCH6. Access Guidelines: LPREFETCH

  • 39 2008 IBM Corporation

    IBM DB2

    Query: SELECT C1 FROM T1 /*

  • 40 2008 IBM Corporation

    IBM DB2

    Query: SELECT T1 FROM T1 WHERE C1 = ? AND C2 = ?

    Guideline:

    /*

    */

    Note: Indexes must be specified in a IXAND guideline.

    6. Access Guidelines: IXAND6. Access Guidelines: IXAND

  • 41 2008 IBM Corporation

    IBM DB2

    Query: SELECT * FROM T1 WHERE C1 in (?,?)

    Guideline: /* */

    Note: We cannot specify indexes in an IXOR guideline

    6. Access Guidelines: IXOR6. Access Guidelines: IXOR

  • 42 2008 IBM Corporation

    IBM DB2

    Query: select * from t1 join t2 on t1.c1 = t2.c1

    Guideline: /* */

    Guideline: /* */

    Guideline: /* */

    Guideline: /* */

    6. Access Guidelines: JOIN6. Access Guidelines: JOIN

  • 43 2008 IBM Corporation

    IBM DB2

    Query: select * from t1, t2, t3 where t1.c1 = t3.c1 and t1.c1 = t2.c1

    Guideline: /*

    */

    Note: Make sure the tables joined are part of the same QTB

    6. Access Guidelines: More complex Join 6. Access Guidelines: More complex Join

  • 44 2008 IBM Corporation

    IBM DB2

    6. More ways to reference tables: TABID attribute6. More ways to reference tables: TABID attribute

    Query: SELECT * FROM T1

    Rewriten query: SELECT Q1.C1 AS "C1", Q1.C2 AS "C2FROM DDEACONU.T1 AS Q1

    Use of TABID attribute in an ACCESS hint:

    SELECT * FROM T1 /* */

    OR

    SELECT * FROM T1 /* */

  • 45 2008 IBM Corporation

    IBM DB2

    6. Specifying exposed names in ACCESS hints:6. Specifying exposed names in ACCESS hints:

    Query: SELECT * FROM T1 as TAB

    Use of exposed name in an ACCESS hint:

    SELECT * FROM T1 /* */

    Note:

    SELECT * FROM T1 /* */Will return SQL0437 rc13, EXP0009W: TABLE attribute not found

  • 46 2008 IBM Corporation

    IBM DB2

    6. Accessing base tables through views:6. Accessing base tables through views:

    Tables, indexes and views:

    CREATE TABLE T1 (C1 INT, C2 INT);

    CREATE INDEX T1_I1 ON T1 (C1);

    CREATE VIEW V1 AS SELECT * FROM T1 as TAB;

    CREATE VIEW V2 AS SELECT C1 FROM V1;

    Query:

    SELECT C1 FROM v2 /*

    */;

  • 47 2008 IBM Corporation

    IBM DB2

    7. User Defined Function C sample7. User Defined Function C samplevoid SQL_API_FN ToNum ( SQLUDF_DOUBLE *inAmt

    , SQLUDF_CHAR *outVal, SQLUDF_SMALLINT *amtNullInd, SQLUDF_SMALLINT *valNullInd, SQLUDF_TRAIL_ARGS_ALL, SQLUDF_DBINFO *dbinfo)

    {int intvalue, charlen;int i, j,k;char charvalue[30], *charp, *retp, *retvalue;char format[30];

    sprintf(charvalue, "%f", *inAmt);for ( k = 0 ; k < strlen(charvalue) ; k++ ) if ( charvalue[k] == '.' ) break;charlen = k;

    retp = retvalue = (char *)malloc(charlen + charlen/3 + 5);

    charp = charvalue;

    if (charvalue[0] == '-') {*retp++ = *charp++;charlen -= 1;

    }

    while (charlen > 3) {i = charlen % 3;if (i == 0)

    i = 3;for (j=0; j

  • 48 2008 IBM Corporation

    IBM DB2

    7. User Defined Function C sample7. User Defined Function C samplevoid SQL_API_FN ToHg ( SQLUDF_DOUBLE *inAmt

    , SQLUDF_CHAR *outVal, SQLUDF_SMALLINT *amtNullInd, SQLUDF_SMALLINT *valNullInd, SQLUDF_TRAIL_ARGS_ALL, SQLUDF_DBINFO *dbinfo)

    {

    /*static char *suja[]={"","","","","","","","","",""};static char *suja[]={"","","","","","","","","",""};*/static char *suja[]={"","","","","","","","","",""};

    char charvalue[100], *charp;char retv[100], *retp, *returnvalue;char tmp_su[1];int charlen,cur_num;int i,j,k;

    memset(retv,0x00,sizeof(retv));retp = returnvalue = retv;

    sprintf( charvalue,"%f", *inAmt);charp = charvalue;

    for ( i = 0; i < strlen(charvalue); i++ ) if ( charvalue[i] == '.' ) break;charlen = i;

    if ( charvalue[0] == '-' ) {sprintf(retp,"%c",*charp++);retp += strlen(retp);charlen--;

    }

  • 49 2008 IBM Corporation

    IBM DB2

    7. User Defined Function C sample7. User Defined Function C sample

    while ( charlen > 0 ) {i = charlen % 4 ;if ( i == 0 ) i = 4;k = i;for ( j = 0; j < i ; j++ ) {

    sprintf(tmp_su,"%c",*charp++);cur_num = atoi(tmp_su);

    if ((cur_num>=1)&&(cur_num

  • 50 2008 IBM Corporation

    IBM DB2

    7. User Defined Function C sample7. User Defined Function C sample

    # Build proceduredb2 connect to sample

    db2 prep kc.sqc bindfiledb2 bind kc.bnd

    cl -Zi -Od -c -W2 -DWIN32 -MD kc.c

    link -debug -out:kc.dll -dll kc.obj db2api.lib -def:kc.defcopy kc.dll "C:\Program Files\IBM\SQLLIB\FUNCTION"

    CREATE FUNCTION TOHG(DOUBLE)RETURNS VARCHAR(45)EXTERNAL NAME 'kc!ToHg'FENCEDLANGUAGE CPARAMETER STYLE SQL DETERMINISTICNO SQLNO EXTERNAL ACTIONALLOW PARALLEL DBINFO;

    CREATE FUNCTION ToHg(INTEGER)RETURNS VARCHAR(45)SOURCE TOHG(DOUBLE);

    CREATE FUNCTION ToHg(SMALLINT)RETURNS VARCHAR(45)SOURCE TOHG(DOUBLE);

    CREATE FUNCTION TONUM(DOUBLE)RETURNS VARCHAR(45)EXTERNAL NAME 'kc!ToNum'FENCEDLANGUAGE CPARAMETER STYLE SQL DETERMINISTICNO SQLNO EXTERNAL ACTIONALLOW PARALLEL DBINFO;

    CREATE FUNCTION TONUM(INTEGER)RETURNS VARCHAR(45)SOURCE TONUM(DOUBLE);

    CREATE FUNCTION TONUM(SMALLINT)RETURNS VARCHAR(45)SOURCE TONUM(DOUBLE);

  • 51 2008 IBM Corporation

    IBM DB2

    8. DBMS 8. DBMS

    WFS DEMO

    -------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------connect to sample;drop wrapper net8;

    create wrapper net8;

    CREATE SERVER ORCL_SVR TYPE ORACLE VERSION 10WRAPPER NET8--AUTHORIZATION SCOTT PASSWORD TIGEROPTIONS(NODE 'orcl'

    , ADD CPU_RATIO '1.0', COLLATING_SEQUENCE 'N', IO_RATIO '1.0', COMM_RATE '1.0', DB2_TWO_PHASE_COMMIT 'Y', VARCHAR_NO_TRAILING_BLANKS 'N', PUSHDOWN 'Y', DB2_MAXIMAL_PUSHDOWN 'Y');

    create user mapping for user server orcl_svroptions ( remote_authid 'scott', remote_password 'tiger');

    commit;

  • 52 2008 IBM Corporation

    IBM DB2

    8. DBMS 8. DBMS

    -------------------------------------------------------------------------------------------------------------------------------- Table : Nickname ------------------------------------------------------------------------------------------------------------------------------

    create nickname ora_dept for orcl_svr.scott.dept;create nickname ora_emp for orcl_svr.scott.emp;

    commit;

    -------------------------------------------------------------------------------------------------------------------------------- Table : Data ------------------------------------------------------------------------------------------------------------------------------

    drop table db2_dept ;drop table db2_emp ;create table db2_dept like ora_dept;create table db2_emp like ora_emp ;

    insert into db2_dept select * from ora_dept;insert into db2_emp select * from ora_emp ;

    export to ora_dept.del of del select * from ora_dept;export to ora_emp.del of del select * from ora_emp;

    commit;

  • 53 2008 IBM Corporation

    IBM DB2

    8. DBMS 8. DBMS

    -------------------------------------------------------------------------------------------------------------------------------- Table : Nickname ------------------------------------------------------------------------------------------------------------------------------

    create nickname ora_dept for orcl_svr.scott.dept;create nickname ora_emp for orcl_svr.scott.emp;

    commit;

    -------------------------------------------------------------------------------------------------------------------------------- Table : Data ------------------------------------------------------------------------------------------------------------------------------

    drop table db2_dept ;drop table db2_emp ;create table db2_dept like ora_dept;create table db2_emp like ora_emp ;

    insert into db2_dept select * from ora_dept;insert into db2_emp select * from ora_emp ;

    export to ora_dept.del of del select * from ora_dept;export to ora_emp.del of del select * from ora_emp;

    commit;

  • 54 2008 IBM Corporation

    IBM DB2

    8. DBMS 8. DBMS

    -------------------------------------------------------------------------------------------------------------------------------- Table : Query ------------------------------------------------------------------------------------------------------------------------------

    select empno, ename, job, a.deptno, b.dnamefrom ora_emp a, ora_dept b

    where a.deptno = b.deptno;

    select empno, ename, job, a.deptno, b.dnamefrom db2_emp a, db2_dept b

    where a.deptno = b.deptno;

    select empno, ename, job, a.deptno, b.dnamefrom ora_emp a, db2_dept b

    where a.deptno = b.deptno;

    select empno, ename, job, a.deptno, b.dnamefrom db2_emp a, ora_dept b

    where a.deptno = b.deptno;

    commit;

  • 55 2008 IBM Corporation

    IBM DB2

    8. DBMS 8. DBMS

    --------------------------------------------------------------

    --------------------------------------------------------------

    --

    -- set passthru :

    --

    --------------------------------------------------------------

    --------------------------------------------------------------

    set passthru orcl_svr;

    drop table employee;

    drop table department;

    select * from tab;

    select * from all_users;

    set passthru reset;

    select * from tab;

    select * from all_users;

    commit;

  • 56 2008 IBM Corporation

    IBM DB2

    9. SQL 9. SQL

    Data Type

    - DECFLOAT(16) / DECFLOAT(32)

    Function

    - ROWID

    - ROW CHANGE TOKEN / ROW CHANGE TIMESTAMP

    - TO_CHAR / TO_DATE

    - START WITH name = 'Goyal'

    - CONNECT BY PRIOR empid = mgrid

    - ORDER SIBLINGS BY salary;

    - FETCH FIRST n ROWS / ROW_NUMBER() / ROWNUM

    - NVL / DECODE

    - LEAST / GREATEST

    - BITAND, BITANDNOT, BITOR, BITXOR, BITNOT

  • 57 2008 IBM Corporation

    IBM DB2

    9. SQL 9. SQL

    DUAL

    - select current date from dual

    Outer Join (+)

    - select * from org a, org2 b where a.deptnumb = b.deptnumb

    - select * from org a, org2 b where a.deptnumb(+) = b.deptnumb

    - select * from org a, org2 b where a.deptnumb = b.deptnumb(+)

    SEQUENCE

    - sequence-name.NEXTVAL can be specified in place of NEXT VALUE FOR sequence-name

    - sequence-name.CURRVAL can be specified in place of PREVIOUS VALUE FOR sequence-

    name

  • 58 2008 IBM Corporation

    IBM DB2

    9. SQL 9. SQL

    SELECT

    LEVEL

    , cast(SYS_CONNECT_BY_PATH(Name, '-') as char(30))AS Path

    , EMPNO, MGR

    FROM EMP3

    START WITH EMPNO = 7839

    CONNECT BY PRIOR EMPNO = MGR

    Order siblings by name

    ;

    SELECT LEVEL

    ,cast(SYS_CONNECT_BY_PATH(Name, '-') as char(30))AS Path

    ,empno, mgr, Name

    FROM EMP3

    START WITH Name = 'KING'

    CONNECT BY PRIOR empno = mgr

    ORDER SIBLINGS BY Name

    ;

  • 59 2008 IBM Corporation

    IBM DB2

    Q&AQ&A

    Q&AQ&A