À¯¿ëÇÑ SQL scripts
ÀÛ¼ºÀÚ °ü¸®ÀÚ ÀÛ¼º½Ã°£ 2006-03-07 16:36:26
 

[b][color=BLUE]Å×À̺íÀÌ »ç¿ëÁßÀÎ ºí·Ï Å©±â¸¦ °è»êÇØÁÖ´Â SQL[/color][/b]

/*
**  TableÀÌ »ç¿ëÇÏ´Â ºí·° Å©±â¸¦ ±¸ÇÏ´Â ½ºÅ©¸³Æ®...  <<¹ÚÁ¦¿ë>>
**
**  »ç¿ë¹ý : 1) DBA ±ÇÇÑÀ¸·Î ·Î±×ÀÎÇÑ´Ù.
**          2) SQL> @tab_block [table¸í]
**
**  Notice : sum(blocks)´Â »ç¿ëÇÏ´Â ºí·°ÀÇ °¹¼öÀÌ¸ç »çÀÌÁî´Â db_block_size¸¦
**          °öÇÏ¿© ¾òÀ» ¼ö ÀÖ´Ù.
*/
SELECT OWNER, TABLESPACE_NAME, SEGMENT_NAME, SUM(BLOCKS)
FROM  DBA_EXTENTS
WHERE  SEGMENT_NAME = UPPER('&1')
GROUP BY OWNER, TABLESPACE_NAME, SEGMENT_NAME
/

[b][color=BLUE]ÀÌ¹Ì ÄÄÆÄÀÏµÈ ÇÁ·Î½ÃÁ®¼Ò½º¸¦ º¸°í½ÍÀ» ¶§ »ç¿ëÇÏ´Â ½ºÅ©¸³Æ®[/color][/b]

/*
**  PL/SQL ¼Ò½º¸¦ º¸±âÀ§ÇÑ ½ºÅ©¸³Æ®..                      <¹ÚÁ¦¿ë>
**
**  »ç¿ë¹ý : find_plsql [ÇÁ·Î½ÃÁ®¸íĪ]
** 
** 
*/
select text
from  user_source
where  name = upper('&1')
order  by line;

[b][color=BLUE]Å×À̺íÀ» º¹»çÇØÁÖ´Â ½ºÅ©¸³Æ® (v8.0 only)[/color][/b]

/*
**    tableÀ» ´Ù¸¥ ½ºÅ°¸¶ ȤÀº table·Î º¹»ç    <<¹ÚÁ¦¿ë>>
**
**    Notice) 1. Oracle 8.0 À̻󿡼­¸¸ Áö¿ø. 
**            2. sql*net ÀÌ ¼³Á¤µÇ¾î ÀÖ¾î¾ß¸¸ ÇÑ´Ù.
**            3. Å×À̺í°ú PK¸¸ º¹»çÇÏ°í À妽º´Â ¸ðµÎ ´Ù½Ã »ý¼ºÇØÁÖ¾î¾ß ÇÑ´Ù.
**              µû¶ó¼­ Å×À̺íÀ» »ý¼ºÇØ ÁÖ°í ÀÔ·ÂÇϴ°ÍÀÌ ÁÁ´Ù.
**            4. sql*plus ¿¡¼­¸¸ ½ÇÇàµÈ´Ù.
**  »ç¿ë¹ý) @tab_copy scott/tiger@link source_table_name target_table_name
**
*/
copy from &1 create &3 using select * from &2

/* ´Ù¸¥ DB·Î º¹»çÇÒ¶§´Â
copy from &1 to &2 create &4 using select * from &3
*/

/* ¹Ì¸® ¸¸µé¾îÁø table¿¡ ÀÔ·ÂÇÒ¶§´Â
copy from &1 insert &3 using select * from &2
*/

[b][color=BLUE]Table Data Size¸¦ Á¤È®È÷ °è»êÇØÁÖ´Â ½ºÅ©¸³Æ®[/color][/b]

/*
**  Table Data Size¸¦ Á¤È®È÷ °è»êÇØÁÖ´Â ½ºÅ©¸³Æ®.  <<¹ÚÁ¦¿ë>>
**
**  »ç¿ë¹ý : @tab_size [table_name]
**
*/
analyze table &1 delete statistics;
analyze table &1 compute statistics;

SELECT GREATEST(4, ceil(NUM_ROWS/
( (round(((1958-(INI_TRANS*23))*((100-PCT_FREE)/100))/AVG_ROW_LEN)))) * 2048) TableSize_Kbytes
FROM user_tables
WHERE table_name = upper('&1');

[b][color=BLUE]dead lockÀÌ ¹ß»ýÇßÀ»¶§ ¹ß»ý½ÃŲ À¯Àú¿Í SQL¹®À» ã¾ÆÁÖ´Â SQL[/color][/b]

/*
**
** »ç¿ë¹ý  :SQL> @find_deadlock
** Description : µ¥µå¶ôÀÌ ¹ß»ýÇÒ °æ¿ì locking µÈ À¯Àú¿Í sql¹®À» º¸¿©ÁØ´Ù.
**
** µ¥µå¶ôÀÌ ¹ß»ýÇÑ À¯Àú¸¦ kill ÇÏ·Á¸é.
**  Alter system kill session '{serial#},{SID}';
**
*/
Select a.serial#, a.sid, a.username, b.id1, c.sql_text
from  v$session a, v$lock b, v$sqltext c
where  b.id1 in( select distinct e.id1 from v$session d, v$lock e
                where d.lockwait = e.kaddr)
and a.sid = b.sid
and c.hash_value = a.sql_hash_value
and b.request = 0;

[b][color=BLUE]µñ¼Å³Ê¸®¿¡¼­ ÇØ´ç Å°¿öµå¿¡ °üÇÑ ºä, Å×À̺íÀ» ã¾ÆÁÖ´Â SQL[/color][/b]

/*
**  µñ¼Å³Ê¸®·ÎºÎÅÍ ÀÔ·ÂÇÑ Å°¿öµå¿¡ °üÇÑ Å×À̺í¸íÀ» Á¶È¸ÇÑ´Ù.    <<¹ÚÁ¦¿ë>>
**
**  »ç¿ë¹ý : SQL> @dic_find [Å°¿öµå(´ë¼Ò¹®ÀÚ°¡¸²)]
**
*/
col TABLE_NAME format a15
col COMMENTS  format a100

select * from dictionary
where COMMENTS like ('%&1%')
/

[b][color=BLUE]Ä÷³¸í¸¸ °¡Áö°í Å×À̺í°ú ¼³Á¤»óŸ¦ ã¾ÆÁÖ´Â SQL[/color][/b]

/*
**  Ä÷³ÀÇ ½ºÆå°ú, ¼Ò¼Ó Å×À̺íÀ» ã´Â´Ù.        <<¹ÚÁ¦¿ë>>
**
**  »ç¿ë¹ý : SQL> @col_find [Ä÷³¸í]
**
*/
col CNAME format a20
col COLTYPE format a10
col NULLS format a5
col DEFAULTVAL format a10

select TNAME, COLNO, CNAME, COLTYPE, WIDTH, NULLS, DEFAULTVAL
from col
where CNAME = UPPER('&1')
/

[b][color=BLUE]Constraint À̸§À¸·Î ÇØ´ç Å×À̺í°ú Ä÷³Ã£´Â SQL[/color][/b]

/*
**=============================================
** CONSTRAINT À̸§À¸·Î »ç¿ë Å×À̺í ã±â
**=============================================
**
**  Usage        :  @Show_Columns  Constraint_Name
**  Description  :  Shows The Columns Bound By A Constraint
**  »ç¿ë¿¹      :  SQL> @show_Columns PK_EMPNO
*/
SET VERIFY OFF
CLEAR BREAK
BREAK ON CONSTRAINT_NAME ON TABLES

SELECT SUBSTR(CONSTRAINT_NAME,1,25) CONSTRAINT_NAME,
      SUBSTR(TABLE_NAME,1,15) TABLES,
      SUBSTR(COLUMN_NAME,1,15) COL_NAME
FROM  ALL_CONS_COLUMNS
WHERE  CONSTRAINT_NAME = UPPER('&1');

[b][color=BLUE]Ä÷³¿¡ °É·ÁÀÖ´Â constraint ¸¦ º¸¿©ÁÖ´Â SQL[/color][/b]

/*
**=======================================
** ÇØ´ç COLUMN¿¡ °É·Á ÀÖ´Â CONSTRAINTÈ®ÀÎ
**=======================================
**
**  Usage      :  @Show_Constraints  Table_Name  Column_Name
**
**  Description  :  ÇØ´ç TableÀÇ Column¿¡ °É·Á ÀÖ´Â Constraint¸¦ º¸¿©ÁØ´Ù.
**
** < ½ÇÇà ¿¹ >
** SQL>  @SHOW_CONSTRAINTS  WIDGETS  LENGTH
**
*/

SET VERIFY OFF
CLEAR BREAK
BREAK ON TABLES ON COL_NAME
SELECT  SUBSTR(TABLE_NAME,1,15)    TABLES,
          SUBSTR(COLUMN_NAME,1,15)  COL_NAME,
          SUBSTR(CONSTRAINT_NAME,1,25)  CONSTRAINT_NAME
FROM    USER_CONS_COLUMNS
WHERE  TABLE_NAME = UPPER('&1')
AND    COLUMN_NAME = UPPER('&2');

[b][color=BLUE]PK¿Í FK°£ÀÇ ¿¬°ü°ü°è¸¦ ã¾Æ º¸¿©ÁÖ´Â SQL[/color][/b]

/*
**
** »ç¿ë¹ý  :> @Show_Positions Parent_Table Child_Table
** Description : Shows Primary And Foreign Key Positions
**
** WARNING : ÀÌ ¹®ÀåÀº ÇØ´ç TableÀÇ Constraint»ý¼º½Ã Naming
** ConventionÀ» µû¸¥ °æ¿ì¿¡ Àû¿ëµÇµµ·Ï µÇ¾î ÀÖ´Ù.
**
*/
SET VERIFY OFF
CLEAR BREAK
BREAK ON CONSTRAINT_NAME ON TABLES
SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
      SUBSTR(TABLE_NAME,1,15) TABLES,
      SUBSTR(COLUMN_NAME,1,15) COL_NAME,
      SUBSTR(POSITION,1,3)    POSITION,
      SUBSTR(OWNER,1,7) OWNER
FROM USER_CONS_COLUMNS WHERE TABLE_NAME = UPPER('&1') AND CONSTRAINT_NAME LIKE 'PK%'
UNION
SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
      SUBSTR(TABLE_NAME,1,15) TABLES,
      SUBSTR(COLUMN_NAME,1,25) COL_NAME,
      SUBSTR(POSITION,1,3) POSITION,
      SUBSTR(OWNER,1,7) OWNER
FROM USER_CONS_COLUMNS WHERE TABLE_NAME = UPPER('&2') AND CONSTRAINT_NAME LIKE 'FK%'
ORDER BY 1 DESC,4 ASC;

[b][color=BLUE]Å×À̺íÀÇ Æ¯Á¤ Ä÷³¿¡ Áߺ¹µÈ °ªÀ» ã´Â SQL[/color][/b]

/*
**=============================================
** Áߺ¹µÈ °ª ÀÖ´ÂÁö ã±â
**=============================================
**  Usage  :  @Áߺ¹Ã£±â.sql [Å×À̺í¸í]  [Áߺ¹À»Á¶»çÇÒÄ÷³¸í]
**
**  Warning : ¶È°°Àº°ªÀÌ 2°³ ÀÌ»óÀÖÀ»¶§ óÀ½°ªÀº Ãâ·Â ¾ÊµÇ°í 2¹ø° °ªºÎÅÍ Ãâ·ÂµÊ. <>
*/

select * from &1 A
where rowid >
(SELECT min(rowid) FROM &1 B
  WHERE B.&2 = A.&2)
order by &2;


¸ñ·Ï | ÀÔ·Â | ¼öÁ¤ | ´äº¯ | »èÁ¦