2014. 11. 7. 11:13

보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

Oracle2010. 3. 9. 14:46
Oracle - comment on table 또는 column  Database 

2010/02/27 10:57

복사http://blog.naver.com/json2811/90082159361

▶ comment on table 테이블명 is '멋진 테이블';

 

▶ comment on column 테이블명.칼럼명 is '더 멋진 칼럼';

 

▶ data dictionary

USER_TAB_COMMENTS
USER_COL_COMMENTS

 

select * from user_tab_comments

where comments is not null

/

 

select * from user_col_comments

where comments is not null

/


[SAMPLE#1]

COMMENT ON COLUMN SAEBIT.ADDITIONCDR_ITEMCOD.TYPE IS '타입';


[SAMPLE#2]

select 'COMMENT ON TABLE '||TABLE_NAME||' IS '||COMMENTS||';'
from user_tab_comments
where comments is not null
 and table_name in ('PBCATFMT', 'PBCATTBL')

select 'COMMENT ON COLUMN '||TABLE_NAME||'.'||COLUMN_NAME||' IS '||COMMENTS||';' 

from user_col_comments

where comments is not null

 and table_name in ('PBCATFMT', 'PBCATTBL',)





1. Object 로 조회하기

  > SELECT * FROM all_objects

     WHERE object_type='TABLE'

     AND object_name LIKE '%테이블명 일부%'

 

 

2. all_tables 로 조회하기

  > SELECT * FROM all_tables

     WHERE talbe_name LIKE '%테이블명 일부%'



Posted by Julyus
Oracle2009. 11. 20. 18:11
Oracle 11g Improves Partitioning
 
Location: Blogs  Bert Scalzo's Blog    
 Bert Tuesday, August 21, 2007 4:21 AM
Oracle 11g has a plethora of great new features. One area that has improved with each of the last four releases has been partitioning, i.e. the method to break larger tables into smaller, more manageable and efficient sub-tables. While it was originally touted as a boon for just the data warehousing world, partitioning nonetheless works well in many situations. With Oracle continuing to improve upon them – partitioning is now a powerful asset in any DBA’s tool belt. So let’s examine some of the new table partitioning techniques introduced with Oracle 11g.

First, Oracle has nicely “rounded out” the composite partitioning alternatives by adding list-hash, list-list, list-range and range-range partitioning. These new methods are pretty straight forward for anyone who has already been using partitioning. However nice these new composite options may be – this was only an incremental or evolutionary change.

Second, Oracle has introduced “Interval Partitioning” – a very useful and powerful option for DBAs whose data is continuously growing over a range. Before 11g, the DBA had to keep ahead of the data growth curve by manually adding partitions for the new range of values. So for example if I was partitioning by week, I had to remember to manually add the next weeks partition before some application tried to insert values within that range. Otherwise you’d get the Oracle error ORA-14400: inserted partition key does not map to any partition. Here’s an example of that happening:

CREATE TABLE TABLE1
(
 
 C1  INTEGER                        NOT NULL PRIMARY KEY,
 
 C2  VARCHAR2(1 BYTE)        NOT NULL,
 
 C3  VARCHAR2(1 BYTE)        NOT NULL,
  C4  VARCHAR2(1 BYTE)        NOT NULL
)
PARTITION BY RANGE (C1)
(  
  PARTITION P1 VALUES LESS THAN (100),
  PARTITION P2 VALUES LESS THAN (200),
  PARTITION P3 VALUES LESS THAN (300)
);

insert into table1 values (100,'a','b','c');
insert into table1 values (101,'a','b','c');
insert into table1 values (200,'a','b','c');
insert into table1 values (201,'a','b','c');
insert into table1 values (300,'a','b','c');  ç this statement causes the error 

You can sort of think of this like the old “unable to allocate extent” error message for tablespaces where the data file size was not allowed to automatically extend and, much like that extent allocation failure message, ORA-14400 should be a message that never should really occur (assuming the DBA is keeping current with their data growth needs).

So here’s the same table implemented using interval partitioning.

CREATE TABLE TABLE2
(
  C1  INTEGER                            NOT NULL PRIMARY KEY,
  C2  VARCHAR2(1 BYTE)        NOT NULL,
  C3  VARCHAR2(1 BYTE)        NOT NULL,
  C4  VARCHAR2(1 BYTE)        NOT NULL
)
PARTITION BY RANGE (C1)
INTERVAL (100)
(  
  PARTITION P1 VALUES LESS THAN (100)
); 

insert into table2 values (100,'a','b','c');
insert into table2 values (101,'a','b','c');
insert into table2 values (200,'a','b','c');
insert into table2 values (201,'a','b','c');
insert into table2 values (300,'a','b','c'); 

We don’t get any errors with this implementation – even though we did not create but the first partition for values less than 100. In this case, Oracle simply creates the necessary partitions for you on the fly. Here’s what partitions the above two table examples yield:

TABLE_NAME         PARTITION_NAME        HIGH_VALUE
--------------------------  ------------------------------  -------------------
TABLE1                      P1                                      100
TABLE1                      P2                                      200
TABLE1                      P3                                      300
TABLE2                      P1                                      100
TABLE2                      SYS_P41                             200
TABLE2                      SYS_P42                             300
TABLE2                      SYS_P43                             400

Third, Oracle has introduced “Reference Partitioning.” This technique is both novel and a little more complex. You must have a “parent-child relationship” between two tables with active primary and foreign keys between them. There are real benefits to this approach, namely that reference partitioning permits logically equi-partitioning the child table by inheriting the partition key from the parent table without duplicating the key columns.

Here’s an example or reference partitioning:

CREATE TABLE PARENT
(
  P1  INTEGER                             NOT NULL PRIMARY KEY,
  P2  VARCHAR2(1 BYTE)        NOT NULL
)
PARTITION BY RANGE (P1)
(  
  PARTITION P1 VALUES LESS THAN (100),
  PARTITION P2 VALUES LESS THAN (200),
  PARTITION P3 VALUES LESS THAN (300)
); 

CREATE TABLE CHILD
(
  C1  INTEGER                             NOT NULL,
  C2  VARCHAR2(1 BYTE)             NOT NULL,
  C3  VARCHAR2(1 BYTE)             NOT NULL,
  constraint child_pk primary key(c1,c2),
  constraint child_fk foreign key(c1) references parent(p1)
)
PARTITION BY REFERENCE(child_fk);

And here are the partitions the reference partition example created:

TABLE_NAME         PARTITION_NAME        HIGH_VALUE
--------------------------  ------------------------------  -------------------
CHILD                        P1
CHILD                        P2
CHILD                        P3
PARENT                     P1                                      100
PARENT                     P2                                      200
PARENT                     P3                                      300

Notice how child table high value settings are NULL? Since this is an equi-partitioning method where the child inherits its partitioning directly this from the parent, there is no need to duplicate the meta-data. As pointed out above, this also saves the database from storing the actual data in both places. This could be significant with VLDB’s.

Fourth and finally, Oracle has introduced “Virtual Columns based Partitioning.” I wrote about virtual columns last week – and here’s the example. 

CREATE TABLE PROD4 (
XPNUM    CHAR(13)                NOT  NULL,
STAT    CHAR(2)      GENERATED ALWAYS AS ((SUBSTR(XPNUM,1,2))),
DEPT    CHAR(4)      GENERATED ALWAYS AS ((SUBSTR(XPNUM,3,4))),
PNUM    CHAR(7)     GENERATED ALWAYS AS ((SUBSTR(XPNUM,7,7))),
CONSTRAINT PROD4_PK PRIMARY KEY (XPNUM)
);

Now with 11g, we can even partition on such virtual columns as shown below:

CREATE TABLE VIRT_PART (
XPNUM   CHAR(13)    NOT  NULL,
STAT    CHAR(2)     GENERATED ALWAYS AS ((SUBSTR(XPNUM,1,2))),
DEPT    CHAR(4)     GENERATED ALWAYS AS ((SUBSTR(XPNUM,3,4))),
PNUM    CHAR(7)     GENERATED ALWAYS AS ((SUBSTR(XPNUM,7,7))),
CONSTRAINT VIRT_PART_PK PRIMARY KEY (XPNUM)
)
PARTITION BY HASH (DEPT)
PARTITIONS 4;

Wow – Partitioning has come a long way baby

Copyright ©2007 Quest Software Inc.
Posted by Julyus
Oracle2009. 11. 20. 13:44

관리 >> 파티션(Range List Composition Partition)  오라클(운영)

2007/12/24 17:16

복사http://blog.naver.com/owner71/20045212389

No. 22103

(V9.2) RANGE LIST PARTITIONING - ORACLE 9.2 ENHANCEMENT
=======================================================

PURPOSE
-------

   이 문서는 Oracle 9.2의 새 기능인 Range list partition을 생성하고
   관리하기 위한 방법에 대한 자료이다.


Explanation
-----------

Range List Partitioning은 RDBMS V9.2에서 처음으로 소개된 기능이다. 
이 방법은 V8.0에서 소개된 Range partitioning과 V9.0.1에서 소개된 
List partitioning을 결합한 형태의 새로운 방법이다.

Range-List method는 Range 형태로 먼저 데이타를 partition하고  
그 다음에 List-method를 이용하여 subpartitioning을 하는 방법이다.

Composite Range-Hash method와는 달리 이 방법은 각 row가 어느 
subpartition에 속하게 될지를 조절할 수 있다. 
그러나, multiple subpartition keys 는 지원하지 않는다. 이는 List 
method가 이것을 지원하지 않기 때문이다. 
오직 하나의 column만 key partition으로 가능하다.
List partitioning 에 대한 자료는 <Note:149116.1>을 참고하기 바란다.


RANGE-LIST Table에 지원되는 명령어
----------------------------------
1) All DMLs operations
2) Add partition or subpartition
3) Drop partition or subpartition
4) Modify partition or subpartition
5) Rename partition or subpartition
6) Exchange partition or subpartition
7) Merge partitions or subpartition
8) Modify default attribute of a table or partition
9) Modify real attribute of a partition or subpartition
10) Add/Drop values in subpartition
11) Set subpartition template
12) Rename partition or subpartition
13) Move subpartition
14) Split partition or subpartition
15) Truncate partition or subpartition


Index에 지원되는 명령어
-----------------------

단지 btree 또는 bitmap Local Index 만이 RANGE-LIST type일 수 있다.

아래의 command만이 가능하다.

1) Modify default attributes for table or partition.
2) Modify real attributes for partition or subpartition
3) Rebuild of index subpartition
4) Rename partition or subpartition


제약사항
--------

The same known restrictions are still available for Range-List 
partitioning like the current limit of 64k overall segments.


Example
-------
1) Range-List partition 생성 예제

CREATE TABLE empdata
( empno number,
ename varchar2(20),
deptno number,
continent varchar2(6),
hiredate date,
job varchar2(10),
salary number)
PARTITION BY RANGE (deptno)
SUBPARTITION BY LIST (continent)
(PARTITION d1_emp VALUES LESS THAN (100)
(SUBPARTITION d1_con1 VALUES ('ASIA', 'AUST'),
SUBPARTITION d1_con2 VALUES ('AMER'),
SUBPARTITION d1_con3 VALUES ('AFRICA'),
SUBPARTITION d1_con4 VALUES ('EUROPE')),
PARTITION d2_emp VALUES LESS THAN (maxvalue)
(SUBPARTITION d2_con1 VALUES ('ASIA', 'AUST'),
SUBPARTITION d2_con2 VALUES ('AMER'),
SUBPARTITION d2_con3 VALUES ('AFRICA'),
SUBPARTITION d2_con4 VALUES ('EUROPE'))
);


2) Range-Hash partition 생성 예제

Range-Hash method는 어떤 level에 모든 다른 subpartition들을 
반드시 명시하지 않아도 된다. 
아래와 같이 SUBPARTITION TEMPLATE 절을 사용할 수 있다.


CREATE TABLE empdata
( empno number,
ename varchar2(20),
deptno number,
continent varchar2(6),
hiredate date,
job varchar2(10),
salary number)
PARTITION BY RANGE (deptno)
SUBPARTITION BY LIST (continent)
SUBPARTITION TEMPLATE
(SUBPARTITION d1_con1 VALUES ('ASIA', 'AUST') tablespace PART1,
SUBPARTITION d1_con2 VALUES ('AMER') tablespace PART2,
SUBPARTITION d1_con3 VALUES ('AFRICA') tablespace PART3,
SUBPARTITION d1_con4 VALUES ('EUROPE') tablespace PART3
)
(PARTITION d1_emp VALUES LESS THAN (100),
PARTITION d2_emp VALUES LESS THAN (maxvalue)
);

Storage 절은 TABLESPACE 절을 제외하고는 partition level로부터 상속받는다. 
만약, partition level에서 정의되어 있지 않으면 underlying table로부터 
storage 절을 상속받는다.

Sample data to load:
INSERT INTO empdata(empno,deptno,continent) values(1,50,'AMER');
--> Will be inserted into subpartition d1_con2
INSERT INTO empdata(empno,deptno,continent) values(2,100,'ASIA');
--> Will be inserted into subpartition d2_con1
INSERT INTO empdata(empno,deptno,continent) values(3,150,'EUROPE');
--> Will be inserted into subpartition d2_con4
INSERT INTO empdata(empno,deptno,continent) values(4,50,'AUST');
--> Will be inserted into subpartition d1_con1
INSERT INTO empdata(empno,deptno,continent) values(5,250,'AFRICA');
--> Will be inserted into subpartition d2_con3

  
Reference Documents
-------------------
<Note:209368.1>
Oracle 9.2 Administrator's Guide
Oracle 9.2 Performance Tuning and Reference

 

[ 생성 / 수정 / 관리 ]

set linesize 130;
col high_value format a20;


SELECT table_name, partition_name partition, high_value,
            partition_position position 
     FROM user_tab_partitions 
     WHERE table_name='PTNEW2' order by position;

 SELECT TABLESPACE_NAME, PARTITION_NAME, SUBPARTITION_NAME
  FROM user_TAB_SUBPARTITIONS WHERE TABLE_NAME='PTNEW2'
  ORDER BY TABLESPACE_NAME;


alter table ptnew2  add  partition pt_Site02 values less than('003');

ALTER TABLE ptnew2
   MODIFY PARTITION pt_Site02 
      ADD SUBPARTITION site02_z_article_pt
         VALUES ('z0000') tablespace partition_1;


ALTER TABLE ptnew2
   MODIFY PARTITION pt_Site01 
      ADD SUBPARTITION site01_x_article_pt
         VALUES ('x0000') tablespace partition_1;

alter table ptnew2 
       modify subpartition site01_x_article_pt  
       add values('x0001');


alter table ptnew2 
       modify subpartition site01_a_article_pt  
       drop values('a0002');

alter table ptnew2 
       modify partition pt_site01
       drop subpartition site01_x_article_pt;

alter table ptnew2
      drop subpartition site01_x_article_pt;


alter table ptnew2  add  partition pt_Site03 values less than('003')
                         (subpartition site03_a_article_pt values('a0000'));

ALTER TABLE ptnew2
   MODIFY PARTITION pt_Site03 
      ADD SUBPARTITION site03_b_article_pt
         VALUES ('b0000') tablespace partition_1;

 

SELECT partition_name partition, high_value,
            partition_position position 
     FROM user_tab_partitions 
     WHERE table_name='ARTICLE_TB'
     order by position;


SELECT  PARTITION_NAME, SUBPARTITION_NAME,TABLESPACE_NAME
FROM USER_TAB_SUBPARTITIONS WHERE TABLE_NAME='ARTICLE_TB'
 ORDER BY TABLESPACE_NAME;


SELECT partition_name partition, high_value
     FROM user_tab_subpartitions 
     WHERE table_name='ARTICLE_TB'
     order by position;

select partition_name,  SUBPARTITION_NAME,high_value, subpartition_position from user_tab_subpartitions

Posted by Julyus
Java2009. 10. 15. 15:05

url="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=000.000.000.000)(PORT=1521))                         (ADDRESS=(PROTOCOL=TCP)(HOST=000.000.000.000)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCL)))"

Posted by Julyus
Oracle2009. 10. 14. 13:24
Oracle 10g 에서 table drop 후에 휴지통 비우기

오라클 10g 에서는 table을 drop 하면 테이블명이 이상한 테이블이 남는다.

14:39:03 SQL> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
DEPT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
STUDENT TABLE
BIN$KoR6DxitQe2IROQYZ/VCeQ==$0 TABLE
BIN$fpGTGSbtRHu8b8WEkLl/mQ==$0 TABLE
BIN$+vzg/bJsTySbtJXGBnsgHw==$0 TABLE
SYSDATETB TABLE
EMP_FTEST TABLE
BIN$6Cen+DdJQW66ybpCCiP2IA==$0 TABLE
CONS_TEST TABLE

12 rows selected.

14:39:08 SQL>

이것을 지우려면 아래의 명령어를 치면 된다

SQL> PURGE RECYCLEBIN

10g는 휴지통 관리를 해서

drop한 후에도 다시 복구 할 수 있다고 한다...

그래서 drop 후에는 쓰레기테이블이 남아있다.
Posted by Julyus
2009. 10. 6. 09:35

보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

Oracle2009. 9. 21. 13:42

* 테이블 삭제 시

drop table 테이블명 CASCADE CONSTRAINT;

 

* 휴지통 비우기

purge recyclebin;

 

* 테이블 완전 삭제하기 (휴지통에 저장되지 않음)

DROP TABLE 테이블명 CASCADE CONSTRAINT purge;

 

* 휴지통에 있는 테이블 복원

FLASHBACK TABLE 테이블명 TO BEFORE DROP

 

* 컬럼명 변경

ALTER TABLE 테이블명 RENAME COLUMN 변경전 컬럼명 TO 변경후 컬럼명;

Posted by Julyus
Oracle2009. 9. 21. 11:42
PROCEDURE Sample oracle 

2009/09/02 00:04

복사http://blog.naver.com/delcom/80087374247

DROP   PROCEDURE Proc_master;
CREATE PROCEDURE Proc_master
  (sSIPNUM in  varchar2)
IS
begin
    begin
      insert into imms.mc_comsip_m
        (SIPNUM) values (sSIPNUM);
    exception
       when DUP_VAL_ON_INDEX then -- key 중복 error 일 경우 update 수행
            rollback; 
            raise_application_error(-20502, 'insert other error...DUP');
       when OTHERS then
            rollback;
            raise_application_error(-20502, 'insert other error...');         
    end;  
--    begin
    
--    end; 
        
END Proc_master;

 

==========================================================================================

DROP   PROCEDURE Proc_test;
CREATE PROCEDURE Proc_test
  (sPJTCOD     in  varchar2,
   sSTART_YM   in  varchar2,
   sPRLCOA     in  varchar2,
   sPRICOD     in  varchar2,
   sP_EMPNO    in  varchar2,
   sMsg       out varchar2)
IS
  sOPTTYP varchar2(10);


CURSOR  M1 IS
  select OPTTYP from imms.MC_POSUM_D
   where PJTCOD   = sPJTCOD  
     and START_YM = sSTART_YM
     and PRLOCA   = sPRLCOA  
     and PRICOD   = sPRICOD  
     and P_EMPNO  = sP_EMPNO;
begin    

  begin
    Insert into imms.MC_POSUM
      (select * from imms.MC_POSUM
        where PJTCOD   = sPJTCOD  
          and START_YM = sSTART_YM
          and PRLOCA   = sPRLCOA  
          and PRICOD   = sPRICOD  
          and P_EMPNO  = sP_EMPNO);
          
  end;


  open M1;
  Loop
    FETCH M1
      into sOPTTYP;

      begin    
        Insert into imms.MC_POSUM_D
          (select * from imms.MC_POSUM_D     
            where PJTCOD   = sPJTCOD       
              and START_YM = sSTART_YM     
              and PRLOCA   = sPRLCOA       
              and PRICOD   = sPRICOD       
              and P_EMPNO  = sP_EMPNO
              and OPTTYP   = sOPTTYP);    
     exception
       when DUP_VAL_ON_INDEX then -- key 중복 error 일 경우 update 수행
            rollback; 
            raise_application_error(-20502, 'insert other error...DUP');
            sMsg := '-20502, insert other error...';
       when OTHERS then
            rollback;
            raise_application_error(-20502, 'insert other error...');         
            sMsg := '-20502, insert other error...';
     end;
      
  End Loop;      
  Commit;
  
close M1;

        
END Proc_test;

==========================================================================================

      

PROCEDURE SAMPLE_TEST IS
  aa varchar2(10) := 'test';
  bb varchar2(10) := 'test1';
  cc varchar2(10) := 'test2';
BEGIN
  begin
     insert into test_tab(a, b, c)
     values (aa, bb, cc);
  exception
       when DUP_VAL_ON_INDEX then -- key 중복 error 일 경우 update 수행
            begin
               update test_tab
                  set b = bb,
                      c = cc
                where a = aa;
            exception
                 when OTHERS then -- 기타 error 일 경우
                      raise_application_error(-20501, 'update error...');         
            end;
       when OTHERS then
            rollback;
            raise_application_error(-20502, 'insert other error...');         
  end;
END;

Posted by Julyus
Oracle2009. 9. 18. 11:16
해당 서버의 table, procedure, trigger.. 등의 내용을 스크립트로 저장
Toad For Oracle

2009/02/04 15:22

복사 http://blog.naver.com/csr1214/20061393061

간혹 서버의 내용을 테스트하기 위해서 table, procedure 등등.. 내용을

다른 컴퓨터에 셋팅할때까 있다. 그 많은 table 을 하나 하나 만든다면... 헉 ㅠㅠ

생각만해도 끔찍할 수 없다.

토드에서 스크립트로 만들어서, 데이터만 옮긴다면 많은 시간을 절약 할 수 있을것이다.

 

1. "Database" → "Export" → "Export DDL" 선택

 

 

2. "Add" 버튼을 눌러준다.

 

 

3. 어떤 계정의 table, function, procedure, trigger, index... 등을 내려 받을지 선택을해준다

    → "▶" 눌러준다.

 

 

4. 만들 자료들이 들어와 있을것이다. 여기에서 불필요한것을 제외 시키고 "OK" 버튼을 눌러준다.

 

 

5. "Output" 에서 자료를 어떻게 받을지를 설정 한 후 → "▶" 눌러준다.

     나는 "HR.SQL" 파일로 받으라고 설정을 해주었다

 

 

6. 밑에 파일은 HR.SQL 파일을 열어 본것이다. ㅋㅋㅋ

    이 파일을 다른 PC로 가지고 가서 실행하면 서버의 테이블, 프로시저, 트리거, 함수등의

    내용이 금방 만들어진다. 움하하.. 쉽지 않은가... ㅋㅋ

 

 


Posted by Julyus