๐Ÿ’ป Programming/Oracle 11g (64)

1. Full ๋ฐฑ์—…(Full Level)

 

    1) Export ( ์˜ค๋ผํด DB ์ „์ฒด๊ฐ€ ๋ฐฑ์—…๋œ๋‹ค. ๋ชจ๋“  ํ…Œ์ด๋ธ” ์ŠคํŽ˜์ด์Šค, ์‚ฌ์šฉ์ž, ๊ฐ์ฒด, ๋ฐ์ดํ„ฐ๋“ค ํฌํ•จ ) 

 

[oracle@MyServer ~]$ exp userid=system/manager statistics=none file='./full.dmp' full=y


    2) Import

 

[oracle@MyServer ~]$ imp userid=system/system statistics=none file='./full.dmp' full=y  

 

   3) Import ์‹œ ์ฃผ์˜์‚ฌํ•ญ

๊ธฐ์กด DB์—์„œ export ๋‹น์‹œ์™€ ๋™์ผํ•œ SID๋ฅผ ๊ฐ€์ง€๋Š” DB๊ฐ€ ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค. 

๊ทธ๋ ‡์ง€ ์•Š์„๊ฒฝ์šฐ import ์ค‘์— ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

 

 

2. ์‚ฌ์šฉ์ž๋‹จ์œ„ ๋ฐฑ์—…(User Level)

    

    1) Export ( ์‚ฌ์šฉ์ž๊ฐ€ ์†Œ์œ ํ•˜๊ณ  ์žˆ๋Š” ๊ฐ์ฒด, ๋ฐ์ดํ„ฐ๋“ค ํฌํ•จ ) 

 

[oracle@MyServer ~]$ exp userid=scott/tiger statistics=none file='./scott.dmp'  

 

    2) Import

 

[oracle@MyServer ~]$ imp userid=system/manager owner=scott statistics=none file='./scott.dmp'  

 

   3) Import ์‹œ ์ฃผ์˜์‚ฌํ•ญ

     ์ด๊ด€ํ•˜๋ ค๋Š” ์„œ๋ฒ„๋‚˜ ๊ธฐ์กด DB์— ๋™์ผํ•œ ์‚ฌ์šฉ์ž ๊ณ„์ •์ด ์ƒ์„ฑ์ด ๋˜์–ด ์žˆ์–ด์•ผ ํ•˜๋ฉฐ, TableSapce๊ฐ€ ์žˆ์–ด์•ผ ํ•œ๋‹ค.  

     SID๋Š” ๋‹ฌ๋ผ๋„ ์ƒ๊ด€์—†๋‹ค.

 

   4) Import ์ ˆ์ฐจ.

      - DB ์ƒ์„ฑ

      - TableSpace ์ƒ์„ฑ

      - ๊ณ„์ • ์ƒ์„ฑ ๋ฐ TableSpace ์ ‘๊ทผ ๊ถŒํ•œ ์ถ”๊ฐ€.

      - imp ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•œ ๋ฐ์ดํ„ฐ import

 

 

# exp, imp๋ช…๋ น์–ด์˜ ์˜ต์…˜์— ๋Œ€ํ•ด์„œ ์•Œ๊ณ ์‹ถ์œผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. 

 

[oracle@MyServer ~]$ imp help=y 

 


1. ๋‚˜ ์ž์‹ ์ด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ…Œ์ด๋ธ”์„ ์กฐํšŒํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด 

select * from user_tables;

 

2. dba๊ถŒํ•œ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž์˜ ํ…Œ์ด๋ธ”์„ ์กฐํšŒํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด

select * from dba_tables where owner='์‚ฌ์šฉ์žID'; 


์ด ์˜ค๋ฅ˜๋Š” Blobํ˜•ํƒœ์˜ ๋ฐ์ดํƒ€๋ฅผ String๋ณ€์ˆ˜์— ๋ฐ›์•„์˜ค๋ ค๊ณ  ํ• ๋•Œ ๋ฐœ์ƒํ•œ๋‹ค.

Blobํ˜•ํƒœ์˜ ๋ฐ์ดํƒ€๋ฅผ ๋ฐ›์•„์˜ฌ๋•Œ๋Š” String๋ณ€์ˆ˜ ๋Œ€์‹ ์— byte[]๋ฅผ ์จ์•ผํ•œ๋‹ค.


๋ง๊ทธ๋Œ€๋กœ ์ฝค๋งˆ๊ฐ€ ๋ˆ„๋ฝ๋˜์—ˆ๋‹ค๋Š” ์–˜๊ธฐ๋‹ค.  

ํ•˜์ง€๋งŒ!!!!! ๋•Œ๋กœ๋Š” ์—‰๋šฑํ•œ ์‹ค์ˆ˜์— ์—‰๋šฑํ•œ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๊ธฐ๋„ ํ•œ๋‹ค.

 

๋‚ด๊ฐ€ ์ € ์—๋Ÿฌ๋ฉ”์‹œ์ง€๋ฅผ ๋ณธ๊ฒƒ์€ ์•„๋ž˜์™€ ๊ฐ™์€ ์„ค์ •์„ ํ–ˆ์„๋•Œ๋‹ค.

์Šคํ”„๋ง ๊ธฐ๋ฐ˜ ์›น์•ฑ์„ ๋งŒ๋“ค๊ณ  xmlํŒŒ์ผ์— ์ฟผ๋ฆฌ๋ฌธ์„ ๋„ฃ์—ˆ๋Š”๋ฐ....

 

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

<insert id="add">
        insert into
            ํ…Œ์ด๋ธ”๋ช…
        values(
            column1 = #{col1, jdbcType=VARCHAR}
            ,โ€‹column2 = #{col2, jdbcType=VARCHAR}
            ,โ€‹column3 = #{col3, jdbcType=VARCHAR}
        )
</insert> 

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

์ž, ์—ฌ๊ธฐ์„œ ํ…Œ์ด๋ธ”๋ช…๊ณผ ์ปฌ๋Ÿผ๋ช…์€ ์ž„์˜๋กœ ์จ๋„ฃ์—ˆ๋‹ค. ๋ฌผ๋ก  ์‹ค์ œ ์†Œ์Šค์—์„œ๋Š” ์‹ค์ œ ํ…Œ์ด๋ธ”๋ช…๊ณผ ์ปฌ๋Ÿผ๋ช…์ด ๋“ค์–ด๊ฐ€์žˆ๋‹ค. ์ด ํ…Œ์ด๋ธ”์—๋Š” ์„ธ๊ฐœ์˜ ์ปฌ๋Ÿผ( column1, column2, column3 )์ด ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค. 

 

์ด ์ฝ”๋“œ์—์„œ ์™œ ๋ˆ„๋ฝ๋œ ์ฝค๋งˆ ๋ˆ„๋ฝ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”์ง€ ์ฐพ์•˜๋Š”๊ฐ€???

 

์ด ์ฝ”๋“œ์—๋Š” ์ฝค๋งˆ๊ฐ€ ๋ˆ„๋ฝ๋œ ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค. Insert ๋ฌธ์˜ ํ˜•์‹์ž์ฒด๊ฐ€ ํ‹€๋ ธ๋‹ค.

์œ„ ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฐ”๋€Œ์–ด์•ผ ํ•œ๋‹ค.

 

        insert into
            ํ…Œ์ด๋ธ”๋ช…
        values(
            #{col1, jdbcType=VARCHAR}
            ,โ€‹#{col2, jdbcType=VARCHAR}
            ,โ€‹#{col3, jdbcType=VARCHAR}
        ) 

 

์—๋Ÿฌ๋ฉ”์‹œ์ง€๋งŒ๋ณด๊ณ  ์ฝค๋งˆ๊ฐ€ ์–ด๋””๊ฐ€ ๋ˆ„๋ฝ๋๋‹ค๋Š”๊ฑฐ์ง€? ๋ผ๋Š” ์ƒ๊ฐ์„ ๊ฐ€์ง€๊ณ  ์˜ค๋ฅ˜๋ฅผ ์ฐพ์œผ๋ คํ•œ๋‹ค๋ฉด ํ•˜๋ฃจ์ข…์ผ์„ ํ—ˆ๋น„ํ•ด๋„ ๋ชป์ฐพ์„ ๊ฒƒ์ด๋‹ค.

 

๋‹น์‹ ์˜ ์ง€์‹์— ์กฐ๊ธˆ์ด๋‚˜๋งˆ ๋„์›€์ด ๋๊ธฐ๋ฅผ ๋ฐ”๋ผ๋ฉฐ ๊ธ€์„ ๋งˆ์นœ๋‹ค.... 


์•„๋ž˜ ์˜ˆ์ œ๋Š” JMNote.com์˜ ์œ„ํ‚คํŽ˜์ด์ง€์—์„œ ๋ณต์‚ฌํ•ด์˜จ ๊ฒƒ์ž„์„ ๋ฐํž™๋‹ˆ๋‹ค.

( ์›๋ณธ ์ฃผ์†Œ - 

http://jmnote.com/wiki/%EC%98%A4%EB%9D%BC%ED%81%B4_%EC%BB%AC%EB%9F%BC%EB%AA%85_%EC%88%9C%EC%84%9C_%EB%B3%80%EA%B2%BD

์‹ค์Šต ํ…Œ์ด๋ธ” ์ƒ์„ฑ

CREATE TABLE employee (
emp_no NUMBER PRIMARY KEY,
dept VARCHAR2 (16),
name VARCHAR2 (32)
);
INSERT INTO employee VALUES (130001, '์ธ์‚ฌ๋ถ€', 'ํ™๊ธธ๋™');
INSERT INTO employee VALUES (130002, '์˜์—…๋ถ€', '์ž„๊บฝ์ •');
INSERT INTO employee VALUES (130003, '์ƒ์‚ฐ๋ถ€', '์žฅ๊ธธ์‚ฐ');

๋ณ€๊ฒฝ ์ „

SELECT * FROM employee;
EMP_NO  DEPT    NAME
130001  ์ธ์‚ฌ๋ถ€       ํ™๊ธธ๋™
130002  ์˜์—…๋ถ€       ์ž„๊บฝ์ •
130003  ์ƒ์‚ฐ๋ถ€       ์žฅ๊ธธ์‚ฐ

๋ณ€๊ฒฝ

  • ์žฌ๋ฐฐ์—ด๋œ ์‚ฌ๋ณธ ์ƒ์„ฑ โ†’ ์‚ฌ๋ณธ์„ ์›๋ณธ์œผ๋กœ ๋Œ€์ฒด
CREATE TABLE temp AS SELECT emp_no, name, dept FROM employee;
DROP TABLE employee;
RENAME temp TO employee;

๋ณ€๊ฒฝ ํ›„

SELECT * FROM employee;
EMP_NO  NAME    DEPT
130001  ํ™๊ธธ๋™       ์ธ์‚ฌ๋ถ€
130002  ์ž„๊บฝ์ •       ์˜์—…๋ถ€
130003  ์žฅ๊ธธ์‚ฐ       ์ƒ์‚ฐ๋ถ€


์˜ค๋ผํด์—์„œ ํ…Œ์ด๋ธ”์— ์ƒˆ๋กœ์šด PRIMARY KEY๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ์ด๋ฅผ FK๋กœ ๋งŒ๋“ค์–ด์ฃผ๊ณ  ์‹ถ์—ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‹ค๊ฐ€ ๊ทธ๋งŒ ORA-02270 ์—๋Ÿฌ๋ฅผ ๋งŒ๋‚˜๊ฒŒ ๋˜์—ˆ๋‹ค.

๋งŒ๋‚˜๊ฒŒ ๋œ ์ƒํ™ฉ์€ ์ด๋ ‡๋‹ค.

 

ํ…Œ์ด๋ธ” A์™€ B๊ฐ€ ์žˆ๋‹ค.

ํ…Œ์ด๋ธ” A๋Š” a๋ผ๋Š” PK๊ฐ€ ์žˆ๊ณ  ํ…Œ์ด๋ธ” B๋Š” (a, b)๋ฅผ ๋ณตํ•ฉPK๋กœ ๊ฐ€์ง€๊ณ  ์žˆ์—ˆ๋‹ค.

์ž, ์—ฌ๊ธฐ์„œ A์™€ Bํ…Œ์ด๋ธ”์— ์ปฌ๋Ÿผc๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ๋ณตํ•ฉPK๋กœ ๋งŒ๋“ค์–ด์ฃผ๋ คํ–ˆ๋‹ค.

์ฆ‰, A์˜ PK๋Š” (a, c), ๊ทธ๋ฆฌ๊ณ  B์˜ PK๋Š” (a, b, c)๊ฐ€ ๋˜๋Š”๊ฒƒ์ด๋‹ค. ๊ทธ๋ฆฌ๊ณ  B์˜ a, c๋Š” FK๋กœ A์˜ a, c๋ฅผ ์ฐธ์กฐํ•ด์•ผํ•œ๋‹ค.

 

์ด๋ฅผ ํ•˜๊ธฐ์œ„ํ•ด์„œ ์ƒ๊ฐํ–ˆ๋˜ ์ˆœ์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค. 

 

1. ํ…Œ์ด๋ธ” A, B์˜ PK๋ฅผ DROPํ•œ๋‹ค.

2. ํ…Œ์ด๋ธ” A, B์— ์ปฌ๋Ÿผc๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

3. ํ…Œ์ด๋ธ” A์˜ PK๋กœ (a, c)๋ฅผ ์„ ์–ธํ•œ๋‹ค. 

3. ํ…Œ์ด๋ธ” B์˜ a๋ฅผ FK๋กœ ์„ ์–ธํ•˜๋ฉด์„œ A์˜ a๋ฅผ ์ฐธ์กฐํ•˜๋„๋ก ํ•œ๋‹ค.

 - alter table B add foreign key (a) references A(a);

4. ํ…Œ์ด๋ธ” B์˜ c๋ฅผ FK๋กœ ์„ ์–ธํ•˜๋ฉด์„œ A์˜ c๋ฅผ ์ฐธ์กฐํ•˜๋„๋ก ํ•œ๋‹ค.

 - alter table B add foreign key (c) references A(c);

5. ํ…Œ์ด๋ธ” B์˜ PK๋กœ (a, b, c)๋ฅผ ์„ ์–ธํ•œ๋‹ค.

 

ํ•˜์ง€๋งŒ 3๋ฒˆ์—์„œ 02270 ์—๋Ÿฌ๋ฅผ ๋งŒ๋‚˜๊ฒŒ ๋˜์—ˆ๋‹ค.

์ด ์—๋Ÿฌ๋Š” UNIQUE KEY๋‚˜ PK๊ฐ€ ์•„๋‹Œ๊ฒƒ์„ ์ฐธ์กฐํ•˜๋ ค๊ณ  ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ์ด๋‹ค.

๊ทธ๋ž˜์„œ ์ƒ๊ฐํ•ด๋ณด๋‹ˆ ํ…Œ์ด๋ธ” A์˜ PK๋Š” a๋‚˜ c๊ฐ€ ์•„๋‹Œ (a, c)์ธ ๊ฒƒ์ด๋‹ค.

ํ•˜์—ฌ 3, 4๋ฒˆ ๊ณผ์ •์„ ๋ฌถ์–ด์„œ ํ…Œ์ด๋ธ” B์˜ FK๋กœ B์˜ (a, c)๊ฐ€ A์˜ (a, c)๋ฅผ ์ฐธ์กฐํ•˜๋„๋ก ์„ค์ •ํ•˜์˜€๋”๋‹ˆ ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.

 - alter table B add foreign key (a, c) references A(a, c);


๐Ÿ’ป Programming/Oracle 11g

[SQL] Truncate vs Drop vs Delete

DELETE

The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed. After performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. Note that this operation will cause all DELETE triggers on the table to fire.

 

TRUNCATE

TRUNCATE removes all rows from a table. The operation cannot be rolled back and no triggers will be fired. As such, TRUCATE is faster and doesn't use as much undo space as a DELETE.

 

DROP

The DROP command removes a table from the database. All the tables' rows, indexes and privileges will also be removed. No DML triggers will be fired. The operation cannot be rolled back.  

 

 

* DROP and TRUNCATE are DDL commands, whereas DELETE is a DML command. Therefore DELETE operations can be rolled back (undone), while DROP and TRUNCATE operations cannot be rolled back.


ALTER TABLE [DB๋ช…] MODIFY([์ปฌ๋Ÿผ๋ช…] NOT NULL);

 

๊ฐ„๋‹จํ•˜๋‹ค!!!!!!!!!!

 

ํ™”์ดํŒ…!!! 


์˜ค๋ผํด์—์„œ ํ•œ๋ฒˆ์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ ˆ์ฝ”๋“œ๋ฅผ insertํ•˜๋ ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

INSERT ALL
INTO ํ…Œ์ด๋ธ”๋ช… ( column_1, column_2 ) VALUES ( value_1,  value_2)

INTO ํ…Œ์ด๋ธ”๋ช… ( column_1, column_2 ) VALUES ( value_3,  value_4)

SELECT 1 FROM DUAL


๐Ÿ’ป Programming/Oracle 11g

[SQL] COUNT(*) ์™€ COUNT(1)

SQL์—์„œ ํŠน์ • ๋ฐ์ดํƒ€์˜ ๊ฐœ์ˆ˜๋ฅผ ๋ฝ‘์•„๋‚ผ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” COUNT()ํ•จ์ˆ˜๊ฐ€ ์žˆ๋‹ค.

๋ญ ๋ฐ์ดํ„ฐ์˜ ์–‘์ด ์ ์€ ๊ฒฝ์šฐ์—๋Š” ์†๋„์ฐจ์ด๋ฅผ ๋Š๋ผ์ง€ ๋ชปํ•˜๊ฒ ์ง€๋งŒ ๋ฐ์ดํ„ฐ์˜ ์–‘์ด ๋งŽ์€ DB๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ์–ด๋–จ๊นŒ...????ํ•˜๋Š” ์˜๋ฌธ์ด ์ƒ๊ธด๋‹ค.

 

์•„์ง ํ™•์‹คํ•œ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ณด์ง€๋Š” ์•Š์•˜๋‹ค. ๊ทธ์ € ์ธํ„ฐ๋„ท์—์„œ ์ฐพ์€ ์ •๋ณด์— ์˜ํ•˜๋ฉด....

 

์˜์–ด์— ์•ฝํ•œ๋ถ„๋“ค์€ Example๋ถ€๋ถ„์€ ๊ทธ๋ƒฅ ๊ฑด๋„ˆ๋›ฐ๊ณ  Tip: Performance......๋ถ€๋ถ„์„ ๋ณด๋ฉด๋œ๋‹ค. 

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

Example - Using SQL GROUP BY Clause

In some cases, you will be required to use the SQL GROUP BY clause with the SQL COUNT function.

For example, you could use the SQL COUNT function to return the name of the department and the number of employees (in the associated department) that make over $25,000 / year.

SELECT department, COUNT(*) AS "Number of employees"
FROM employees
WHERE salary > 25000
GROUP BY department;

Because you have listed one column in your SQL SELECT statement that is not encapsulated in the SQL COUNT function, you must use the SQL GROUP BY clause. The department field must, therefore, be listed in the GROUP BY section.

TIP: Performance Tuning with SQL COUNT

Since the SQL COUNT function will return the same results regardless of what NOT NULL field(s) you include as the SQL COUNT function parameters (ie: within the brackets), you can change the syntax of the SQL COUNT function to COUNT(1) to get better performance as the database engine will not have to fetch back the data fields.

For example, based on the example above, the following syntax would result in better performance:

SELECT department, COUNT(1) AS "Number of employees"
FROM employees
WHERE salary > 25000
GROUP BY department;

Now, the SQL COUNT function does not need to retrieve all fields from the employees table as it had to when you used the COUNT(*) syntax. It will merely retrieve the numeric value of 1 for each record that meets your criteria.

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

 

 

 

์ถœ์ฒ˜ :Http://www.techonthenet.com/sql/count.php


java.lang.SecurityException: Sealing violation exception (ID 6554602)

Description

Starting with JDBC 10.2 drivers, having more than one JDBC jar file in the CLASSPATH may result in a java.lang.SecurityException: Sealing violation exception.

Detailed explanation from Oracle is documented in the following Oracle Document ID:

Note:405446.1
Subject: JDBC Driver 10.2 Uses Sealed JAR files and May Cause SecurityException Sealing Violation

Solution

(Suggested by Oracle) Make sure that the CLASSPATH includes only one JDBC driver JAR file.

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


๐Ÿ’ป Programming/Oracle 11g

[SQL] CONNECT BY , START WITH

๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง„ ๋ฐ์ดํƒ€๋ฅผ ๋ฝ‘์•„๋ณด์ž!!!!

ํ•œ ํ…Œ์ด๋ธ” Table_1์ด ์žˆ๋‹ค.

์ด ํ…Œ์ด๋ธ”์€ objectIDํ•„๋“œ์™€ parentObjectID ํ•„๋“œ๋ฅผ ๊ฐ–๊ณ  ์žˆ๋‹ค.

๋‘ ํ•„๋“œ์—๋Š” OBJECT_X(X๋Š” ์ •์ˆ˜ํ˜• ์ˆซ์ž)ํ˜•์‹์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด์žˆ๋‹ค. 

๋˜, OBJECT_1์ด ํ•˜์œ„ OBJECT_2๋ฅผ ๊ฐ€์ง€๊ณ  OBJECT_2๊ฐ€ ๋˜ ํ•˜์œ„ OBJECT_3์„ ๊ฐ€์ง„๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์ž. (OBJECT_2๋Š” OBJECT_1์˜ ์ž์‹ OBJECT๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด๋œ๋‹ค.)

์—ฌ๋Ÿฌ ๋‹ค๋ฅธ OBJECT_X ํ˜•์‹์˜ ๋ฐ์ดํ„ฐ๋“ค์ด ํ…Œ์ด๋ธ” ๋‚ด์— ๋งŽ์ด ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์ž.

 

์ด๋•Œ CONNECT BY์™€ START WITH๋ฅผ ์ด์šฉํ•˜์—ฌ OBJECT_2์™€ ๊ทธ ์ƒ์œ„, ๋˜ ๊ทธ ์ƒ์œ„, ๋˜ ๊ทธ ์ƒ์œ„...์ญˆ์šฐ์šฑ ํ•ด์„œ OBJECT_2๋ฅผ ๊ฐ–๋Š” ์ตœ์ƒ์œ„ OBJECT๊นŒ์ง€ ๊ณ„์ธต๊ตฌ์กฐ๋กœ ๋ฝ‘์•„๋‚ด๊ธฐ ์œ„ํ•ด์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ํ•˜๋ฉด ๋œ๋‹ค.

 

SELECT *

FROM Table_1

CONNECT BY PRIOR objectID = parentObjectID

START WITH objectID = 'OBJECT_2'

 

------- 

 ํŒŒ๋ž€์ƒ‰ ์กฐ๊ฑด๋ถ€์˜ ์ˆœ์„œ๊ฐ€ ๋ฐ”๋€Œ๋ฉด ๊ฒฐ๊ณผ๋„ ๋ฐ”๋€Œ๋ฏ€๋กœ ์ฃผ์˜ํ•˜์ž.!!!!


SQL ์ฟผ๋ฆฌ์—์„œ ๊ฒฐ๊ณผ๋กœ ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋‚˜์™”์„ ๋•Œ ์ด ๋ฆฌ์ŠคํŠธ๋“ค์„ ํ•œ์ค„(1 row)๋กœ ํ•ฉ์ณ์„œ ๋ณด์—ฌ์ฃผ๊ณ  ์‹ถ๋‹ค๋ฉด!!!!!

LISTAGG๋ฅผ ์‚ฌ์šฉํ•˜์ž!! 

SELECT LISTAGG(last_name, '; ')
         WITHIN GROUP (ORDER BY hire_date, last_name) "Emp_list",
       MIN(hire_date) "Earliest"
  FROM employees
  WHERE department_id = 30;

Emp_list                                                     Earliest
------------------------------------------------------------ ---------
Raphaely; Khoo; Tobias; Baida; Himuro; Colmenares            07-DEC-02


SQL join์„ ํ•  ๊ฒฝ์šฐ ์–ด๋– ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ฌ์ง€ ์˜ˆ์ƒ์„ ํ•˜๊ณ ์„œ ์ฟผ๋ฆฌ๋ฌธ์„ ์ž‘์„ฑ์„ ํ•ด์•ผํ•œ๋‹ค.

join์˜ ์ข…๋ฅ˜๊ฐ€ ๋งŽ๊ธฐ ๋•Œ๋ฌธ์— ์ดํ•ดํ•˜๊ธฐ๊ฐ€ ํž˜๋“  ๋ถ„๋“ค์„ ์œ„ํ•ด์„œ ์ธํ„ฐ๋„ท์— ๋Œ์•„๋‹ค๋‹ˆ๋Š” ์‚ฌ์ง„์„ ํ•˜๋‚˜ ์ฒจ๋ถ€ํ•ด๋ณด์•˜๋‹ค. ๋‘ ํ…Œ์ด๋ธ”์„ ์กฐ์ธํ–ˆ์„ ๋•Œ ์–ด๋– ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ๊ทธ๋ฆผ์œผ๋กœ ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•ด๋†“์€ ์‚ฌ์ง„์ด๋‹ค.

 

 


ORA-00031: session marked for kill

์•„๋ž˜ ๋งํฌ๋กœ ๊ฐ€๋ณด์ž.

Check the link below.



https://blog.tanelpoder.com/2009/08/13/alter-system-kill-session-and-ora-00031-session-marked-for-kill/ 


๊ฐ„๋‹จํžˆ ๋งํ•˜์ž๋ฉด ๋™์  ์ฟผ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ์‹œ์— ์กฐ๊ฑด๋ฌธ์„ ์ค„์ด๊ธฐ ์œ„ํ•ด์„œ์ด๋‹ค.

select * from table1; ์ด๋ผ๋Š” ์ฟผ๋ฆฌ์™€ select * from table1 where 1=1;์ด๋ผ๋Š” ์ฟผ๋ฆฌ์˜ ๊ฒฐ๊ณผ๋Š” ๋™์ผํ•˜๋‹ค.

ํ•˜์ง€๋งŒ ๋™์  ์ฟผ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์กฐ๊ฑด์ ˆ์— ๋˜๋‹ค๋ฅธ ์กฐ๊ฑด์€ ์ค˜์•ผํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ํ›„์ž๊ฐ€ ๋” ์ข‹๋‹ค.

์™œ???

์ฒซ๋ฒˆ์งธ ์ฟผ๋ฆฌ์— ์กฐ๊ฑด์„ ๋”ํ•˜๋ ค๋ฉด ์šฐ์„  where๊ฐ€ ์žˆ๋Š”์ง€๋ฅผ ๊ฒ€์‚ฌ๋ฅผ ํ•ด์ฃผ๊ณ  ์กฐ๊ฑด์„ ๋”ํ•ด์ฃผ์–ด์•ผ ํ•˜์ง€๋งŒ

๋‘๋ฒˆ์งธ ์ฟผ๋ฆฌ์— ์กฐ๊ฑด์„ ๋”ํ• ๋•Œ๋Š” ๋ฌด์กฐ๊ฑด and๋กœ ์‹œ์ž‘ํ•˜๋Š” ์กฐ๊ฑด์„ ๋„ฃ์–ด์ฃผ๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

 

์˜ˆ๋ฅผ๋“ค์–ด location='Seoul'์ด๋ผ๋Š” ์กฐ๊ฑด์„ ๋ง๋ถ™์—ฌ ์ค˜์•ผํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์ž.

์ฒซ๋ฒˆ์งธ ์ฟผ๋ฆฌ์— ์ € ์กฐ๊ฑด์„ ๋ถ™์ด๋ ค๋ฉด ์šฐ์„  if๋ฌธ์„ ์จ์„œ ์ฟผ๋ฆฌ์— where์ ˆ์ด ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌ๋ฅผ ํ•ด์ค˜์•ผ ํ•˜์ง€๋งŒ

๋‘๋ฒˆ์งธ ์ฟผ๋ฆฌ์— ๋ถ™์ด๋ ค๋ฉด ๊ทธ๋ƒฅ sql += "and location=\'Seoul\'" ์ด๋Ÿฐ์‹์œผ๋กœ ์“ฐ๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. 


00984. 00000 -  "column not allowed here"

 

๋ฌธ์ œ๊ฐ€ ๋œ SQL๋ฌธ 

insert into tablename(field1, FIELD2, FIELD3, FIELD4, FIELD5) values("a","b","c","d",null);

 

ํ•ด๊ฒฐํ•œ SQL๋ฌธ 

insert into tablename(field1, FIELD2, FIELD3, FIELD4, FIELD5) values('a','b','c','d',null);

 

varchar2 ํƒ€์ž…์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐ€์•ผ ํ•  ์ž๋ฆฌ์— ์ŠคํŠธ๋ง์„ ๋„ฃ์–ด์ค€๋‹ค๊ณ  ๋”๋ธ” quotation mark๋ฅผ ์ผ๋‹ค๊ฐ€ ์ €๋Ÿฐ ์—๋Ÿฌ๋ฅผ ๋ณด์•˜๋‹ค. ๊ฐ„๋‹จํžˆ ์‹ฑ๊ธ€ quotation mark๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด ๋ฌธ์ œ ํ•ด๊ฒฐ!!! 


์•„๋ž˜ ๋‚ด์šฉ์€ ํƒ€ ๋ธ”๋กœ๊ทธ์—์„œ ํผ์˜จ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ €๋Š” CentOS 6.4 / Oracle 11g์— ์ ์šฉํ•ด๋ดค๋Š”๋ฐ ์•„๋ฌด ๋ฌธ์ œ์—†์ด ์ž˜ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.



ํ™˜๊ฒฝ
Cent OS 5.5 / Oracle 10g

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

1. ์บ๋ฆญํ„ฐ์…‹ ํ™•์ธ 

SELECT * FROM sys.props$ where name='NLS_CHARACTERSET';


2. ํ”„๋กœํŒŒ์ผ ์ˆ˜์ •

export NLS_LANG=KOREAN_KOREA.UTF-8 
export NLS_LANG=KOREAN_KOREA.KO16MSWIN949 



3. ์บ๋ฆญํ„ฐ์…‹ ๋ณ€๊ฒฝ

C:\>sqlplus /nolog; 
sql>conn /as sysdba; 

 

๋ณ€๊ฒฝํ•˜๊ณ ์žํ•˜๋Š” ์บ๋ฆญํ„ฐ์…‹์„ ์ˆ˜์ •

== UTF-8 == 
sql> update sys.props$ set value$='UTF8' where name='NLS_CHARACTERSET'; 
sql> update sys.props$ set value$='UTF8' where name='NLS_NCHAR_CHARACTERSET'; 
sql> update sys.props$ set value$='KOREAN_KOREA.UTF8' where name='NLS_LANGUAGE'; 

= KO16MSWIN949 = //ํ•œ๊ธ€ํ™•์žฅ 
sql> update sys.props$ set value$='KO16MSWIN949' where name='NLS_CHARACTERSET'; 
sql> update sys.props$ set value$='KO16MSWIN949' where name='NLS_NCHAR_CHARACTERSET'; 
sql> update sys.props$ set value$='KOREAN_KOREA.KO16MSWIN949' where name='NLS_LANGUAGE'; 
sql> commit; 

 

 

์žฌ์‹œ์ž‘

sql> shutdown immediate; 
sql> startup mount; 
sql> alter system enable restricted session; 
sql> alter system set job_queue_processes=0; 
sql> alter system set aq_tm_processes=0; 
sql> alter database open; 
sql> alter database character set UTF8; 
or alter database character set KO16MSWIN949; 
sql> shutdown immediate; 
sql> startup; 







์ถœ์ฒ˜ : http://algina.tistory.com/41

์ถœ์ฒ˜ : http://www.techonthenet.com/oracle/functions/dump.php


Oracle/PLSQL: DUMP Function

This Oracle tutorial explains how to use the Oracle/PLSQL DUMP function with syntax and examples.

Description

The Oracle/PLSQL DUMP function returns a varchar2 value that includes the datatype code, the length in bytes, and the internal representation of the expression.

Syntax

The syntax for the Oracle/PLSQL DUMP function is:

DUMP( expression, [return_format], [start_position], [length] )

Parameters or Arguments

expression is the expression to analyze.

return_format is optional. It determines the format of the return value. This parameter can be any of the following values:

ValueExplanation
8octal notation
10decimal notation
16hexadecimal notation
17single characters
1008octal notation with the character set name
1010decimal notation with the character set name
1016hexadecimal notation with the character set name
1017single characters with the character set name

start_position and length are optional parameters. They determines which portion of the internal representation to display. If these parameters are omitted, the DUMP function will display the entire internal representation in decimal notation.

Applies To

The DUMP function can be used in the following versions of Oracle/PLSQL:

  • Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Example

Let's look at some Oracle DUMP function examples and explore how to use the DUMP function in Oracle/PLSQL.

For example:

DUMP('Tech')
Result: 'Typ=96 Len=4: 84,101,99,104'

DUMP('Tech', 10)
Result: 'Typ=96 Len=4: 84,101,99,104'

DUMP('Tech', 16)
Result: 'Typ=96 Len=4: 54,65,63,68'

DUMP('Tech', 1016)
Result: 'Typ=96 Len=4 CharacterSet=US7ASCII: 54,65,63,68'

DUMP('Tech', 1017)
Result: 'Typ=96 Len=4 CharacterSet=US7ASCII: T,e,c,h'


์ตœ๊ทผ์— ์•Œ๊ฒŒ๋œ ์ง€์‹์„ ๊ณต์œ ํ•˜๊ณ ์ž ํฌ์ŠคํŒ…์„ ๋‚จ๊น๋‹ˆ๋‹ค.


์•„๋ž˜ ๊ทธ๋ฆผ์ฒ˜๋Ÿผ EUC-KR(MSWIN949)๋กœ ์ธ์ฝ”๋”ฉ์„ค์ •์ด ๋˜์–ด์žˆ๋Š” DB์— varcharํƒ€์ž…์˜ ์ปฌ๋Ÿผ์— ํ•œ๊ธ€์„ ๋„ฃ์–ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค.

select dump()๋ฅผ ์ด์šฉํ•ด์„œ ๋“ค์–ด๊ฐ€์žˆ๋Š” ๋ฐ์ดํƒ€๋ฅผ ํ—ฅ์‚ฌ๊ฐ’์œผ๋กœ ์ถœ๋ ฅํ•ด๋ณด๋ฉด 2๋ฐ”์ดํŠธ์งœ๋ฆฌ๋กœ ํ•œ๊ธ€์ด ์ž˜ ๋“ค์–ด๊ฐ€์žˆ์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ ์ž๋ฐ” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ด ๊ฐ’์„ Resultset.getBytes()๋กœ ์ฝ์–ด์™€์„œ ์ถœ๋ ฅํ•ด๋ณด๋‹ˆ 3๋ฐ”์ดํŠธ UTF-8 ์ธ์ฝ”๋”ฉ์œผ๋กœ ๋ณ€ํ™˜์ด ๋˜์–ด์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.



 


euc-kr ๋ฐ”์ดํŠธ๋ฅผ ์ฝ์–ด์™€์„œ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด ๊ฒƒ์ธ๋ฐ์š”.


์˜ค๋ผํด ๋ฌธ์„œ๋ฅผ ์ฐพ์•„๋ดค๋”๋‹ˆ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ถ€๋ถ„์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.


How JDBC Drivers Perform Globalization Support Conversions

The techniques that the Oracle JDBC drivers use to perform character set conversion for Java applications depend on the character set the database uses. The simplest case is where the database uses the US7ASCII or WE8ISO8859P1 character set. In this case, the driver converts the data directly from the database character set to UTF-16, which is used in Java applications, and vice versa.

If you are working with databases that employ a non-US7ASCII or non-WE8ISO8859P1 character set (for example, JA16SJIS or KO16KSC5601), then the driver converts the data first to UTF-8 (this step does not apply to the server-side internal driver), then to UTF-16. For example, the driver always converts CHAR and VARCHAR2 data in a non-US7ASCII, non-WE8ISO8859P1 character set. It does not convert RAW data.


Note:

The JDBC drivers perform all character set conversions transparently. No user intervention is necessary for the conversions to occur.

 


 


์˜ค๋ผํด ๋“œ๋ผ์ด๋ฒ„๊ฐ€ ํ•œ๊ธ€์„ ๊ธฐ๋ณธ์ ์œผ๋กœ utf-8 ๋ฐ์ดํƒ€๋กœ ๋ณ€ํ™˜์„ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ์ž๋ฐ” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ฝ์–ด๋“ค์ผ ๋•Œ Resulset.getBytes()๋กœ ์ฝ์–ด์˜ค๋ฉด utf-8๋กœ ์ธ์ฝ”๋”ฉ๋œ ๋ฐ์ดํƒ€๊ฐ€ ๋‚˜์˜ค๊ฒŒ ๋˜๋Š” ๊ฒƒ์ด์ฃ .


๊ทธ๋ž˜์„œ getBytes()ํ•˜๋Š” ๊ฒƒ์„ getString()์œผ๋กœ ๋ฐ”๊พธ๊ณ  String.getBytes(encoding) ์œผ๋กœ bytes๋ฅผ ์ฝ์–ด์˜ค๋„๋ก ๋ฐ”๊ฟ”์„œ ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.






Reference : http://docs.oracle.com/cd/B10500_01/java.920/a96654/advanc.htm