이 Documents 는 SQL 과 SQL*PLUS를 동적으로 생성하고 수행하는 방법을 소개하고 있다. 이를 위해 자주 사용하는 3가지 사용 예를 소개한다.
* 이 Document는 다음과 같이 구성 되어져 있다.
* CREATING A DYNAMIC DROP TABLE SCRIPT * CREATING A DYNAMIC GRANT PRIVILEGES SCRIPT * CREATING A DYNAMIC SCRIPT TO SET SQL PROMPT TO DATABASE NAME 1. CREATING A DYNAMIC DROP TABLE SCRIPT * 개발 과정 중 우리는 Table을 Drop하고 Original Data를 Import하는 작업을 빈번하게 수행하는 데, 이때 개개의 Drop 문을 사용하지 않고 SET_UP_DROP.SQL 이라 불리우는 다음의 Script를 사용한다.
set heading off set feedback off spool drop_all.sql select 'drop table'||table_name||';'from user_tables; spool off set feedback on start drop_all.sql
* DROP_ALL.SQL script 는 다음과 같다. drop table DEPT; drop table BONUS; drop table SALGRADE; drop table DUMMY; drop table CUSTOMER; drop table ORD; drop table ITEM; drop table PRODUCT; drop table PRICE;
2. CREATING A DYNAMIC GRANT PRIVILEGES SCRIPT * 자신의 모든 Table 을 다른 사람에게 SELECT 권한을 부여하고자 할때 다음의 SET_UP_GRANT.SQL 을 이용하면 빠르고 손쉽게 해결할 수 있다.
set heading off set feedback off spool grant_all.sql select 'grant select on'||table_name||'to SCOTT;'from user_tables; spool off set feedback on start grant_all.sql
* GRANT_ALL.SQL 의 script 는 다음과 같다.
grant select on DEPT to SCOTT; grant select on BONUS to SCOTT; grant select on SALGRADE to SCOTT; grant select on DUMMY to SCOTT; grant select on CUSTOMER to SCOTT; grant select on ORD to SCOTT; grant select on ITEM to SCOTT; grant select on PRODUCT to SCOTT; grant select on PRICE to SCOTT;
3. CREATING A DYNAMIC SCRIPT TO SET SQL PROMPT TO DATABASE NAME * 위의 개념들을 보다 더 잘 사용하기 위해서는 Sql Prompt를 자신의 Database로 변환해 주는 SET_UP_PROMPT.SQL Script를 login.sql File 에 추가시켜 자동적으로 SQL*PLUS 를 불러 올수있게 한다. 이는 Multiple Databases에 유용하다.
set termout off set heading off set feedback off spool set_prompt.sql select 'set sqlprompt'||value||'>"from v$parameter where name='db_name'; spool off start set_prompt.sql
* SET_PROMPT.SQL 은 다음과 같다. set sqlprompt V715>
* V$PARAMETER 는 Dynamic Performance Table 의 View 이다. Install후 SYS 만이 Dynamic Performance Table을 수행할 수 있으므로 위의 Script를 사용하기 위해 View를 Create 하거나 User에게 Access 권한을 부여하여야 한다.
w Dynamic Performance Table은 ORACLE RDBMS Database Administrators Guide V6 또는 ORACLE7 Server Utilities User's Guide를 참조. |