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

๊ธฐ๋ณธ์ ์œผ๋กœ ์˜ค๋ผํด์—๋Š” ํŠน์ˆ˜๊ธฐํ˜ธ์— ๋Œ€ํ•ด์„œ ๊ฒ€์‚ฌ๋ฅผ ํ•˜๊ณ  ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋„๋ก ์ •์˜๋ฅผ ํ•ด๋†“์€ ๊ฒƒ์ด ์žˆ๋Š”๋ฐ ์ด ์ค‘์— ํŠน์ˆ˜๊ธฐํ˜ธ '&'๋„ ํฌํ•จ์ด ๋˜์–ด์žˆ๋‹ค. 


๋”ฐ๋ผ์„œ insert into table1 values ( 'a & b'); ๋ผ๋Š” ๋ฌธ์žฅ์„ ์‹คํ–‰ํ•˜๋ฉด SQLDeveloper์—์„œ๋Š” ๋Œ€์ฒด๋ฌธ์ž๋ฅผ ์„ค์ •ํ•˜๋ผ๊ณ  ํŒ์—…์ฐฝ์ด ๋œฌ๋‹ค.


์ฒ˜์Œ์—๋Š” ์ด๊ฒŒ ๋ญ์ง€? ํ•˜๊ณ ์„œ ๊ทธ๋ƒฅ ์—”ํ„ฐ๋ฅผ ์ณค์—ˆ๋Š”๋ฐ ๋‚˜์ค‘์— ๋ณด๋‹ˆ ๊ทธ๋ ‡๊ฒŒ ์—”ํ„ฐ์ณค๋˜ ๊ฒƒ ๋•Œ๋ฌธ์— insertํ•  ๋•Œ &๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๋ฐ”๋€Œ์–ด์ ธ์„œ ๋‚ด์šฉ์ด ๋“ค์–ด๊ฐ€์žˆ์—ˆ๋‹ค.


๊ทธ๋Ÿฐ๋ฐ ์ด๋ ‡๊ฒŒ ํŠน์ˆ˜๊ธฐํ˜ธ๊ฐ€ ๋“ค์–ด๊ฐ„ ๋ฌธ์žฅ์„ ์ˆ˜ ๋ฐฑ๊ฐœ insertํ•ด์•ผ ํ•œ๋‹ค๋ฉด....???


์ผ์ผํžˆ ๋‹ค ๋Œ€์ฒด๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜๊ฐ€ ์—†๋‹ค!!!


์ด๋Ÿด ๋•Œ ์œ ์šฉํ•˜๊ฒŒ ์“ธ ์ˆ˜ ์žˆ๋Š”๊ฒŒ


SQL> set define off;


์ด๋‹ค.


์œ„ ๋ช…๋ น์–ด๋Š” ํ˜„์žฌ ์„ธ์…˜์— ๋Œ€ํ•ด์„œ "ํŠน์ˆ˜๊ธฐํ˜ธ ๋Œ€์ฒด ๊ฒ€์‚ฌ"๋ฅผ ํ•˜์ง€ ์•Š๋„๋ก ํ•ด์ค€๋‹ค. 

How to increase the number of processes at database level in Oracle?

 


1.  Log on to the database as system administrator

  •  In SQL Plus enter: "connect / as sysdba"

2. Set the number of processes to be desired value <num_processes>

  • In SQL Plus "alter system set processes=<num_processes> scope=spfile"

3. Shutdown the database

  • In SQL Plus "shutdown immediate"


4. Startup the database 

  • In SQL Plus "startup"


5. Check the changes have taken effect.

  • In SQL Plus "show parameter sessions" and "show parameter processes"






โ€‹์ถœ์ฒ˜ : http://knowledgebase.progress.com/articles/Article/P164971

 

CentOS 6์— ์˜ค๋ผํด 11g ์„ค์น˜์‹œ์— ์„ค์ •ํ•ด์ฃผ๋Š” ์ปค๋„ ํŒŒ๋ผ๋ฏธํ„ฐ ์˜๋ฏธ


ใ…‡ ์ปค๋„ ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •

/etc/sysctl.conf ํŒŒ์ผ

fs.aio-max-nr = 1048576
fs.file-max = 6815744
#kernel.shmall = 2097152
#kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

์•„๋ž˜ ๋งํฌ๋ฅผ ์ฐธ์กฐํ•˜์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.


https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html-single/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/#sect-Oracle_9i_and_10g_Tuning_Guide-Setting_Semaphores-Setting_Semaphore_Parameters


https://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#BHCCADGD



select 

owner, segment_name, segment_type, sum(bytes)/1024/1024 as MB

from 

dba_segments

where

owner='{username in uppercase}' 

group by owner, segment_name, segment_type order by MB

๐Ÿ’ป Programming/Oracle 11g

ORA-01157: cannot identify/lock data file

ORA-01157: cannot identify/lock data file

๋ฐ์ดํƒ€ ํŒŒ์ผ์„ ์‹ค์ˆ˜๋กœ ์‚ญ์ œํ•ด๋ฒ„๋ ธ๋‹ค๊ฐ€ DB์žฌ์‹œ์ž‘ํ•˜๊ฒŒ๋˜๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋œ๋‹ค.

๋‚ด๊ฐ€ ์•„๋‹Œ ๋ˆ„๊ตฐ๊ฐ€๊ฐ€ dbf์ƒ์„ฑํ–ˆ๋‹ค๊ฐ€ drop๋ช…๋ น์„ ์“ฐ์ง€์•Š๊ณ  unix ์ฝ˜์†”์—์„œ dbfํŒŒ์ผ์„ ์‚ญ์ œํ•˜๊ฒŒ ๋˜๋ฉด ๋ฐœ์ƒํ•˜๊ฒŒ๋˜๋Š” ์˜ค๋ฅ˜์ธ๋ฐ ์ƒ๊ฐ๋ณด๋‹ค ์‰ฝ๊ฒŒ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



ERROR at line 1:
ORA-01157: cannot identify/lock data file 29 - see DBWR trace file
ORA-01110: data file 29:
'/opt/oracle/product/oracle9i/dbs/C:oracleproduct10.2.0oradatapentahoptho_ts.dbf
'

from above datafile name you have realized that its a kinda jerk :s someone has made a datafile with no sense and then he/she have removed the file by O.S command, but he/she did'nt updated database about it !

So during the test when we were starting this database it came untill mount stage and then got stuck !!! i.e.

Problem:

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 29 - see DBWR trace file
ORA-01110: data file 29:
'/opt/oracle/product/oracle9i/dbs/C:oracleproduct10.2.0oradatapentahoptho_ts.dbf
'

so to fix it, i did following:

Solution:


SQL>alter database datafile 29 OFFLINE DROP;
SQL>alter database open;


์ถœ์ฒ˜ : http://nayyares.blogspot.kr/2009/08/ora-01157-cannot-identifylock-data-file.html


์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ด์œ ๋กœ ํ…Œ์ด๋ธ”์„ ์‚ญ์ œํ•  ์ƒํ™ฉ์ด ์žˆ๋‹ค.

Drop table๋กœ ํ•˜๋‚˜ํ•˜๋‚˜ ์ง€์šฐ๊ธฐ์— ๋„ˆ๋ฌด ์–‘์ด ๋งŽ์„๋•Œ ํ…Œ์ด๋ธ” ์ „์ฒด๋ฅผ ํ•œ๋ฒˆ์— ์‚ญ์ œํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

๊ทธ ๋ฐฉ๋ฒ•์„ ์•„๋ž˜์— ์†Œ๊ฐœํ•˜๊ฒ ๋‹ค.

 

๋จผ์ € sql์— ์ ‘์†ํ•œ ํ›„

 

SQL> Begin

2    for c in (select table_name from user_tables) loop

3    execute immediate ('drop table '||c.table_name||' cascade constraints');

4    end loop;

5    End;

6    . <- ์ฉœ ์ฐ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์—”ํ„ฐ

 

์ด๋ ‡๊ฒŒ ์ž…๋ ฅํ•˜๋ฉด

 

SQL>

 

๋‹ค์‹œ ์ด๋ ‡๊ฒŒ ์•„๋ฌด๊ฒƒ๋„ ์•ˆ๋œจ๋Š” ๋ช…๋ น์–ด๊ฐ€ ๋œฌ๋‹ค.

 

SQL> run

์„ ์‹คํ–‰ํ•œ๋‹ค.

์‹คํ–‰ํ•˜๋ฉด ์•„๋ž˜ ๊ตฌ๋ฌธ์ด ๋‚˜์˜ฌ๊ฒƒ์ด๋‹ค.

 

1    Begin

 

2    for c in (select table_name from user_tables) loop

3    execute immediate ('drop table '||c.table_name||' cascade constraints');

4    end loop;

5    End;

PL/SQL procedure successfully completed.<--๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜ค๋ฉด ์„ฑ๊ณต

 

๊ทธ ํ›„์—

SQL> purge recyclebin; 

Recyclebin purged.<===ํœด์ง€ํ†ต์ด ๋น„์›Œ์กŒ๋‹ค๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๋‚˜์˜จ๋‹ค.

 

๊ทธํ›„ select * from tab;์„ ํ•ด๋ณด๋ฉด ๊นจ๋—ํžˆ ์ง€์›Œ์ง„ ํ…Œ์ด๋ธ”์„ ๋ณผ ์ˆ˜ ์žˆ์„๊ฒƒ์ด๋‹ค.




์ถœ์ฒ˜ : http://munjee.tistory.com/16

์ผ๋ฐ˜ ์‚ฌ์šฉ์ž ๊ณ„์ •์œผ๋กœ ์ œ์•ฝ์‚ฌํ•ญ ๋ชฉ๋ก์„ ์กฐํšŒํ•˜๋ ค๋ฉด ์•„๋ž˜ ์ฟผ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.


select * from user_constraints;



์—ฌ๋Ÿฌ๊ฐœ์˜ ํ…Œ์ด๋ธ”์„ ํ•œ๊บผ๋ฒˆ์— ์‚ญ์ œํ•˜๊ณ  ์‹ถ์€๋ฐ like ์กฐ๊ฑด์ ˆ์„ ์“ธ ์ˆ˜๊ฐ€ ์—†๋‹ค.

๋ญ ๊ฒฐ๊ตญ ํ…Œ์ด๋ธ” ํ•˜๋‚˜ํ•˜๋‚˜๋ฅผ ๊ฐ๊ฐ ์‚ญ์ œํ•ด์ค˜์•ผ ํ•œ๋‹ค๋Š” ๊ฑด๋ฐ....๊ทธ๋ ‡๋‹ค๊ณ  ํ…Œ์ด๋ธ”์ด ์ˆ˜ ์‹ญ๊ฐœ๊ฐ€ ๋„˜๋Š”๋ฐ ์ด๊ฑธ ๋‹ค ์†์œผ๋กœ ํƒ€์ดํ•‘ํ•˜๊ธฐ๋ž€ ์งœ์ฆํ•˜๋Š” ์ผ์ด ์•„๋‹ ์ˆ˜ ์—†๋‹ค.


์ด๋Ÿด ๋•Œ ๋‹ค์Œ ์ฟผ๋ฆฌ๋กœ ํŠน์ • ์‚ฌ์šฉ์ž์˜ ์ „์ฒด ํ…Œ์ด๋ธ”์„ ์‚ญ์ œ ํ•  ์ˆ˜ ์žˆ๋Š” ์ฟผ๋ฆฌ๋ฅผ ์–ป์–ด์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

 

SELECT 'DROP TABLE ' || TABLE_NAME || ';' FROM ALL_TABLES WHERE OWNER = 'user1';


์กฐ๊ฑด์ ˆ์€ ๋งˆ์Œ๋Œ€๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๊ณ  ์œ„์—์„œ ์‚ฌ์šฉํ•œ ALL_TABLES๋Š” DBA๊ถŒํ•œ์ด ์žˆ์–ด์•ผ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.


๋”ฐ๋ผ์„œ ์ผ๋ฐ˜ ์‚ฌ์šฉ์ž์ด๋ฉด์„œ ์ž์‹ ์ด ์†Œ์œ ํ•œ ํ…Œ์ด๋ธ”์„ ์‚ญ์ œํ•  ๋•Œ๋Š”


ALL_TABLES ๋Œ€์‹  USER_TABLES ์—์„œ ์กฐํšŒํ•œ ํ…Œ์ด๋ธ”๋ช…์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.


SELECT 'DROP TABLE ' || TABLE_NAME || ';' FROM USER_TABLES WHERE OWNER = 'user2';


ํ…Œ์ด๋ธ”์„ ์‚ญ์ œํ•˜๋ ค๋ฉด
SQL > drop table ํ…Œ์ด๋ธ”๋ช…;

ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์‚ฌ์‹ค ์ด๊ฒŒ ๋ฌผ๋ฆฌ์ ์œผ๋กœ ๊ณต๊ฐ„์„ ๋‹ค์‹œ ๋‚ด์ฃผ๋Š” ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค.
์˜ค๋ผํด์˜ drop table๊ด€๋ จ ๋ฌธ์„œ๋ฅผ ๋ณด๋ฉด ํ…Œ์ด๋ธ”์„ dropํ•  ๋•Œ purge๋ผ๋Š” ์˜ต์…˜์„ ์ฃผ์ง€ ์•Š์œผ๋ฉด ํœด์ง€ํ†ต์œผ๋กœ ๋„ฃ๊ธฐ๋งŒ ํ•˜๊ณ  ๋ฌผ๋ฆฌ์ ์ธ ๊ณต๊ฐ„์€ ๊ทธ๋Œ€๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์œˆ๋„์šฐ์˜ ํœด์ง€ํ†ต ๊ฐœ๋…๊ณผ ๋™์ผํ•˜๋‹ค๊ณ  ๋ณด๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์˜ค๋ผํด์ด 10g์—์„œ ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•œ 'ํœด์ง€ํ†ต' ์ด๋ผ๋Š” ๊ธฐ๋Šฅ.

ํ…Œ์ด๋ธ”์„ DROP ํ•˜๋”๋ผ๋„ ์–ธ์ œ๋˜์ง€ ๋ณต์›ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฒƒ์ด๊ณ ์š”,
์œˆ๋„์šฐ์˜ ํœด์ง€ํ†ต๊ณผ ๊ฐ™๋‹ค๊ณ  ๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

ํœด์ง€ํ†ต์— ๋“ค์€ ํ…Œ์ด๋ธ”์„ ์กฐํšŒ.
SQL> show recyclebin;

 

ํœด์ง€ํ†ต์˜ ๋ชจ๋“  ๋‚ด์šฉ์ด ๋น„์›Œ์ง‘๋‹ˆ๋‹ค.
SQL> purge recyclebin;

 

์‚ญ์ œ๋œ ํ…Œ์ด๋ธ”์„ ๋˜์‚ด๋ฆฌ๊ณ  ์‹ถ๋‹ค๋ฉด
SQL> flashback table ํ…Œ์ด๋ธ”๋ช… to before drop;

 

๋งŒ์•ฝ, ํŠน์ • ํ…Œ์ด๋ธ”์„ ํœด์ง€ํ†ต์— ๋‚จ๊ธฐ์ง€ ์•Š๊ณ  ๋ชจ๋‘ ์‚ญ์ œํ•˜๋ ค๋ฉด..
SQL> drop table ํ…Œ์ด๋ธ”๋ช… purge;

 

purge๋ฌธ ์—†์ด ๊ทธ๋ƒฅ drop ํ•œ ํ›„์—๋Š”
SQL> purge table ํ…Œ์ด๋ธ”๋ช…;


instrํ•จ์ˆ˜๋Š” ์–ด๋–ค ์ŠคํŠธ๋ง์˜ ํŠน์ •์œ„์น˜์—์„œ ์‹œ์ž‘ํ•ด์„œ ํŠน์ • ์ผ€๋ฆญํ„ฐ๊ฐ€ ์œ„์น˜ํ•œ ๊ณณ๊นŒ์ง€์˜ ์œ„์น˜๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.


Java์˜ split ๋ฉ”์†Œ๋“œ์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ• ๋•Œ ์˜ค๋ผํด์˜ substrํ•จ์ˆ˜์™€ ํ•จ๊ป˜ ๊ฐ™์ด ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์ฃ .


์˜ค๋ผํด ๋ฌธ์„œ์—์„œ ์„ค๋ช…ํ•˜๋Š” instrํ•จ์ˆ˜์— ๋Œ€ํ•œ ์ •์˜ ๋ฐ ๋ฌธ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.


The INSTR functions (INSTR, INSTRB, INSTRC, INSTR2, and INSTR4) searches a string for a substring using characters and returns the position in the string that is the first character of a specified occurrence of the substring. The functions vary in how they determine the position of the substring to return.

  • INSTR calculates lengths using characters as defined by the input character set.

  • INSTRB calculates lengths using bytes.

  • INSTRC calculates lengths using Unicode complete characters.

  • INSTR2 calculates lengths using UCS2 code points.

  • INSTR4 calculates lengths using UCS4 code points.

๋ฐ˜ํ™˜๊ฐ’

A nonzero INTEGER when the search is successful or 0 (zero) when it is not.


๋ฌธ๋ฒ• 

{INSTR | INSTRB | INSTRC | INSTR2 | INSTR4} (string , substring [, position [, occurrence]])


๊ทธ๋Ÿผ ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ํ•œ๋ฒˆ ๋ณด์‹œ์ฃ .


abc.def.ghi.jkl ์ด๋ผ๋Š” ํŒจํ‚ค์ง€๋ช…์ด ์žˆ๋‹ค๊ณ  ํ•ด๋ด…์‹œ๋‹ค.


์ด ํŒจํ‚ค์ง€๋ช…์—์„œ abc.def ( ๋‘๋ฒˆ์งธ depth ๊นŒ์ง€)๋งŒ ์ถ”์ถœํ•ด๋‚ด๊ณ  ์‹ถ์€๋ฐ ๊ทธ๋Ÿฌ๋ ค๋ฉด substr์„ ์ƒ๊ฐํ•˜์‹ค ์ˆ˜๋„ ์žˆ๊ฒ ์ฃ .


select substr(packageNm, 1, 7) from ClassTable;


์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ฒฐ๊ณผ๋Š” abc.def ๊ฐ€ ๋‚˜์˜ฌ ๊ฒƒ์ž…๋‹ˆ๋‹ค.


ํ•˜์ง€๋งŒ ๋งŒ์•ฝ ํŒจํ‚ค์ง€๋ช…์ด 3๊ธ€์ž.3๊ธ€์ž ํ˜•ํƒœ๊ฐ€ ์•„๋‹ˆ๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”?


a.b.c.d.e.f ๋ผ๋Š” ํŒจํ‚ค์ง€๋ช…์„ ์œ„์ฒ˜๋Ÿผ ์ž๋ฅด๋ฉด a.b.c.d ๋ผ๊ณ  ์ž˜๋ ค์„œ ๋‚˜์˜ค๊ฒ ์ฃ ?


๋‘๋ฒˆ์งธ depth๊ฐ€ ์•„๋‹ˆ๋ผ 7๋ฒˆ์งธ๊นŒ์ง€ ์ถœ๋ ฅ์ด ๋˜๋ฒ„๋ฆฌ๊ฒ ๊ตฐ์š”.


์ด๋•Œ instr ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉ์„ ํ•ฉ๋‹ˆ๋‹ค.


select substr( packageNm, 1, instr( packageNm, '.', 1, 2) - 1 ) ) from ClassTable;


์ด๋ ‡๊ฒŒ ํ•จ์ˆ˜๋ฅผ ์จ์ค๋‹ˆ๋‹ค.


instr( packageNm, '.', 1, 2 ) ๋ผ๋Š” ๋ถ€๋ถ„์€ packageNm์ด๋ผ๋Š” ์ŠคํŠธ๋ง์„ '.' (๋งˆ์นจํ‘œ)๋กœ ๊ตฌ๋ถ„์„ ์ง“๊ณ  1๋ฒˆ์งธ ์ธ๋ฑ์Šค์—์„œ ์‹œ์ž‘ํ•ด์„œ 2๋ฒˆ์งธ ๋งˆ์นจํ‘œ๊ฐ€ ๋‚˜์˜ค๋Š” ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜์„ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ๋งˆ์นจํ‘œ๊ฐ€ ์žˆ๋Š” ์ธ๋ฑ์Šค๊ฐ€ ๋‚˜์˜ค๊ธฐ ๋•Œ๋ฌธ์— -1์„ ํ•ด์ค€ ๊ฐ’์„ substrํ•จ์ˆ˜์˜ length์— ๋„ฃ์–ด์ฃผ๋ฉด ๋‘๋ฒˆ์งธ depth๊นŒ์ง€ substrํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

### ์บ๋ฆญํ„ฐ์…‹ ๋ณ€๊ฒฝ์ „ ํ™•์ธ ์‚ฌํ•ญ :

sqlplus '/as sysdba'

sql>select instance from v$thread;

INSTANCE
----------------
ora9i


oracle\ora92\network\admin\snmp_ro.ora ๋ฅผ ๋ด๋„ ๋œ๋‹ค.
=> snmp.SID.Oracle = ORACLE




select parameter, value from nls_database_parameters where parameter like '%CHAR%';

PARAMETERVALUE
NLS_NUMERIC_CHARACTERS.,
NLS_CHARACTERSETKO16KSC5601
NLS_NCHAR_CONV_EXCPFALSE
NLS_NCHAR_CHARACTERSETUTF8


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

****  connect sys as sysdba;

NLS CHARACTERSET ๋ณ€๊ฒฝ๋ฐฉ๋ฒ• (DB REBUILD ์—†์ด)
Bulletin no : 10016

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

  ๋ฐ์ดํƒ€๋ฒ ์ด์Šค์˜  CHARACTER SET์€ ๋ฐ์ดํƒ€ ๋”•์…”๋„ˆ๋ฆฌ ํ…Œ์ด๋ธ”์ธ sys.props$์—
 ๋“ค์–ด ์žˆ๋‹ค

   SQL>desc sys.props$
   Name                                Null?                  Type
   -------------------------------  -----------------      ---------------
   NAME                               NOT NULL             VARCHAR2(30)
   VALUE$                                                  VARCHAR2(2000)
   COMMENT$                                                VARCHAR2(2000)

   SQL>column c1 format a30
   SQL>select name c1, value$ c1 from sys.props$;

   C1                              C1
   -----------------------------   ------------------------------
   DICT.BASE                        2
   NLS_LANGUAGE                     AMERICAN
   NLS_TERRITORY                    AMERICA
   NLS_CURRENCY                     $
   NLS_ISO_CURRENCY                 AMERICA
   NLS_NUMERIC_CHARACTERS           .,
   NLS_DATE_FORMAT                  DD-MON-YY
   NLS_DATE_LANGUAGE                AMERICAN
   NLS_CHARACTERSET                 US7ASCII
   NLS_SORT                         BINARY
   GLOBAL_DB_NAME                   NLSV7.WORLD
   
  ์—ฌ๊ธฐ์„œ NLS_CHARACTERSET์— ํ˜„์žฌ DB์˜ CHARACTER SET์ด ๋“ค์–ด ์žˆ๋Š”๋ฐ ์ด ๊ฐ’์„
 ๋ณ€๊ฒฝํ•˜์—ฌ DB์˜ CHARACTER SET์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” US7ASCII์—์„œ
 KO16KSC5601 ๋กœ ์˜ฎ๊ธฐ๋Š” ๊ฒฝ์šฐ๋ฅผ ์•Œ์•„๋ณด์ž.

 ์šฐ์„  ๋ฐ”๊พธ๊ณ ์ž ํ•˜๋Š” CHRACTER SET์ด ์ง€์›๋˜๋Š” ์ง€๋ฅผ ๋‹ค์Œ ๋ช…๋ น์œผ๋กœ ํ™•์ธํ•œ๋‹ค.

         select convert('a','WE8DEC','KO16MSWIN949') from dual; 

  ๋งŒ์•ฝ ์ด Select ๋ฌธ์—์„œ ORA-01482 ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ง€์ •ํ•œ CHARACTER SET์ด
 ์ง€์›๋˜์ง€ ์•Š๋Š”  ๊ฒฝ์šฐ์ด๋ฉฐ  ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š์œผ๋ฉด CHARACTER SET์„ ๋ณ€๊ฒฝํ•  ์ˆ˜
 ์žˆ๋‹ค.
 
  ์ž‘์—…์„ ํ•˜๊ธฐ์ „์—๋Š” ๋งŒ์•ฝ์„ ์œ„ํ•ด์„œ DB ์ „์ฒด๋ฅผ ๋ฐฑ์—… ๋ฐ›์•„๋‘๋„๋ก ํ•œ๋‹ค.
  CHARACTER SET ์„ ์ž˜๋ชป ๋ณ€๊ฒฝํ•˜๋ฉด DB ๋ฅผ OPEN ํ• ์ˆ˜๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
  ---------------------------------------------------------------

1.  ๋‹ค์Œ์˜ Update๋ฌธ์„ ์‹คํ–‰ํ•˜์—ฌ CHARACTER SET์„ ๋ณ€๊ฒฝํ•œ๋‹ค.

   UPDATE sys.props$
   SET value$ = 'WE8DEC'
   WHERE name = 'NLS_CHARACTERSET';

  Update ์‹œ์— NLS_CHARACTERSET์„ ์ง€์›๋˜์ง€ ์•Š๋Š” ๊ฐ’์œผ๋กœ ์ž˜๋ชป ์„ค์ •ํ•˜๊ฑฐ๋‚˜
 ์‹ค์ˆ˜๋กœ ์ฝ˜ํŠธ๋กค ๋ฌธ์ž ๊ฐ™์€ ๊ฒƒ์ด ๋“ค์–ด๊ฐ€๊ฒŒ ๋˜๋ฉด DB๊ฐ€ Shutdown ๋œ ๋‹ค์Œ์—๋Š”
 Startup ์ด ์•ˆ ๋˜๋ฏ€๋กœ Update ํ›„์— ๋‹ค์Œ ๋ช…๋ น์œผ๋กœ ํ™•์ธ์„ ํ•œ ๋‹ค์Œ์—  Commit์„
 ํ•˜๋„๋ก ํ•œ๋‹ค.

        select name, value$
        from sys.props$
        where value$ = 'KO16KSC5601';

 Select   ์ œ๋Œ€๋กœ ์ถœ๋ ฅ๋˜๋ฉด Commit ํ•˜๊ณ  Shutdown ํ–ˆ๋‹ค๊ฐ€ Startup ํ•˜๊ฒŒ ๋˜๋ฉด
 ์ƒˆ๋กœ์šด CHARACTER SET ๊ฐ’์„ ๊ฐ–๊ฒŒ ๋œ๋‹ค. SELECT๊ฐ€ ์•ˆ ๋˜๋ฉด ROLLBACKํ•˜๊ณ  UPDATE
 ๋ถ€ํ„ฐ ๋‹ค์‹œ ํ•˜๋„๋ก ํ•œ๋‹ค.

2. ํ™˜๊ฒฝ ๋ณ€์ˆ˜ NLS_LANG ์„ ๋ณ€๊ฒฝํ•œ๋‹ค.

.profile ( or .cshrc) ์—์„œ

NLS_LANG=American_America.KO16KSC5601; export NLS_LANG

or

setenv NLS_LANG American_America.KO16KSC5601






์ถœ์ฒ˜ : http://develop.sunshiny.co.kr/201



SQL ์ปค๋งจ๋“œ๋ผ์ธ์—๋‹ค๊ฐ€ 2์ค„์งœ๋ฆฌ ์ฟผ๋ฆฌ๋ฌธ์„ ํ•œ์ฐธ ์น˜๊ณ ์„œ ์‹คํ–‰ํ–ˆ๋”๋‹ˆ ์˜คํƒ€๊ฐ€ ๋‚˜์„œ ๋‹ค์‹œ ์ณ์•ผํ•œ๋‹ค๋ฉด???


OMG !!!!!!!!!!


์ด๋Ÿฐ ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•ด์„œ ์˜ค๋ผํด์€ SQL ์—๋””ํ„ฐ๋ฅผ ์ œ๊ณตํ•ด์ค€๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณตํ•ด์ฃผ๋Š”๊ฒŒ ๋ญ”์ง„ ๋ชฐ๋ผ๋„ ๋ถˆํŽธํ•˜๋‹ค.


์ข€๋” ํŽธํ•˜๊ฒŒ ํ•˜์ž๋ฉด ์šฐ๋ฆฌ๊ฐ€ ์œ ๋‹‰์Šค ํ™˜๊ฒฝ์—์„œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” vi ์—๋””ํ„ฐ๋ฅผ SQL ๊ธฐ๋ณธ ์—๋””ํ„ฐ๋กœ ์„ค์ •ํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ


์ด ๊ธฐ๋ณธ ์—๋””ํ„ฐ๋Š” _editor ๋ผ๋Š” ๋ณ€์ˆ˜์•ˆ์— ๋“ค์–ด๊ฐ€์žˆ๋‹ค.


SQL > define _editor = vi  


์œ„ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋‹ค์Œ๋ถ€ํ„ฐ๋Š” ed๋ผ๋Š” ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด์„œ ๋ฐฉ๊ธˆ ์ณค๋˜ ๋ช…๋ น์–ด๋ฅผ vi์—๋””ํ„ฐ ๋ชจ๋“œ์—์„œ ๋‹ค์‹œ ๋ณด์—ฌ์ค€๋‹ค.


์งฑ์ด๋‹ค.

DB์ž‘์—…์„ ํ•˜๋‹ค๊ฐ€๋ณด๋ฉด ๋‚ด ๊ณ„์ •์— ์–ด๋–ค ๊ถŒํ•œ์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ด์•ผํ•  ๋•Œ๊ฐ€ ์žˆ๋‹ค.

๊ถŒํ•œ์ž์ฒด๊ฐ€ ์—†์œผ๋ฉด ์ž‘์—…์ž์ฒด๊ฐ€ ์•ˆ๋  ์ˆ˜๋„ ์žˆ์œผ๋‹ˆ๊นŒ ๋ง์ด๋‹ค.

์•„๋ž˜ ์ฟผ๋ฆฌ๋ฌธ์€ ํ˜„์žฌ ์ ‘์†ํ•œ ๊ณ„์ •์˜ ๊ถŒํ•œ์„ ๋ณด์—ฌ์ค€๋‹ค.


select * from user_sys_privs;



user_sys_privs์™ธ์—๋„ ๊ถŒํ•œ๊ณผ ๊ด€๋ จ๋œ ๋‹ค์–‘ํ•œ ํ…Œ์ด๋ธ” ๋˜๋Š” ๋ทฐ(view)๋“ค์ด ์žˆ๋‹ค. ์•„๋ž˜๋Š” ๊ทธ ํ…Œ์ด๋ธ”๋“ค์˜ ๋ชฉ๋ก์ด๋‹ค.

๊ฐ ํ…Œ์ด๋ธ”๋“ค์ด ์–ด๋– ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”์ง€๋Š” ํ•œ๋ฒˆ ๋ณด๋ฉด์„œ ํ™•์ธํ•ด๋ณด๊ธธ ๋ฐ”๋ž€๋‹ค.



ALL_COL_PRIVS
ALL_COL_PRIVS_MADE
ALL_COL_PRIVS_RECD
ALL_REPGROUP_PRIVILEGES
ALL_TAB_PRIVS
ALL_TAB_PRIVS_MADE
ALL_TAB_PRIVS_RECD


USER_AQ_AGENT_PRIVS
USER_COL_PRIVS
USER_COL_PRIVS_MADE
USER_COL_PRIVS_RECD
USER_REPGROUP_PRIVILEGES

TNAME
------------------------------
USER_ROLE_PRIVS
USER_SYS_PRIVS
USER_TAB_PRIVS
USER_TAB_PRIVS_MADE
USER_TAB_PRIVS_RECD


๐Ÿ’ป Programming/Oracle 11g

[Oracle/SQL] merge into

MERGE INTO bonuses b
USING (
  SELECT employee_id, salary, dept_no
  FROM employee
  WHERE dept_no =20) e
ON (b.employee_id = e.employee_id)
WHEN MATCHED THEN
  UPDATE SET b.bonus = e.salary * 0.1
  DELETE WHERE (e.salary < 40000)
WHEN NOT MATCHED THEN
  INSERT (b.employee_id, b.bonus) VALUES (e.employee_id, e.salary * 0.05) WHERE (e.salary > 40000);



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


MERGE INTO bonuses b
USING dual e
ON (b.employee_id = ? )
WHEN MATCHED THEN
  UPDATE SET b.bonus = e.salary * 0.1
WHEN NOT MATCHED THEN
  INSERT (b.employee_id, b.bonus) VALUES (e.employee_id, e.salary * 0.05) WHERE (e.salary > 40000);


์‚ฌ์šฉ์ž๊ณ„์ •์ด SAMPLE ์ธ ์‚ฌ์šฉ์ž์˜ ๊ถŒํ•œ์„ ์กฐํšŒํ•˜๋ ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

select privilege
from dba_sys_privs
where grantee='SAMPLE'
order by 1;

Oracle 10g Character set ๋ณ€๊ฒฝ(EUC-KR์„ UTF8 ๋ณ€๊ฒฝ) :
์ฐธ๊ณ 

kor ๋ฒ„์ „์œผ๋กœ ๋ฐ›๋Š”๋‹ค๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ ์„ค์น˜๋˜๋Š” ๋ฒ„์ „์€ KO16MSWIN949 ์ผ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค.
ํ•œ๊ธ€์„ ์ง€์›ํ•˜๋Š” Character Set์„ ๋น„๊ตํ•ด๋ณด์ž.

1. KO16KSC5601
- ํ•œ๊ธ€ ์ง€์›์ƒํƒœ : ํ•œ๊ธ€ 2350์ž
- ์ง€์›๋ฒ„์ „ : 7.x
- ํ•œ๊ธ€๋ฐ”์ดํŠธ : 2๋ฐ”์ดํŠธ

2. KO16MSWIN949
- ํ•œ๊ธ€ ์ง€์›์ƒํƒœ : KO16KSC5601 + ํ™•์žฅ ( ์ด 11172์ž )
- ์ง€์›๋ฒ„์ „ : 8.0.6 ์ด์ƒ
- ํ•œ๊ธ€๋ฐ”์ดํŠธ : 2๋ฐ”์ดํŠธ

3. UTF8
- ํ•œ๊ธ€ ์ง€์›์ƒํƒœ : ํ•œ๊ธ€ 11172์ž
- ์ง€์›๋ฒ„์ „ : 8.0 ์ดํ›„
- ํ•œ๊ธ€๋ฐ”์ดํŠธ : 3๋ฐ”์ดํŠธ

4. AL32UTF8
- ํ•œ๊ธ€ ์ง€์›์ƒํƒœ : ํ•œ๊ธ€ 11172์ž
- ์ง€์›๋ฒ„์ „ : 9i Release 1 ์ด์ƒ
- ํ•œ๊ธ€๋ฐ”์ดํŠธ : 3๋ฐ”์ดํŠธ

UTF8์€ ๋งŽ์€ ๋ฌธ์ž๋ฅผ ์ง€์›ํ•˜์ง€๋งŒ ํ•œ๊ธ€์„ 3๋ฐ”์ดํŠธ ์†Œ๋ชจํ•œ๋‹ค๋Š” ๋‹จ์ ์ด ์žˆ๋‹ค.
(๋ชป๋Š๋‚„ ์ •๋„๋กœ ๋น ๋ฅธ ์ปดํ“จํ„ฐ๊ฐ€ ๋ณ„ ์ฐจ์ด๊ฐ€ ์—†์„ ๋“ฏํ•จ)
์บ๋ฆญํ„ฐ์…‹์ด ์–ด๋–ป๊ฒŒ ์„ค์ •๋˜์–ด ์žˆ๋‚˜ ํ™•์ธ ์ฟผ๋ฆฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹คใ…ฃ

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

Oracle 10g Character Set ๋ณ€๊ฒฝ
SQLPLUS ์ ‘์†ํ›„ (system ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ ํ˜น์‹œ ๋ชจ๋ฅธ๋‹ค๋ฉด sqlplus /nolog; ํ›„ conn /as sysdba; ๋กœ ์ ‘์†ํ•œ๋‹ค)

C:\>sqlplus /nolog;
sql>conn /as sysdba;
๋ณ€๊ฒฝํ•˜๊ณ ์žํ•˜๋Š” ์บ๋ฆญํ„ฐ์…‹์„ ์ˆ˜์ •

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';
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;
sql>shutdown immediate;
sql>startup;

์ถœ์ฒ˜ : http://www.garubi.com/11

ํ…Œ์ด๋ธ”์— ์–ด๋–ค ๋ฐ์ดํƒ€๋ฅผ insert, update, delete๋ฅผ ํ•  ๋•Œ๋Š” ํ•œ ๋ช…์˜ ์‚ฌ์šฉ์ž๋งŒ์ด ํ•ด๋‹น ํ…Œ์ด๋ธ”์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค€๋‹ค.


๊ทธ ๋Ÿฐ๋ฐ ๋งŒ์•ฝ Aํ…Œ์ด๋ธ”์—์„œ ๋ฐ์ดํƒ€๋ฅผ ์ฝ์–ด์™€์„œ ์ด์™€ ๊ด€๋ จ๋œ ๋‚ด์šฉ์„ Bํ…Œ์ด๋ธ”์— ๋„ฃ์œผ๋ ค๋Š”๋ฐ Bํ…Œ์ด๋ธ”์— FK๋กœ Aํ…Œ์ด๋ธ”์˜ PK๊ฐ€ ๊ฑธ๋ ค์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž. ๋‚˜๋Š” Aํ…Œ์ด๋ธ”์—์„œ pk๊ฐ€ 1์ธ ๋ฐ์ดํƒ€๋ฅผ ์ฝ์–ด์™€์„œ Bํ…Œ์ด๋ธ”์— ์—…๋ฐ์ดํŠธ๋ฅผ ํ•ด์ค˜์•ผํ•˜๋Š”๋ฐ ๋ฐ์ดํƒ€๋ฅผ ์ฝ์–ด์™€์„œ ์—…๋ฐ์ดํŠธ ํ•˜๊ธฐ ์ „์— ๋ˆ„๊ตฐ๊ฐ€๊ฐ€ ๋ฐ์ดํƒ€ 1์„ ์ง€์›Œ๋ฒ„๋ ธ๋‹ค๋ฉด?? ๋‚ด๊ฐ€ Bํ…Œ์ด๋ธ”์— ์—…๋ฐ์ดํŠธ๋ฅผ ์‹œ๋„ํ•  ๋•Œ fk ์˜ค๋ฅ˜๊ฐ€ ๋‚  ๊ฒƒ์ด๋‹ค. pk๊ฐ€ ์‚ฌ๋ผ์กŒ์œผ๋‹ˆ ๋ง์ด๋‹ค.


์ž ์ด๋Ÿด ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด select ... for update ์ด๋‹ค.

 


for update๋Š” ์ฝ์–ด์˜จ ๋ชจ๋“  rows์™€ ๊ทธ rows์™€ ๊ด€๋ จ๋œ ์ธ๋ฑ์Šค ์—”ํŠธ๋ฆฌ๊นŒ์ง€ lock์„ ํ•œ๋‹ค. ์ด๋Š” update๋ฌธ์„ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ์™€ ๋™์ผํ•œ ๊ฒƒ์ด๋‹ค. for update๋กœ ์‹คํ–‰๋œ select๋ฌธ์€ ๋‹ค๋ฅธ ๋ชจ๋“  ์—…๋ฐ์ดํŠธ ๊ด€๋ จ ์ฟผ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. ๋”ฐ๋ผ์„œ ๋˜ ๋‹ค๋ฅธ select ... for update ๋ฌธ ์—ญ์‹œ ๊ธฐ์กด ์„ธ์…˜์—์„œ commit์ด๋‚˜ rollback์ด ์‹คํ–‰๋˜๊ธฐ ์ „๊นŒ์ง€ ๊ธฐ๋‹ค๋ ธ๋‹ค๊ฐ€ ์ตœ์‹ ์ •๋ณด๋ฅผ selectํ•˜๊ฒŒ ๋œ๋‹ค.


์‚ฌ์šฉ๋ฒ•์€ ๋‹จ์ˆœํ•˜๋‹ค.


SQL > select * from emp for update;


SQL FOREIGN KEY Constraint on ALTER TABLE

- ์™ธ๋ž˜ํ‚ค ์ถ”๊ฐ€ํ•˜๊ธฐ

MySQL / SQL Server / Oracle / MS Access:

ALTER TABLE Orders
ADD FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id)


- ์™ธ๋ž˜ํ‚ค ์ด๋ฆ„ ์ง€์ •ํ•ด์ฃผ๊ธฐ

MySQL / SQL Server / Oracle / MS Access:

ALTER TABLE Orders
ADD CONSTRAINT fk_PerOrders
FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id)


To DROP a FOREIGN KEY Constraint

- ์™ธ๋ž˜ํ‚ค ์‚ญ์ œํ•˜๊ธฐ 


MySQL:

ALTER TABLE Orders
DROP FOREIGN KEY fk_PerOrders

SQL Server / Oracle / MS Access:

ALTER TABLE Orders
DROP CONSTRAINT fk_PerOrders


ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋‹ค ๋ณด๋ฉด ํ…Œ์ด๋ธ” ๋ชจ๋ธ๋ง์„ ์ˆ˜์ •ํ•ด์•ผ ํ•  ๋•Œ๊ฐ€ ์žˆ๋‹ค. ์ด๋Ÿฐ ์ €๋Ÿฐ ์ถ”๊ฐ€์š”๊ตฌ๊ฐ€ ๋“ค์–ด์˜ค๋ฉด ๋ง์ด๋‹ค.

 

๊ทธ๋Ÿด ๋•Œ๋Š” ๊ฐ„๋‹จํ•˜๊ฒŒ SQL ํ•œ๋ฌธ์žฅ์œผ๋กœ ํ›„๋”ฑ ํ•ด์น˜์›Œ ๋ฒ„๋ฆฌ๋ฉด ๋œ๋‹ค.

 

ยง ์•„๋ž˜๋Š” ํ…Œ์ด๋ธ”์— ํ•˜๋‚˜์˜ ์ปฌ๋Ÿผ์„ ์ถ”๊ฐ€๋กœ ๋งŒ๋“ค์–ด ์ฃผ๊ธฐ์œ„ํ•œ SQL๋ฌธ์ด๋‹ค.

 

ALTER TABLE table_name ADD column_name datatype

 

ยง ํ…Œ์ด๋ธ”์—์„œ ํ•„์š”์—†๋Š” ์ปฌ๋Ÿผ์„ ์‚ญ์ œํ•˜๋ ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

 

ALTER TABLE table_name DROP COLUMN column_name

ยง ๋˜ํ•œ ํŠน์ • ์ปฌ๋Ÿผ์˜ ๋ฐ์ดํƒ€ ํƒ€์ž…์„ ๋ณ€๊ฒฝํ•˜๋ ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

Oracle 10G and later: ALTER TABLE table_name MODIFY column_name datatype




ยง ์˜ค๋ผํด์ด ์•„๋‹Œ ๋‹ค๋ฅธ ๋ฐ์ดํƒ€๋ฒ ์ด์Šค ์‹œ์Šคํ…œ์˜ ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

SQL Server / MS Access:

ALTER TABLE table_name ALTER COLUMN column_name datatype

My SQL / Oracle:

ALTER TABLE table_name MODIFY COLUMN column_name datatype


๋Œ€๋Ÿ‰์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•ด์•ผํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค๋‹ค๋ณด๋ฉด ์„ฑ๋Šฅ๋ฌธ์ œ๋ฅผ ์ธ์‹ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์—†๋‹ค. JMeter๋ฅผ ์ด์šฉํ•˜์—ฌ ์›น์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํ…Œ์ŠคํŠธ ํ•˜๋ฉด์„œ ์„ฑ๋Šฅ๊ฐœ์„ ์„ ์œ„ํ•ด์„œ ์ด๊ฒƒ ์ €๊ฒƒ ํ•ด๋ณด๋‹ค๊ฐ€ ์˜ค๋ผํด์—์„œ ์ œ๊ณตํ•˜๋Š” " Insert ๋ฌธ์˜ ์†๋„ "์— ๊ด€ํ•œ ๋ฌธ์„œ๋ฅผ ๋ฐœ๊ฒฌํ•˜์˜€๋‹ค.  

 

์•„๋ž˜ ๊ทธ ๋ฌธ์„œ์˜ ๋‚ด์šฉ์ด ์žˆ์œผ๋ฉฐ insert๋ฌธ์˜ ์†๋„์™€ ๊ด€๋ จ๋œ ์‚ฌํ•ญ๋“ค ๋ฐ ์–ด๋–ป๊ฒŒ ์†๋„๋ฅผ ๋†’์ผ ์ˆ˜ ์žˆ๋Š”์ง€์— ๋Œ€ํ•˜์—ฌ ์„ค๋ช…์„ ํ•˜๊ณ  ์žˆ๋‹ค. 

์ถœ์ฒ˜ : https://docs.oracle.com/cd/E17952_01/refman-5.1-en/insert-speed.html

Speed of INSERT Statements

The time required for inserting a row is determined by the following factors, where the numbers indicate approximate proportions:

  • Connecting: (3)

  • Sending query to server: (2)

  • Parsing query: (2)

  • Inserting row: (1 ร— size of row)

  • Inserting indexes: (1 ร— number of indexes)

  • Closing: (1)

This does not take into consideration the initial overhead to open tables, which is done once for each concurrently running query.

The size of the table slows down the insertion of indexes by log N, assuming B-tree indexes.

You can use the following methods to speed up inserts:

  • If you are inserting many rows from the same client at the same time, use INSERT statements with multiple VALUES lists to insert several rows at a time. This is considerably faster (many times faster in some cases) than using separate single-row INSERT statements. If you are adding data to a nonempty table, you can tune the bulk_insert_buffer_size variable to make data insertion even faster. See Section 5.1.4, โ€œServer System Variablesโ€.

  • If multiple clients are inserting a lot of rows, you can get higher speed by using the INSERT DELAYED statement. See Section 13.2.5.2, โ€œINSERT DELAYED Syntaxโ€.

  • For a MyISAM table, you can use concurrent inserts to add rows at the same time that SELECT statements are running, if there are no deleted rows in middle of the data file. See Section 8.7.3, โ€œConcurrent Insertsโ€.

  • When loading a table from a text file, use LOAD DATA INFILE. This is usually 20 times faster than using INSERT statements. See Section 13.2.6, โ€œLOAD DATA INFILE Syntaxโ€.

  • With some extra work, it is possible to make LOAD DATA INFILE run even faster for a MyISAM table when the table has many indexes. Use the following procedure:

    1. Optionally create the table with CREATE TABLE.

    2. Execute a FLUSH TABLES statement or a mysqladmin flush-tables command.

    3. Use myisamchk --keys-used=0 -rq /path/to/db/tbl_name. This removes all use of indexes for the table.

    4. Insert data into the table with LOAD DATA INFILE. This does not update any indexes and therefore is very fast.

    5. If you intend only to read from the table in the future, use myisampack to compress it. See Section 14.5.3.3, โ€œCompressed Table Characteristicsโ€.

    6. Re-create the indexes with myisamchk -rq /path/to/db/tbl_name. This creates the index tree in memory before writing it to disk, which is much faster that updating the index during LOAD DATA INFILE because it avoids lots of disk seeks. The resulting index tree is also perfectly balanced.

    7. Execute a FLUSH TABLES statement or a mysqladmin flush-tables command.

    LOAD DATA INFILE performs the preceding optimization automatically if the MyISAM table into which you insert data is empty. The main difference between automatic optimization and using the procedure explicitly is that you can let myisamchk allocate much more temporary memory for the index creation than you might want the server to allocate for index re-creation when it executes the LOAD DATA INFILE statement.

    You can also disable or enable the nonunique indexes for a MyISAM table by using the following statements rather than myisamchk. If you use these statements, you can skip the FLUSH TABLE operations:

    ALTER TABLE tbl_name DISABLE KEYS;
    ALTER TABLE tbl_name ENABLE KEYS;
    
  • To speed up INSERT operations that are performed with multiple statements for nontransactional tables, lock your tables:

    LOCK TABLES a WRITE;
    INSERT INTO a VALUES (1,23),(2,34),(4,33);
    INSERT INTO a VALUES (8,26),(6,29);
    ...
    UNLOCK TABLES;
    

    This benefits performance because the index buffer is flushed to disk only once, after all INSERT statements have completed. Normally, there would be as many index buffer flushes as there are INSERT statements. Explicit locking statements are not needed if you can insert all rows with a single INSERT.

    To obtain faster insertions for transactional tables, you should use START TRANSACTION and COMMIT instead of LOCK TABLES.

    Locking also lowers the total time for multiple-connection tests, although the maximum wait time for individual connections might go up because they wait for locks. Suppose that five clients attempt to perform inserts simultaneously as follows:

    • Connection 1 does 1000 inserts

    • Connections 2, 3, and 4 do 1 insert

    • Connection 5 does 1000 inserts

    If you do not use locking, connections 2, 3, and 4 finish before 1 and 5. If you use locking, connections 2, 3, and 4 probably do not finish before 1 or 5, but the total time should be about 40% faster.

    INSERT, UPDATE, and DELETE operations are very fast in MySQL, but you can obtain better overall performance by adding locks around everything that does more than about five successive inserts or updates. If you do very many successive inserts, you could do a LOCK TABLES followed by an UNLOCK TABLES once in a while (each 1,000 rows or so) to permit other threads to access table. This would still result in a nice performance gain.

    INSERT is still much slower for loading data than LOAD DATA INFILE, even when using the strategies just outlined.

  • To increase performance for MyISAM tables, for both LOAD DATA INFILE and INSERT, enlarge the key cache by increasing the key_buffer_size system variable. See Section 8.9.2, โ€œTuning Server Parametersโ€.