2026-03-12 20:23:15
This commit is contained in:
86
timhall/script_creation/backup.sql
Normal file
86
timhall/script_creation/backup.sql
Normal file
@@ -0,0 +1,86 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/backup.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates a very basic hot-backup script. A useful starting point.
|
||||
-- Call Syntax : @backup
|
||||
-- Last Modified: 28/01/2001
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET SERVEROUTPUT ON
|
||||
SET LINESIZE 1000
|
||||
SET TRIMOUT ON
|
||||
SET FEEDBACK OFF
|
||||
SPOOL Backup.txt
|
||||
|
||||
DECLARE
|
||||
|
||||
CURSOR c_tablespace IS
|
||||
SELECT a.tablespace_name
|
||||
FROM dba_tablespaces a
|
||||
ORDER BY 1;
|
||||
|
||||
CURSOR c_datafiles (in_ts_name IN VARCHAR2) IS
|
||||
SELECT a.file_name
|
||||
FROM dba_data_files a
|
||||
WHERE a.tablespace_name = in_ts_name
|
||||
ORDER BY 1;
|
||||
|
||||
CURSOR c_archive_redo IS
|
||||
SELECT a.value
|
||||
FROM v$parameter a
|
||||
WHERE a.name = \'log_archive_dest\';
|
||||
|
||||
v_sid VARCHAR2(100) := \'ORCL\';
|
||||
v_backup_com VARCHAR2(100) := \'!ocopy \';
|
||||
v_remove_com VARCHAR2(100) := \'!rm\';
|
||||
v_dest_loc VARCHAR2(100) := \'/opt/oracleddds/dbs1/oradata/ddds/\';
|
||||
|
||||
BEGIN
|
||||
|
||||
DBMS_Output.Disable;
|
||||
DBMS_Output.Enable(1000000);
|
||||
|
||||
DBMS_Output.Put_Line(\'svrmgrl\');
|
||||
DBMS_Output.Put_Line(\'connect internal\');
|
||||
|
||||
DBMS_Output.Put_Line(\' \');
|
||||
DBMS_Output.Put_Line(\'-- ----------------------\');
|
||||
DBMS_Output.Put_Line(\'-- Backup all tablespaces\');
|
||||
DBMS_Output.Put_Line(\'-- ----------------------\');
|
||||
FOR cur_ts IN c_tablespace LOOP
|
||||
DBMS_Output.Put_Line(\' \');
|
||||
DBMS_Output.Put_Line(\'ALTER TABLESPACE \' || cur_ts.tablespace_name || \' BEGIN BACKUP;\');
|
||||
FOR cur_df IN c_datafiles (in_ts_name => cur_ts.tablespace_name) LOOP
|
||||
DBMS_Output.Put_Line(v_backup_com || \' \' || cur_df.file_name || \' \' ||
|
||||
v_dest_loc || SUBSTR(cur_df.file_name, INSTR(cur_df.file_name, \'/\', -1)+1));
|
||||
END LOOP;
|
||||
DBMS_Output.Put_Line(\'ALTER TABLESPACE \' || cur_ts.tablespace_name || \' END BACKUP;\');
|
||||
END LOOP;
|
||||
|
||||
DBMS_Output.Put_Line(\' \');
|
||||
DBMS_Output.Put_Line(\'-- -----------------------------\');
|
||||
DBMS_Output.Put_Line(\'-- Backup the archived redo logs\');
|
||||
DBMS_Output.Put_Line(\'-- -----------------------------\');
|
||||
FOR cur_ar IN c_archive_redo LOOP
|
||||
DBMS_Output.Put_Line(v_backup_com || \' \' || cur_ar.value || \'/* \' ||
|
||||
v_dest_loc);
|
||||
END LOOP;
|
||||
|
||||
|
||||
DBMS_Output.Put_Line(\' \');
|
||||
DBMS_Output.Put_Line(\'-- ----------------------\');
|
||||
DBMS_Output.Put_Line(\'-- Backup the controlfile\');
|
||||
DBMS_Output.Put_Line(\'-- ----------------------\');
|
||||
DBMS_Output.Put_Line(\'ALTER DATABASE BACKUP CONTROLFILE TO \'\'\' || v_dest_loc || v_sid || \'Controlfile.backup\'\';\');
|
||||
DBMS_Output.Put_Line(v_backup_com || \' \' || v_dest_loc || v_sid || \'Controlfile.backup\');
|
||||
DBMS_Output.Put_Line(v_remove_com || \' \' || v_dest_loc || v_sid || \'Controlfile.backup\');
|
||||
|
||||
DBMS_Output.Put_Line(\' \');
|
||||
DBMS_Output.Put_Line(\'EXIT\');
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
PROMPT
|
||||
SPOOL OFF
|
||||
SET LINESIZE 80
|
||||
SET FEEDBACK ON
|
||||
302
timhall/script_creation/build_api.sql
Normal file
302
timhall/script_creation/build_api.sql
Normal file
@@ -0,0 +1,302 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/build_api.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Generates a basic API package for the specific table.
|
||||
-- Requirements : USER_% and ALL_% views.
|
||||
-- Call Syntax : @build_api (table-name) (schema)
|
||||
-- Last Modified: 08/01/2002
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET SERVEROUTPUT ON
|
||||
SET VERIFY OFF
|
||||
SET ECHO OFF
|
||||
SET TERMOUT OFF
|
||||
SET FEEDBACK OFF
|
||||
|
||||
SPOOL Package.pkh
|
||||
|
||||
DECLARE
|
||||
|
||||
v_table_name VARCHAR2(30) := Upper('&1');
|
||||
v_owner VARCHAR2(30) := Upper('&2');
|
||||
|
||||
CURSOR c_pk_columns IS
|
||||
SELECT a.position,
|
||||
a.column_name
|
||||
FROM all_cons_columns a,
|
||||
all_constraints b
|
||||
WHERE a.owner = v_owner
|
||||
AND a.table_name = v_table_name
|
||||
AND a.constraint_name = b.constraint_name
|
||||
AND b.constraint_type = 'P'
|
||||
AND b.owner = a.owner
|
||||
AND b.table_name = a.table_name
|
||||
ORDER BY position;
|
||||
|
||||
CURSOR c_columns IS
|
||||
SELECT atc.column_name
|
||||
FROM all_tab_columns atc
|
||||
WHERE atc.owner = v_owner
|
||||
AND atc.table_name = v_table_name;
|
||||
|
||||
CURSOR c_non_pk_columns (p_nullable IN VARCHAR2) IS
|
||||
SELECT atc.column_name
|
||||
FROM all_tab_columns atc
|
||||
WHERE atc.owner = v_owner
|
||||
AND atc.table_name = v_table_name
|
||||
AND atc.nullable = p_nullable
|
||||
AND atc.column_name NOT IN (SELECT a.column_name
|
||||
FROM all_cons_columns a,
|
||||
all_constraints b
|
||||
WHERE a. owner = v_owner
|
||||
AND a.table_name = v_table_name
|
||||
AND a.constraint_name = b.constraint_name
|
||||
AND b.constraint_type = 'P'
|
||||
AND b.owner = a.owner
|
||||
AND b.table_name = a.table_name);
|
||||
|
||||
PROCEDURE GetParameterList IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_pk_columns LOOP
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad(Lower(cur_col.column_name), 30, ' ') || ' IN ' || Lower(v_table_name) || '.' || Lower(cur_col.column_name) || '%TYPE,');
|
||||
END LOOP;
|
||||
FOR cur_col IN c_non_pk_columns('N') LOOP
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad(Lower(cur_col.column_name), 30, ' ') || ' IN ' || Lower(v_table_name) || '.' || Lower(cur_col.column_name) || '%TYPE,');
|
||||
END LOOP;
|
||||
FOR cur_col IN c_non_pk_columns('Y') LOOP
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad(Lower(cur_col.column_name), 30, ' ') || ' IN ' || Lower(v_table_name) || '.' || Lower(cur_col.column_name) || '%TYPE DEFAULT NULL,');
|
||||
END LOOP;
|
||||
DBMS_Output.Put(Chr(9) || 'p_' || RPad('commit', 30, ' ') || ' IN VARCHAR2 DEFAULT ''Y''');
|
||||
END;
|
||||
|
||||
PROCEDURE GetPKParameterList IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_pk_columns LOOP
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad(Lower(cur_col.column_name), 30, ' ') || ' IN ' || Lower(v_table_name) || '.' || Lower(cur_col.column_name) || '%TYPE,');
|
||||
END LOOP;
|
||||
DBMS_Output.Put(Chr(9) || 'p_' || RPad('commit', 30, ' ') || ' IN VARCHAR2 DEFAULT ''Y''');
|
||||
END;
|
||||
|
||||
PROCEDURE GetInsertColumnList IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_columns LOOP
|
||||
IF c_columns%ROWCOUNT != 1 THEN
|
||||
DBMS_Output.Put_Line(',');
|
||||
END IF;
|
||||
DBMS_Output.Put(Chr(9) || Chr(9) || Lower(cur_col.column_name));
|
||||
END LOOP;
|
||||
DBMS_Output.New_Line;
|
||||
END;
|
||||
|
||||
PROCEDURE GetInsertValueList IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_columns LOOP
|
||||
IF c_columns%ROWCOUNT != 1 THEN
|
||||
DBMS_Output.Put_Line(',');
|
||||
END IF;
|
||||
DBMS_Output.Put(Chr(9) || Chr(9) || 'p_' || Lower(cur_col.column_name));
|
||||
END LOOP;
|
||||
DBMS_Output.New_Line;
|
||||
END;
|
||||
|
||||
PROCEDURE GetUpdateSetList IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_columns LOOP
|
||||
IF c_columns%ROWCOUNT != 1 THEN
|
||||
DBMS_Output.Put_Line(',');
|
||||
DBMS_Output.Put(Chr(9) || Chr(9) || Chr(9) || Chr(9));
|
||||
ELSE
|
||||
DBMS_Output.Put(Chr(9) || 'SET ');
|
||||
END IF;
|
||||
DBMS_Output.Put(RPad(Lower(cur_col.column_name), 30, ' ') || ' = p_' || Lower(cur_col.column_name));
|
||||
END LOOP;
|
||||
DBMS_Output.New_Line;
|
||||
END;
|
||||
|
||||
PROCEDURE GetPKWhere (p_for_update IN VARCHAR2 DEFAULT NULL) IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_pk_columns LOOP
|
||||
IF c_pk_columns%ROWCOUNT = 1 THEN
|
||||
DBMS_Output.Put(Chr(9) || 'WHERE ');
|
||||
ELSE
|
||||
DBMS_Output.New_Line;
|
||||
DBMS_Output.Put(Chr(9) || 'AND ');
|
||||
END IF;
|
||||
DBMS_Output.Put(RPad(Lower(cur_col.column_name), 30, ' ') || ' = p_' || Lower(cur_col.column_name));
|
||||
END LOOP;
|
||||
|
||||
IF p_for_update = 'Y' THEN
|
||||
DBMS_Output.New_Line;
|
||||
DBMS_Output.Put(Chr(9) || 'FOR UPDATE');
|
||||
END IF;
|
||||
DBMS_Output.Put_Line(';');
|
||||
END;
|
||||
|
||||
PROCEDURE GetCommit IS
|
||||
BEGIN
|
||||
DBMS_Output.Put_Line(Chr(9) || 'IF p_commit = ''Y'' THEN');
|
||||
DBMS_Output.Put_Line(Chr(9) || Chr(9) || 'COMMIT;');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'END IF;');
|
||||
DBMS_Output.New_Line;
|
||||
END;
|
||||
|
||||
PROCEDURE GetSeparator IS
|
||||
BEGIN
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
END;
|
||||
|
||||
BEGIN
|
||||
|
||||
DBMS_Output.Enable(1000000);
|
||||
|
||||
-- ---------------------
|
||||
-- Package Specification
|
||||
-- ---------------------
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('-- Name : ' || Lower(v_table_name) || '_api.pkh');
|
||||
DBMS_Output.Put_Line('-- Created By : Tim Hall');
|
||||
DBMS_Output.Put_Line('-- Created Date: ' || To_Char(Sysdate, 'DD-Mon-YYYY'));
|
||||
DBMS_Output.Put_Line('-- Description : API procedures for the ' || v_table_name || ' table.');
|
||||
DBMS_Output.Put_Line('-- Ammendments :');
|
||||
DBMS_Output.Put_Line('-- ' || To_Char(Sysdate, 'DD-Mon-YYYY') || ' TSH Initial Creation');
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('CREATE OR REPLACE PACKAGE ' || Lower(v_table_name) || '_api AS');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
DBMS_Output.Put_Line('TYPE cursor_type IS REF CURSOR;');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('PROCEDURE Sel (');
|
||||
GetPKParameterList;
|
||||
DBMS_Output.New_Line;
|
||||
DBMS_Output.Put_Line(Chr(9) || RPad('p_recordset', 32, ' ') || ' OUT cursor_type');
|
||||
DBMS_Output.Put_Line(');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('PROCEDURE Ins (');
|
||||
GetParameterList;
|
||||
DBMS_Output.Put_Line(');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('PROCEDURE Upd (');
|
||||
GetParameterList;
|
||||
DBMS_Output.Put_Line(');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('PROCEDURE Del (');
|
||||
GetPKParameterList;
|
||||
DBMS_Output.Put_Line(');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('END ' || Lower(v_table_name) || '_api;');
|
||||
DBMS_Output.Put_Line('/');
|
||||
|
||||
-- ------------
|
||||
-- Package Body
|
||||
-- ------------
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('-- Name : ' || Lower(v_table_name) || '_api.pkg');
|
||||
DBMS_Output.Put_Line('-- Created By : Tim Hall');
|
||||
DBMS_Output.Put_Line('-- Created Date: ' || To_Char(Sysdate, 'DD-Mon-YYYY'));
|
||||
DBMS_Output.Put_Line('-- Description : API procedures for the ' || v_table_name || ' table.');
|
||||
DBMS_Output.Put_Line('-- Ammendments :');
|
||||
DBMS_Output.Put_Line('-- ' || To_Char(Sysdate, 'DD-Mon-YYYY') || ' TSH Initial Creation');
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('CREATE OR REPLACE PACKAGE BODY ' || Lower(v_table_name) || '_api AS');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
-- Select
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line('PROCEDURE Sel (');
|
||||
GetPKParameterList;
|
||||
DBMS_Output.New_Line;
|
||||
DBMS_Output.Put_Line(Chr(9) || RPad('p_recordset', 32, ' ') || ' OUT cursor_type');
|
||||
DBMS_Output.Put_Line(') IS');
|
||||
GetSeparator;
|
||||
|
||||
DBMS_Output.Put_Line('BEGIN');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line(Chr(9) || 'OPEN p_recordset FOR');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'SELECT');
|
||||
GetInsertColumnList;
|
||||
DBMS_Output.Put_Line(Chr(9) || 'FROM ' || Lower(v_table_name));
|
||||
GetPKWhere;
|
||||
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
DBMS_Output.Put_Line('END Sel;');
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
|
||||
-- Insert
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line('PROCEDURE Ins (');
|
||||
GetParameterList;
|
||||
DBMS_Output.Put_Line(') IS');
|
||||
GetSeparator;
|
||||
|
||||
DBMS_Output.Put_Line('BEGIN');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line(Chr(9) || 'INSERT INTO ' || Lower(v_table_name));
|
||||
DBMS_Output.Put_Line(Chr(9) || '(');
|
||||
GetInsertColumnList;
|
||||
DBMS_Output.Put_Line(Chr(9) || ')');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'VALUES');
|
||||
DBMS_Output.Put_Line(Chr(9) || '(');
|
||||
GetInsertValueList;
|
||||
DBMS_Output.Put_Line(Chr(9) || ');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
GetCommit;
|
||||
DBMS_Output.Put_Line('END Ins;');
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
-- Update
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line('PROCEDURE Upd (');
|
||||
GetParameterList;
|
||||
DBMS_Output.Put_Line(') IS');
|
||||
GetSeparator;
|
||||
|
||||
DBMS_Output.Put_Line('BEGIN');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
DBMS_Output.Put_Line(Chr(9) || 'UPDATE ' || Lower(v_table_name));
|
||||
GetUpdateSetList;
|
||||
GetPKWhere;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
GetCommit;
|
||||
DBMS_Output.Put_Line('END Upd;');
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
-- Delete
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line('PROCEDURE Del (');
|
||||
GetPKParameterList;
|
||||
DBMS_Output.Put_Line(') IS');
|
||||
GetSeparator;
|
||||
|
||||
DBMS_Output.Put_Line('BEGIN');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
DBMS_Output.Put_Line(Chr(9) || 'DELETE FROM ' || Lower(v_table_name));
|
||||
GetPKWhere;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
GetCommit;
|
||||
DBMS_Output.Put_Line('END Del;');
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('END ' || Lower(v_table_name) || '_api;');
|
||||
DBMS_Output.Put_Line('/');
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
SPOOL OFF
|
||||
|
||||
SET ECHO ON
|
||||
SET TERMOUT ON
|
||||
SET FEEDBACK ON
|
||||
301
timhall/script_creation/build_api2.sql
Normal file
301
timhall/script_creation/build_api2.sql
Normal file
@@ -0,0 +1,301 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/build_api2.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Generates a basic API package for the specific table.
|
||||
-- Update of build_api to use ROWTYPEs as parameters.
|
||||
-- Requirements : USER_% and ALL_% views.
|
||||
-- Call Syntax : @build_api2 (table-name) (schema)
|
||||
-- Last Modified: 08/01/2002
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET SERVEROUTPUT ON
|
||||
SET VERIFY OFF
|
||||
SET ECHO OFF
|
||||
SET TERMOUT OFF
|
||||
SET TRIMSPOOL ON
|
||||
SET FEEDBACK OFF
|
||||
|
||||
SPOOL Package.pkh
|
||||
|
||||
DECLARE
|
||||
|
||||
v_table_name VARCHAR2(30) := Upper('&&1');
|
||||
v_owner VARCHAR2(30) := Upper('&&2');
|
||||
|
||||
CURSOR c_pk_columns IS
|
||||
SELECT a.position,
|
||||
a.column_name
|
||||
FROM all_cons_columns a,
|
||||
all_constraints b
|
||||
WHERE a.owner = v_owner
|
||||
AND a.table_name = v_table_name
|
||||
AND a.constraint_name = b.constraint_name
|
||||
AND b.constraint_type = 'P'
|
||||
AND b.owner = a.owner
|
||||
AND b.table_name = a.table_name
|
||||
ORDER BY position;
|
||||
|
||||
CURSOR c_columns IS
|
||||
SELECT atc.column_name
|
||||
FROM all_tab_columns atc
|
||||
WHERE atc.owner = v_owner
|
||||
AND atc.table_name = v_table_name;
|
||||
|
||||
CURSOR c_non_pk_columns (p_nullable IN VARCHAR2) IS
|
||||
SELECT atc.column_name
|
||||
FROM all_tab_columns atc
|
||||
WHERE atc.owner = v_owner
|
||||
AND atc.table_name = v_table_name
|
||||
AND atc.nullable = p_nullable
|
||||
AND atc.column_name NOT IN (SELECT a.column_name
|
||||
FROM all_cons_columns a,
|
||||
all_constraints b
|
||||
WHERE a. owner = v_owner
|
||||
AND a.table_name = v_table_name
|
||||
AND a.constraint_name = b.constraint_name
|
||||
AND b.constraint_type = 'P'
|
||||
AND b.owner = a.owner
|
||||
AND b.table_name = a.table_name);
|
||||
|
||||
PROCEDURE GetPKParameterList(p_commit IN BOOLEAN DEFAULT TRUE) IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_pk_columns LOOP
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad(Lower(cur_col.column_name), 30, ' ') || ' IN ' || Lower(v_table_name) || '.' || Lower(cur_col.column_name) || '%TYPE,');
|
||||
END LOOP;
|
||||
IF p_commit THEN
|
||||
DBMS_Output.Put(Chr(9) || 'p_' || RPad('commit', 30, ' ') || ' IN VARCHAR2 DEFAULT ''Y''');
|
||||
END IF;
|
||||
END;
|
||||
|
||||
PROCEDURE GetInsertColumnList IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_columns LOOP
|
||||
IF c_columns%ROWCOUNT != 1 THEN
|
||||
DBMS_Output.Put_Line(',');
|
||||
END IF;
|
||||
DBMS_Output.Put(Chr(9) || Chr(9) || Lower(cur_col.column_name));
|
||||
END LOOP;
|
||||
DBMS_Output.New_Line;
|
||||
END;
|
||||
|
||||
PROCEDURE GetInsertValueList IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_columns LOOP
|
||||
IF c_columns%ROWCOUNT != 1 THEN
|
||||
DBMS_Output.Put_Line(',');
|
||||
END IF;
|
||||
DBMS_Output.Put(Chr(9) || Chr(9) || 'p_' || Lower(v_table_name) || '.' || Lower(cur_col.column_name));
|
||||
END LOOP;
|
||||
DBMS_Output.New_Line;
|
||||
END;
|
||||
|
||||
PROCEDURE GetUpdateSetList IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_columns LOOP
|
||||
IF c_columns%ROWCOUNT != 1 THEN
|
||||
DBMS_Output.Put_Line(',');
|
||||
DBMS_Output.Put(Chr(9) || Chr(9) || Chr(9) || Chr(9));
|
||||
ELSE
|
||||
DBMS_Output.Put(Chr(9) || 'SET ');
|
||||
END IF;
|
||||
DBMS_Output.Put(RPad(Lower(cur_col.column_name), 30, ' ') || ' = p_' || Lower(v_table_name) || '.' || Lower(cur_col.column_name));
|
||||
END LOOP;
|
||||
DBMS_Output.New_Line;
|
||||
END;
|
||||
|
||||
PROCEDURE GetPKWhere (p_record IN VARCHAR2 DEFAULT NULL,
|
||||
p_for_update IN VARCHAR2 DEFAULT NULL) IS
|
||||
BEGIN
|
||||
FOR cur_col IN c_pk_columns LOOP
|
||||
IF c_pk_columns%ROWCOUNT = 1 THEN
|
||||
DBMS_Output.Put(Chr(9) || 'WHERE ');
|
||||
ELSE
|
||||
DBMS_Output.New_Line;
|
||||
DBMS_Output.Put(Chr(9) || 'AND ');
|
||||
END IF;
|
||||
IF p_record = 'Y' THEN
|
||||
DBMS_Output.Put(RPad(Lower(cur_col.column_name), 30, ' ') || ' = p_' || Lower(v_table_name) || '.' || Lower(cur_col.column_name));
|
||||
ELSE
|
||||
DBMS_Output.Put(RPad(Lower(cur_col.column_name), 30, ' ') || ' = p_' || Lower(cur_col.column_name));
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
IF p_for_update = 'Y' THEN
|
||||
DBMS_Output.New_Line;
|
||||
DBMS_Output.Put(Chr(9) || 'FOR UPDATE');
|
||||
END IF;
|
||||
DBMS_Output.Put_Line(';');
|
||||
END;
|
||||
|
||||
PROCEDURE GetCommit IS
|
||||
BEGIN
|
||||
DBMS_Output.Put_Line(Chr(9) || 'IF p_commit = ''Y'' THEN');
|
||||
DBMS_Output.Put_Line(Chr(9) || Chr(9) || 'COMMIT;');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'END IF;');
|
||||
DBMS_Output.New_Line;
|
||||
END;
|
||||
|
||||
PROCEDURE GetSeparator IS
|
||||
BEGIN
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
END;
|
||||
|
||||
BEGIN
|
||||
|
||||
DBMS_Output.Enable(1000000);
|
||||
|
||||
-- ---------------------
|
||||
-- Package Specification
|
||||
-- ---------------------
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('-- Name : ' || Lower(v_table_name) || '_api.pkh');
|
||||
DBMS_Output.Put_Line('-- Created By : Tim Hall');
|
||||
DBMS_Output.Put_Line('-- Created Date: ' || To_Char(Sysdate, 'DD-Mon-YYYY'));
|
||||
DBMS_Output.Put_Line('-- Description : API procedures for the ' || v_table_name || ' table.');
|
||||
DBMS_Output.Put_Line('-- Ammendments :');
|
||||
DBMS_Output.Put_Line('-- ' || To_Char(Sysdate, 'DD-Mon-YYYY') || ' TSH Initial Creation');
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('CREATE OR REPLACE PACKAGE ' || Lower(v_table_name) || '_api AS');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
DBMS_Output.Put_Line('TYPE cursor_type IS REF CURSOR;');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('PROCEDURE Sel (');
|
||||
GetPKParameterList(FALSE);
|
||||
DBMS_Output.New_Line;
|
||||
DBMS_Output.Put_Line(Chr(9) || RPad('p_recordset', 32, ' ') || ' OUT cursor_type');
|
||||
DBMS_Output.Put_Line(');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('PROCEDURE Ins (');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad(Lower(v_table_name), 30, ' ') || ' IN ' || Lower(v_table_name) || '%ROWTYPE,');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad('commit', 30, ' ') || ' IN VARCHAR2 DEFAULT ''Y''');
|
||||
DBMS_Output.Put_Line(');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('PROCEDURE Upd (');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad(Lower(v_table_name), 30, ' ') || ' IN ' || Lower(v_table_name) || '%ROWTYPE,');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad('commit', 30, ' ') || ' IN VARCHAR2 DEFAULT ''Y''');
|
||||
DBMS_Output.Put_Line(');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('PROCEDURE Del (');
|
||||
GetPKParameterList;
|
||||
DBMS_Output.Put_Line(');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('END ' || Lower(v_table_name) || '_api;');
|
||||
DBMS_Output.Put_Line('/');
|
||||
|
||||
-- ------------
|
||||
-- Package Body
|
||||
-- ------------
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('-- Name : ' || Lower(v_table_name) || '_api.pkg');
|
||||
DBMS_Output.Put_Line('-- Created By : Tim Hall');
|
||||
DBMS_Output.Put_Line('-- Created Date: ' || To_Char(Sysdate, 'DD-Mon-YYYY'));
|
||||
DBMS_Output.Put_Line('-- Description : API procedures for the ' || v_table_name || ' table.');
|
||||
DBMS_Output.Put_Line('-- Ammendments :');
|
||||
DBMS_Output.Put_Line('-- ' || To_Char(Sysdate, 'DD-Mon-YYYY') || ' TSH Initial Creation');
|
||||
DBMS_Output.Put_Line('-- -----------------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('CREATE OR REPLACE PACKAGE BODY ' || Lower(v_table_name) || '_api AS');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
-- Select
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line('PROCEDURE Sel (');
|
||||
GetPKParameterList(FALSE);
|
||||
DBMS_Output.New_Line;
|
||||
DBMS_Output.Put_Line(Chr(9) || RPad('p_recordset', 32, ' ') || ' OUT cursor_type');
|
||||
DBMS_Output.Put_Line(') IS');
|
||||
GetSeparator;
|
||||
|
||||
DBMS_Output.Put_Line('BEGIN');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line(Chr(9) || 'OPEN p_recordset FOR');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'SELECT');
|
||||
GetInsertColumnList;
|
||||
DBMS_Output.Put_Line(Chr(9) || 'FROM ' || Lower(v_table_name));
|
||||
GetPKWhere;
|
||||
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
DBMS_Output.Put_Line('END Sel;');
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
|
||||
-- Insert
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line('PROCEDURE Ins (');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad(Lower(v_table_name), 30, ' ') || ' IN ' || Lower(v_table_name) || '%ROWTYPE,');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad('commit', 30, ' ') || ' IN VARCHAR2 DEFAULT ''Y''');
|
||||
DBMS_Output.Put_Line(') IS');
|
||||
GetSeparator;
|
||||
|
||||
DBMS_Output.Put_Line('BEGIN');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line(Chr(9) || 'INSERT INTO ' || Lower(v_table_name));
|
||||
DBMS_Output.Put_Line(Chr(9) || '(');
|
||||
GetInsertColumnList;
|
||||
DBMS_Output.Put_Line(Chr(9) || ')');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'VALUES');
|
||||
DBMS_Output.Put_Line(Chr(9) || '(');
|
||||
GetInsertValueList;
|
||||
DBMS_Output.Put_Line(Chr(9) || ');');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
GetCommit;
|
||||
DBMS_Output.Put_Line('END Ins;');
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
-- Update
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line('PROCEDURE Upd (');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad(Lower(v_table_name), 30, ' ') || ' IN ' || Lower(v_table_name) || '%ROWTYPE,');
|
||||
DBMS_Output.Put_Line(Chr(9) || 'p_' || RPad('commit', 30, ' ') || ' IN VARCHAR2 DEFAULT ''Y''');
|
||||
DBMS_Output.Put_Line(') IS');
|
||||
GetSeparator;
|
||||
|
||||
DBMS_Output.Put_Line('BEGIN');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
DBMS_Output.Put_Line(Chr(9) || 'UPDATE ' || Lower(v_table_name));
|
||||
GetUpdateSetList;
|
||||
GetPKWhere('Y');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
GetCommit;
|
||||
DBMS_Output.Put_Line('END Upd;');
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
-- Delete
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line('PROCEDURE Del (');
|
||||
GetPKParameterList;
|
||||
DBMS_Output.Put_Line(') IS');
|
||||
GetSeparator;
|
||||
|
||||
DBMS_Output.Put_Line('BEGIN');
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
DBMS_Output.Put_Line(Chr(9) || 'DELETE FROM ' || Lower(v_table_name));
|
||||
GetPKWhere;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
GetCommit;
|
||||
DBMS_Output.Put_Line('END Del;');
|
||||
GetSeparator;
|
||||
DBMS_Output.Put_Line(Chr(9));
|
||||
|
||||
DBMS_Output.Put_Line('END ' || Lower(v_table_name) || '_api;');
|
||||
DBMS_Output.Put_Line('/');
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
SPOOL OFF
|
||||
|
||||
SET ECHO ON
|
||||
SET TERMOUT ON
|
||||
SET FEEDBACK ON
|
||||
90
timhall/script_creation/create_data.sql
Normal file
90
timhall/script_creation/create_data.sql
Normal file
@@ -0,0 +1,90 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/create_data.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL to repopulate the specified table.
|
||||
-- Call Syntax : @create_data (table-name) (schema)
|
||||
-- Last Modified: 28/01/2001
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LINESIZE 1000
|
||||
SET SERVEROUTPUT ON
|
||||
SET FEEDBACK OFF
|
||||
SET PAGESIZE 0
|
||||
SET VERIFY OFF
|
||||
SET TRIMSPOOL ON
|
||||
SET TRIMOUT ON
|
||||
|
||||
ALTER SESSION SET nls_date_format = 'DD-MON-YYYY HH24:MI:SS';
|
||||
|
||||
SPOOL temp.sql
|
||||
|
||||
DECLARE
|
||||
|
||||
CURSOR c_columns (p_table_name IN VARCHAR2,
|
||||
p_owner IN VARCHAR2) IS
|
||||
SELECT Lower(a.column_name) column_name,
|
||||
a.data_type
|
||||
FROM all_tab_columns a
|
||||
WHERE a.table_name = p_table_name
|
||||
AND a.owner = p_owner
|
||||
AND a.data_type IN ('CHAR','VARCHAR2','DATE','NUMBER','INTEGER');
|
||||
|
||||
v_table_name VARCHAR2(30) := Upper('&&1');
|
||||
v_owner VARCHAR2(30) := Upper('&&2');
|
||||
|
||||
|
||||
FUNCTION Format_Col(p_column IN VARCHAR2,
|
||||
p_datatype IN VARCHAR2)
|
||||
RETURN VARCHAR2 IS
|
||||
BEGIN
|
||||
IF p_datatype IN ('CHAR','VARCHAR2','DATE') THEN
|
||||
RETURN ''' || Decode(' || p_column || ',NULL,''NULL'','''''''' || ' || p_column || ' || '''''''') || ''';
|
||||
ELSE
|
||||
RETURN ''' || Decode(' || p_column || ',NULL,''NULL'',' || p_column || ') || ''';
|
||||
END IF;
|
||||
END;
|
||||
|
||||
BEGIN
|
||||
|
||||
Dbms_Output.Disable;
|
||||
Dbms_Output.Enable(1000000);
|
||||
|
||||
Dbms_Output.Put_Line('SELECT ''INSERT INTO ' || Lower(v_owner) || '.' || Lower(v_table_name));
|
||||
Dbms_Output.Put_Line('(');
|
||||
<< Columns_Loop >>
|
||||
FOR cur_rec IN c_columns (v_table_name, v_owner) LOOP
|
||||
IF c_columns%ROWCOUNT != 1 THEN
|
||||
Dbms_Output.Put_Line(',');
|
||||
END IF;
|
||||
Dbms_Output.Put(cur_rec.column_name);
|
||||
END LOOP Columns_Loop;
|
||||
Dbms_Output.New_Line;
|
||||
Dbms_Output.Put_Line(')');
|
||||
Dbms_Output.Put_Line('VALUES');
|
||||
Dbms_Output.Put_Line('(');
|
||||
|
||||
<< Data_Loop >>
|
||||
FOR cur_rec IN c_columns (v_table_name, v_owner) LOOP
|
||||
IF c_columns%ROWCOUNT != 1 THEN
|
||||
Dbms_Output.Put_Line(',');
|
||||
END IF;
|
||||
Dbms_Output.Put(Format_Col(cur_rec.column_name, cur_rec.data_type));
|
||||
END LOOP Data_Loop;
|
||||
Dbms_Output.New_Line;
|
||||
Dbms_Output.Put_Line(');''');
|
||||
Dbms_Output.Put_Line('FROM ' || Lower(v_owner) || '.' || Lower(v_table_name) );
|
||||
Dbms_Output.Put_Line('/');
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
SPOOL OFF
|
||||
|
||||
SET LINESIZE 1000
|
||||
SPOOL table_data.sql
|
||||
|
||||
@temp.sql
|
||||
|
||||
SPOOL OFF
|
||||
|
||||
SET PAGESIZE 14
|
||||
SET FEEDBACK ON
|
||||
20
timhall/script_creation/db_link_ddl.sql
Normal file
20
timhall/script_creation/db_link_ddl.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/db_link_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for DB links for the specific schema, or all schemas.
|
||||
-- Call Syntax : @db_link_ddl (schema or all)
|
||||
-- Last Modified: 16/03/2013
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('DB_LINK', db_link, owner)
|
||||
FROM dba_db_links
|
||||
WHERE owner = DECODE(UPPER('&1'), 'ALL', owner, UPPER('&1'));
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 1000 FEEDBACK ON VERIFY ON
|
||||
20
timhall/script_creation/directory_ddl.sql
Normal file
20
timhall/script_creation/directory_ddl.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/directory_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for specified directory, or all directories.
|
||||
-- Call Syntax : @directory_ddl (directory or all)
|
||||
-- Last Modified: 16/03/2013
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('DIRECTORY', directory_name)
|
||||
FROM dba_directories
|
||||
WHERE directory_name = DECODE(UPPER('&1'), 'ALL', directory_name, UPPER('&1'));
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 1000 FEEDBACK ON VERIFY ON
|
||||
75
timhall/script_creation/drop_cons_on_table.sql
Normal file
75
timhall/script_creation/drop_cons_on_table.sql
Normal file
@@ -0,0 +1,75 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/drop_cons_on_table.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL to drop the UK & PK constraints on the specified table, or all tables.
|
||||
-- Call Syntax : @drop_cons_on_table (table-name or all) (schema)
|
||||
-- Last Modified: 28/01/2001
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET SERVEROUTPUT ON
|
||||
SET LINESIZE 100
|
||||
SET VERIFY OFF
|
||||
SET FEEDBACK OFF
|
||||
PROMPT
|
||||
|
||||
DECLARE
|
||||
|
||||
CURSOR cu_cons IS
|
||||
SELECT *
|
||||
FROM all_constraints a
|
||||
WHERE a.table_name = Decode(Upper('&&1'),'ALL',a.table_name,Upper('&&1'))
|
||||
AND a.owner = Upper('&&2')
|
||||
AND a.constraint_type IN ('P','U');
|
||||
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
FUNCTION Con_Columns(p_tab IN VARCHAR2,
|
||||
p_con IN VARCHAR2)
|
||||
RETURN VARCHAR2 IS
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
CURSOR cu_col_cursor IS
|
||||
SELECT a.column_name
|
||||
FROM all_cons_columns a
|
||||
WHERE a.table_name = p_tab
|
||||
AND a.constraint_name = p_con
|
||||
AND a.owner = Upper('&&2')
|
||||
ORDER BY a.position;
|
||||
|
||||
l_result VARCHAR2(1000);
|
||||
BEGIN
|
||||
FOR cur_rec IN cu_col_cursor LOOP
|
||||
IF cu_col_cursor%ROWCOUNT = 1 THEN
|
||||
l_result := cur_rec.column_name;
|
||||
ELSE
|
||||
l_result := l_result || ',' || cur_rec.column_name;
|
||||
END IF;
|
||||
END LOOP;
|
||||
RETURN Lower(l_result);
|
||||
END;
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
BEGIN
|
||||
|
||||
DBMS_Output.Disable;
|
||||
DBMS_Output.Enable(1000000);
|
||||
DBMS_Output.Put_Line('PROMPT');
|
||||
DBMS_Output.Put_Line('PROMPT Droping Constraints on ' || Upper('&&1'));
|
||||
FOR cur_rec IN cu_cons LOOP
|
||||
IF cur_rec.constraint_type = 'P' THEN
|
||||
DBMS_Output.Put_Line('ALTER TABLE ' || Lower(cur_rec.table_name) || ' DROP PRIMARY KEY;');
|
||||
ELSIF cur_rec.constraint_type = 'R' THEN
|
||||
DBMS_Output.Put_Line('ALTER TABLE ' || Lower(cur_rec.table_name) || ' DROP CONSTRAINT ' || Lower(cur_rec.constraint_name) || ';');
|
||||
ELSIF cur_rec.constraint_type = 'U' THEN
|
||||
DBMS_Output.Put_Line('ALTER TABLE ' || Lower(cur_rec.table_name) || ' DROP UNIQUE (' || Con_Columns(cur_rec.table_name, cur_rec.constraint_name) || ');');
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
PROMPT
|
||||
SET VERIFY ON
|
||||
SET FEEDBACK ON
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
43
timhall/script_creation/drop_fks_on_table.sql
Normal file
43
timhall/script_creation/drop_fks_on_table.sql
Normal file
@@ -0,0 +1,43 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/drop_fks_on_table.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL to drop the foreign keys on the specified table.
|
||||
-- Call Syntax : @drop_fks_on_table (table-name) (schema)
|
||||
-- Last Modified: 28/01/2001
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET SERVEROUTPUT ON
|
||||
SET LINESIZE 100
|
||||
SET VERIFY OFF
|
||||
SET FEEDBACK OFF
|
||||
PROMPT
|
||||
|
||||
DECLARE
|
||||
|
||||
CURSOR cu_fks IS
|
||||
SELECT *
|
||||
FROM all_constraints a
|
||||
WHERE a.constraint_type = 'R'
|
||||
AND a.table_name = Decode(Upper('&&1'),'ALL',a.table_name,Upper('&&1'))
|
||||
AND a.owner = Upper('&&2');
|
||||
|
||||
BEGIN
|
||||
|
||||
DBMS_Output.Disable;
|
||||
DBMS_Output.Enable(1000000);
|
||||
DBMS_Output.Put_Line('PROMPT');
|
||||
DBMS_Output.Put_Line('PROMPT Droping Foreign Keys on ' || Upper('&&1'));
|
||||
FOR cur_rec IN cu_fks LOOP
|
||||
DBMS_Output.Put_Line('ALTER TABLE ' || Lower(cur_rec.table_name) || ' DROP CONSTRAINT ' || Lower(cur_rec.constraint_name) || ';');
|
||||
END LOOP;
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
PROMPT
|
||||
SET VERIFY ON
|
||||
SET FEEDBACK ON
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
44
timhall/script_creation/drop_fks_ref_table.sql
Normal file
44
timhall/script_creation/drop_fks_ref_table.sql
Normal file
@@ -0,0 +1,44 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/drop_fks_ref_table.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL to drop the foreign keys that referenece the specified table.
|
||||
-- Call Syntax : @drop_fks_ref_table (table-name) (schema)
|
||||
-- Last Modified: 28/01/2001
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET SERVEROUTPUT ON
|
||||
SET LINESIZE 100
|
||||
SET VERIFY OFF
|
||||
SET FEEDBACK OFF
|
||||
PROMPT
|
||||
|
||||
DECLARE
|
||||
|
||||
CURSOR cu_fks IS
|
||||
SELECT *
|
||||
FROM all_constraints a
|
||||
WHERE a.owner = Upper('&&2')
|
||||
AND a.constraint_type = 'R'
|
||||
AND a.r_constraint_name IN (SELECT a1.constraint_name
|
||||
FROM all_constraints a1
|
||||
WHERE a1.table_name = Upper('&&1')
|
||||
AND a1.owner = Upper('&&2'));
|
||||
|
||||
BEGIN
|
||||
|
||||
DBMS_Output.Put_Line('PROMPT');
|
||||
DBMS_Output.Put_Line('PROMPT Droping Foreign Keys to ' || Upper('&&1'));
|
||||
FOR cur_rec IN cu_fks LOOP
|
||||
DBMS_Output.Put_Line('ALTER TABLE ' || Lower(cur_rec.table_name) || ' DROP CONSTRAINT ' || Lower(cur_rec.constraint_name) || ';');
|
||||
END LOOP;
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
PROMPT
|
||||
SET VERIFY ON
|
||||
SET FEEDBACK ON
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
42
timhall/script_creation/drop_indexes.sql
Normal file
42
timhall/script_creation/drop_indexes.sql
Normal file
@@ -0,0 +1,42 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/drop_indexes.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL to drop the indexes on the specified table, or all tables.
|
||||
-- Call Syntax : @drop_indexes (table-name or all) (schema)
|
||||
-- Last Modified: 28/01/2001
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET SERVEROUTPUT ON
|
||||
SET LINESIZE 100
|
||||
SET VERIFY OFF
|
||||
SET FEEDBACK OFF
|
||||
PROMPT
|
||||
|
||||
DECLARE
|
||||
|
||||
CURSOR cu_idx IS
|
||||
SELECT *
|
||||
FROM all_indexes a
|
||||
WHERE a.table_name = Decode(Upper('&&1'),'ALL',a.table_name,Upper('&&1'))
|
||||
AND a.owner = Upper('&&2');
|
||||
|
||||
BEGIN
|
||||
|
||||
DBMS_Output.Disable;
|
||||
DBMS_Output.Enable(1000000);
|
||||
DBMS_Output.Put_Line('PROMPT');
|
||||
DBMS_Output.Put_Line('PROMPT Droping Indexes on ' || Upper('&&1'));
|
||||
FOR cur_rec IN cu_idx LOOP
|
||||
DBMS_Output.Put_Line('DROP INDEX ' || Lower(cur_rec.index_name) || ';');
|
||||
END LOOP;
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
PROMPT
|
||||
SET VERIFY ON
|
||||
SET FEEDBACK ON
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
22
timhall/script_creation/fks_on_table_ddl.sql
Normal file
22
timhall/script_creation/fks_on_table_ddl.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/fks_on_table_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for the foreign keys on the specified table, or all tables.
|
||||
-- Call Syntax : @fks_on_table_ddl (schema) (table-name or all)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('REF_CONSTRAINT', constraint_name, owner)
|
||||
FROM all_constraints
|
||||
WHERE owner = UPPER('&1')
|
||||
AND table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'))
|
||||
AND constraint_type = 'R';
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
24
timhall/script_creation/fks_ref_table_ddl.sql
Normal file
24
timhall/script_creation/fks_ref_table_ddl.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/fks_ref_table_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for the foreign keys that reference the specified table.
|
||||
-- Call Syntax : @fks_ref_table_ddl (schema) (table-name)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('REF_CONSTRAINT', ac1.constraint_name, ac1.owner)
|
||||
FROM all_constraints ac1
|
||||
JOIN all_constraints ac2 ON ac1.r_owner = ac2.owner AND ac1.r_constraint_name = ac2.constraint_name
|
||||
WHERE ac2.owner = UPPER('&1')
|
||||
AND ac2.table_name = UPPER('&2')
|
||||
AND ac2.constraint_type IN ('P','U')
|
||||
AND ac1.constraint_type = 'R';
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
24
timhall/script_creation/index_monitoring_off.sql
Normal file
24
timhall/script_creation/index_monitoring_off.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/index_monitoring_on.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Sets monitoring off for the specified table indexes.
|
||||
-- Call Syntax : @index_monitoring_on (schema) (table-name or all)
|
||||
-- Last Modified: 04/02/2005
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET PAGESIZE 0
|
||||
SET FEEDBACK OFF
|
||||
SET VERIFY OFF
|
||||
SPOOL temp.sql
|
||||
|
||||
SELECT 'ALTER INDEX "' || i.owner || '"."' || i.index_name || '" NOMONITORING USAGE;'
|
||||
FROM dba_indexes i
|
||||
WHERE owner = UPPER('&1')
|
||||
AND table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'));
|
||||
|
||||
SPOOL OFF
|
||||
|
||||
SET PAGESIZE 18
|
||||
SET FEEDBACK ON
|
||||
|
||||
@temp.sql
|
||||
|
||||
24
timhall/script_creation/index_monitoring_on.sql
Normal file
24
timhall/script_creation/index_monitoring_on.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/index_monitoring_on.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Sets monitoring on for the specified table indexes.
|
||||
-- Call Syntax : @index_monitoring_on (schema) (table-name or all)
|
||||
-- Last Modified: 04/02/2005
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET PAGESIZE 0
|
||||
SET FEEDBACK OFF
|
||||
SET VERIFY OFF
|
||||
SPOOL temp.sql
|
||||
|
||||
SELECT 'ALTER INDEX "' || i.owner || '"."' || i.index_name || '" MONITORING USAGE;'
|
||||
FROM dba_indexes i
|
||||
WHERE owner = UPPER('&1')
|
||||
AND table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'));
|
||||
|
||||
SPOOL OFF
|
||||
|
||||
SET PAGESIZE 18
|
||||
SET FEEDBACK ON
|
||||
|
||||
@temp.sql
|
||||
|
||||
21
timhall/script_creation/job_ddl.sql
Normal file
21
timhall/script_creation/job_ddl.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/job_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for the specified job.
|
||||
-- Call Syntax : @job_ddl (schema-name) (job-name)
|
||||
-- Last Modified: 31/12/2018
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('PROCOBJ', job_name, owner)
|
||||
FROM all_scheduler_jobs
|
||||
WHERE owner = UPPER('&1')
|
||||
AND job_name = DECODE(UPPER('&2'), 'ALL', job_name, UPPER('&2'));
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
32
timhall/script_creation/logon_as_user.sql
Normal file
32
timhall/script_creation/logon_as_user.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/logon_as_user.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Displays the DDL for a specific user.
|
||||
-- Better approaches included here.
|
||||
-- https://oracle-base.com/articles/misc/proxy-users-and-connect-through
|
||||
-- Call Syntax : @logon_as_user (username)
|
||||
-- Last Modified: 28/01/2006 - Added link to article.
|
||||
-- -----------------------------------------------------------------------------------
|
||||
|
||||
set serveroutput on verify off
|
||||
declare
|
||||
l_username VARCHAR2(30) := upper('&1');
|
||||
l_orig_pwd VARCHAR2(32767);
|
||||
begin
|
||||
select password
|
||||
into l_orig_pwd
|
||||
from sys.user$
|
||||
where name = l_username;
|
||||
|
||||
dbms_output.put_line('--');
|
||||
dbms_output.put_line('alter user ' || l_username || ' identified by DummyPassword1;');
|
||||
dbms_output.put_line('conn ' || l_username || '/DummyPassword1');
|
||||
|
||||
dbms_output.put_line('--');
|
||||
dbms_output.put_line('-- Do something here.');
|
||||
dbms_output.put_line('--');
|
||||
|
||||
dbms_output.put_line('conn / as sysdba');
|
||||
dbms_output.put_line('alter user ' || l_username || ' identified by values '''||l_orig_pwd||''';');
|
||||
end;
|
||||
/
|
||||
32
timhall/script_creation/logon_as_user_orig.sql
Normal file
32
timhall/script_creation/logon_as_user_orig.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/logon_as_user_orig.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Displays the DDL for a specific user.
|
||||
-- Better approaches included here.
|
||||
-- https://oracle-base.com/articles/misc/proxy-users-and-connect-through
|
||||
-- Call Syntax : @logon_as_user_orig (username)
|
||||
-- Last Modified: 06/06/2019 - Added link to article.
|
||||
-- -----------------------------------------------------------------------------------
|
||||
|
||||
set serveroutput on verify off
|
||||
declare
|
||||
l_username VARCHAR2(30) := upper('&1');
|
||||
l_orig_pwd VARCHAR2(32767);
|
||||
begin
|
||||
select password
|
||||
into l_orig_pwd
|
||||
from dba_users
|
||||
where username = l_username;
|
||||
|
||||
dbms_output.put_line('--');
|
||||
dbms_output.put_line('alter user ' || l_username || ' identified by DummyPassword1;');
|
||||
dbms_output.put_line('conn ' || l_username || '/DummyPassword1');
|
||||
|
||||
dbms_output.put_line('--');
|
||||
dbms_output.put_line('-- Do something here.');
|
||||
dbms_output.put_line('--');
|
||||
|
||||
dbms_output.put_line('conn / as sysdba');
|
||||
dbms_output.put_line('alter user ' || l_username || ' identified by values '''||l_orig_pwd||''';');
|
||||
end;
|
||||
/
|
||||
25
timhall/script_creation/monitoring_off.sql
Normal file
25
timhall/script_creation/monitoring_off.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/monitoring_on.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Sets monitoring off for the specified tables.
|
||||
-- Call Syntax : @monitoring_on (schema) (table-name or all)
|
||||
-- Last Modified: 21/03/2003
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET PAGESIZE 0
|
||||
SET FEEDBACK OFF
|
||||
SET VERIFY OFF
|
||||
SPOOL temp.sql
|
||||
|
||||
SELECT 'ALTER TABLE "' || owner || '"."' || table_name || '" NOMONITORING;'
|
||||
FROM dba_tables
|
||||
WHERE owner = UPPER('&1')
|
||||
AND table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'))
|
||||
AND monitoring = 'YES';
|
||||
|
||||
SPOOL OFF
|
||||
|
||||
SET PAGESIZE 18
|
||||
SET FEEDBACK ON
|
||||
|
||||
@temp.sql
|
||||
|
||||
25
timhall/script_creation/monitoring_on.sql
Normal file
25
timhall/script_creation/monitoring_on.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/monitoring_on.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Sets monitoring on for the specified tables.
|
||||
-- Call Syntax : @monitoring_on (schema) (table-name or all)
|
||||
-- Last Modified: 21/03/2003
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET PAGESIZE 0
|
||||
SET FEEDBACK OFF
|
||||
SET VERIFY OFF
|
||||
SPOOL temp.sql
|
||||
|
||||
SELECT 'ALTER TABLE "' || owner || '"."' || table_name || '" MONITORING;'
|
||||
FROM dba_tables
|
||||
WHERE owner = UPPER('&1')
|
||||
AND table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'))
|
||||
AND monitoring != 'YES';
|
||||
|
||||
SPOOL OFF
|
||||
|
||||
SET PAGESIZE 18
|
||||
SET FEEDBACK ON
|
||||
|
||||
@temp.sql
|
||||
|
||||
107
timhall/script_creation/network_acls_ddl.sql
Normal file
107
timhall/script_creation/network_acls_ddl.sql
Normal file
@@ -0,0 +1,107 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/11g/network_acls_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Displays DDL for all network ACLs.
|
||||
-- Requirements : Access to the DBA views.
|
||||
-- Call Syntax : @network_acls_ddl
|
||||
-- Last Modified: 28-JUL-2017
|
||||
-- -----------------------------------------------------------------------------------
|
||||
|
||||
SET SERVEROUTPUT ON FORMAT WRAPPED LINESIZE 300
|
||||
DECLARE
|
||||
l_last_acl dba_network_acls.acl%TYPE := '~';
|
||||
l_last_principal dba_network_acl_privileges.principal%TYPE := '~';
|
||||
l_last_privilege dba_network_acl_privileges.privilege%TYPE := '~';
|
||||
l_last_host dba_network_acls.host%TYPE := '~';
|
||||
|
||||
FUNCTION get_timestamp (p_timestamp IN TIMESTAMP WITH TIME ZONE)
|
||||
RETURN VARCHAR2
|
||||
AS
|
||||
l_return VARCHAR2(32767);
|
||||
BEGIN
|
||||
IF p_timestamp IS NULL THEN
|
||||
RETURN 'NULL';
|
||||
END IF;
|
||||
RETURN 'TO_TIMESTAMP_TZ(''' || TO_CHAR(p_timestamp, 'DD-MON-YYYY HH24:MI:SS.FF TZH:TZM') || ''',''DD-MON-YYYY HH24:MI:SS.FF TZH:TZM'')';
|
||||
END;
|
||||
BEGIN
|
||||
FOR i IN (SELECT a.acl,
|
||||
a.host,
|
||||
a.lower_port,
|
||||
a.upper_port,
|
||||
b.principal,
|
||||
b.privilege,
|
||||
b.is_grant,
|
||||
b.start_date,
|
||||
b.end_date
|
||||
FROM dba_network_acls a
|
||||
JOIN dba_network_acl_privileges b ON a.acl = b.acl
|
||||
ORDER BY a.acl, a.host, a.lower_port, a.upper_port)
|
||||
LOOP
|
||||
IF l_last_acl <> i.acl THEN
|
||||
-- First time we've seen this ACL, so create a new one.
|
||||
l_last_host := '~';
|
||||
|
||||
DBMS_OUTPUT.put_line('-- -------------------------------------------------');
|
||||
DBMS_OUTPUT.put_line('-- ' || i.acl);
|
||||
DBMS_OUTPUT.put_line('-- -------------------------------------------------');
|
||||
DBMS_OUTPUT.put_line('BEGIN');
|
||||
DBMS_OUTPUT.put_line(' DBMS_NETWORK_ACL_ADMIN.drop_acl (');
|
||||
DBMS_OUTPUT.put_line(' acl => ''' || i.acl || ''');');
|
||||
DBMS_OUTPUT.put_line(' COMMIT;');
|
||||
DBMS_OUTPUT.put_line('END;');
|
||||
DBMS_OUTPUT.put_line('/');
|
||||
DBMS_OUTPUT.put_line(' ');
|
||||
DBMS_OUTPUT.put_line('BEGIN');
|
||||
DBMS_OUTPUT.put_line(' DBMS_NETWORK_ACL_ADMIN.create_acl (');
|
||||
DBMS_OUTPUT.put_line(' acl => ''' || i.acl || ''',');
|
||||
DBMS_OUTPUT.put_line(' description => ''' || i.acl || ''',');
|
||||
DBMS_OUTPUT.put_line(' principal => ''' || i.principal || ''',');
|
||||
DBMS_OUTPUT.put_line(' is_grant => ' || i.is_grant || ',');
|
||||
DBMS_OUTPUT.put_line(' privilege => ''' || i.privilege || ''',');
|
||||
DBMS_OUTPUT.put_line(' start_date => ' || get_timestamp(i.start_date) || ',');
|
||||
DBMS_OUTPUT.put_line(' end_date => ' || get_timestamp(i.end_date) || ');');
|
||||
DBMS_OUTPUT.put_line(' COMMIT;');
|
||||
DBMS_OUTPUT.put_line('END;');
|
||||
DBMS_OUTPUT.put_line('/');
|
||||
DBMS_OUTPUT.put_line(' ');
|
||||
l_last_acl := i.acl;
|
||||
l_last_principal := i.principal;
|
||||
l_last_privilege := i.privilege;
|
||||
END IF;
|
||||
|
||||
IF l_last_principal <> i.principal
|
||||
OR (l_last_principal = i.principal AND l_last_privilege <> i.privilege) THEN
|
||||
-- Add another principal to an existing ACL.
|
||||
DBMS_OUTPUT.put_line('BEGIN');
|
||||
DBMS_OUTPUT.put_line(' DBMS_NETWORK_ACL_ADMIN.add_privilege (');
|
||||
DBMS_OUTPUT.put_line(' acl => ''' || i.acl || ''',');
|
||||
DBMS_OUTPUT.put_line(' principal => ''' || i.principal || ''',');
|
||||
DBMS_OUTPUT.put_line(' is_grant => ' || i.is_grant || ',');
|
||||
DBMS_OUTPUT.put_line(' privilege => ''' || i.privilege || ''',');
|
||||
DBMS_OUTPUT.put_line(' start_date => ' || get_timestamp(i.start_date) || ',');
|
||||
DBMS_OUTPUT.put_line(' end_date => ' || get_timestamp(i.end_date) || ');');
|
||||
DBMS_OUTPUT.put_line(' COMMIT;');
|
||||
DBMS_OUTPUT.put_line('END;');
|
||||
DBMS_OUTPUT.put_line('/');
|
||||
DBMS_OUTPUT.put_line(' ');
|
||||
l_last_principal := i.principal;
|
||||
l_last_privilege := i.privilege;
|
||||
END IF;
|
||||
|
||||
IF l_last_host <> i.host||':'||i.lower_port||':'||i.upper_port THEN
|
||||
DBMS_OUTPUT.put_line('BEGIN');
|
||||
DBMS_OUTPUT.put_line(' DBMS_NETWORK_ACL_ADMIN.assign_acl (');
|
||||
DBMS_OUTPUT.put_line(' acl => ''' || i.acl || ''',');
|
||||
DBMS_OUTPUT.put_line(' host => ''' || i.host || ''',');
|
||||
DBMS_OUTPUT.put_line(' lower_port => ' || NVL(TO_CHAR(i.lower_port),'NULL') || ',');
|
||||
DBMS_OUTPUT.put_line(' upper_port => ' || NVL(TO_CHAR(i.upper_port),'NULL') || ');');
|
||||
DBMS_OUTPUT.put_line(' COMMIT;');
|
||||
DBMS_OUTPUT.put_line('END;');
|
||||
DBMS_OUTPUT.put_line('/');
|
||||
DBMS_OUTPUT.put_line(' ');
|
||||
l_last_host := i.host||':'||i.lower_port||':'||i.upper_port;
|
||||
END IF;
|
||||
END LOOP;
|
||||
END;
|
||||
/
|
||||
21
timhall/script_creation/object_grants.sql
Normal file
21
timhall/script_creation/object_grants.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/object_grants.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Displays the DDL for all grants on a specific object.
|
||||
-- Call Syntax : @object_grants (owner) (object_name)
|
||||
-- Last Modified: 28/01/2006
|
||||
-- -----------------------------------------------------------------------------------
|
||||
|
||||
set long 1000000 linesize 1000 pagesize 0 feedback off trimspool on verify off
|
||||
column ddl format a1000
|
||||
|
||||
begin
|
||||
dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'SQLTERMINATOR', true);
|
||||
dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'PRETTY', true);
|
||||
end;
|
||||
/
|
||||
|
||||
select dbms_metadata.get_dependent_ddl('OBJECT_GRANT', UPPER('&2'), UPPER('&1')) AS ddl
|
||||
from dual;
|
||||
|
||||
set linesize 80 pagesize 14 feedback on trimspool on verify on
|
||||
23
timhall/script_creation/profile_ddl.sql
Normal file
23
timhall/script_creation/profile_ddl.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/profile_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Displays the DDL for the specified profile(s).
|
||||
-- Call Syntax : @profile_ddl (profile | part of profile)
|
||||
-- Last Modified: 28/01/2006
|
||||
-- -----------------------------------------------------------------------------------
|
||||
|
||||
set long 20000 longchunksize 20000 pagesize 0 linesize 1000 feedback off verify off trimspool on
|
||||
column ddl format a1000
|
||||
|
||||
begin
|
||||
dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'SQLTERMINATOR', true);
|
||||
dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'PRETTY', true);
|
||||
end;
|
||||
/
|
||||
|
||||
select dbms_metadata.get_ddl('PROFILE', profile) as profile_ddl
|
||||
from (select distinct profile
|
||||
from dba_profiles)
|
||||
where profile like upper('%&1%');
|
||||
|
||||
set linesize 80 pagesize 14 feedback on verify on
|
||||
58
timhall/script_creation/rbs_structure.sql
Normal file
58
timhall/script_creation/rbs_structure.sql
Normal file
@@ -0,0 +1,58 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/rbs_structure.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for specified segment, or all segments.
|
||||
-- Call Syntax : @rbs_structure (segment-name or all)
|
||||
-- Last Modified: 28/01/2001
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET SERVEROUTPUT ON
|
||||
SET LINESIZE 100
|
||||
SET VERIFY OFF
|
||||
SET FEEDBACK OFF
|
||||
PROMPT
|
||||
|
||||
DECLARE
|
||||
|
||||
CURSOR cu_rs IS
|
||||
SELECT a.segment_name,
|
||||
a.tablespace_name,
|
||||
a.initial_extent,
|
||||
a.next_extent,
|
||||
a.min_extents,
|
||||
a.max_extents,
|
||||
a.pct_increase,
|
||||
b.bytes
|
||||
FROM dba_rollback_segs a,
|
||||
dba_segments b
|
||||
WHERE a.segment_name = b.segment_name
|
||||
AND a.segment_name = Decode(Upper('&&1'), 'ALL',a.segment_name, Upper('&&1'))
|
||||
ORDER BY a.segment_name;
|
||||
|
||||
BEGIN
|
||||
|
||||
DBMS_Output.Disable;
|
||||
DBMS_Output.Enable(1000000);
|
||||
|
||||
FOR cur_rs IN cu_rs LOOP
|
||||
DBMS_Output.Put_Line('PROMPT');
|
||||
DBMS_Output.Put_Line('PROMPT Creating Rollback Segment ' || cur_rs.segment_name);
|
||||
DBMS_Output.Put_Line('CREATE ROLLBACK SEGMENT ' || Lower(cur_rs.segment_name));
|
||||
DBMS_Output.Put_Line('TABLESPACE ' || Lower(cur_rs.tablespace_name));
|
||||
DBMS_Output.Put_Line('STORAGE (');
|
||||
DBMS_Output.Put_Line(' INITIAL ' || Trunc(cur_rs.initial_extent/1024) || 'K');
|
||||
DBMS_Output.Put_Line(' NEXT ' || Trunc(cur_rs.next_extent/1024) || 'K');
|
||||
DBMS_Output.Put_Line(' MINEXTENTS ' || cur_rs.min_extents);
|
||||
DBMS_Output.Put_Line(' MAXEXTENTS ' || cur_rs.max_extents);
|
||||
DBMS_Output.Put_Line(' PCTINCREASE ' || cur_rs.pct_increase);
|
||||
DBMS_Output.Put_Line(' )');
|
||||
DBMS_Output.Put_Line('/');
|
||||
DBMS_Output.Put_Line(' ');
|
||||
END LOOP;
|
||||
|
||||
DBMS_Output.Put_Line(' ');
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
SET VERIFY ON
|
||||
SET FEEDBACK ON
|
||||
148
timhall/script_creation/recreate_table.sql
Normal file
148
timhall/script_creation/recreate_table.sql
Normal file
@@ -0,0 +1,148 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/recreate_table.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL to recreate the specified table.
|
||||
-- Comments : Mostly used when dropping columns prior to Oracle 8i. Not updated since Oracle 7.3.4.
|
||||
-- Requirements : Requires a number of the other creation scripts.
|
||||
-- Call Syntax : @recreate_table (table-name) (schema-name)
|
||||
-- Last Modified: 28/01/2001
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET SERVEROUTPUT ON
|
||||
SET LINESIZE 100
|
||||
SET VERIFY OFF
|
||||
SET FEEDBACK OFF
|
||||
SET TERMOUT OFF
|
||||
SPOOL ReCreate_&&1
|
||||
PROMPT
|
||||
|
||||
-- ----------------------------------------------
|
||||
-- Reset the buffer size and display script title
|
||||
-- ----------------------------------------------
|
||||
BEGIN
|
||||
DBMS_Output.Disable;
|
||||
DBMS_Output.Enable(1000000);
|
||||
DBMS_Output.Put_Line('-------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('-- Author : Tim Hall');
|
||||
DBMS_Output.Put_Line('-- Creation Date : ' || To_Char(SYSDATE,'DD/MM/YYYY HH24:MI:SS'));
|
||||
DBMS_Output.Put_Line('-- Description : Re-creation script for ' || Upper('&&1'));
|
||||
DBMS_Output.Put_Line('-------------------------------------------------------------');
|
||||
END;
|
||||
/
|
||||
|
||||
-- ------------------------------------
|
||||
-- Drop existing FKs to specified table
|
||||
-- ------------------------------------
|
||||
@Drop_FKs_Ref_Table &&1 &&2
|
||||
|
||||
-- -----------------
|
||||
-- Drop FKs on table
|
||||
-- -----------------
|
||||
@Drop_FKs_On_Table &&1 &&2
|
||||
|
||||
-- -------------------------
|
||||
-- Drop constraints on table
|
||||
-- -------------------------
|
||||
@Drop_Cons_On_Table &&1 &&2
|
||||
|
||||
-- ---------------------
|
||||
-- Drop indexes on table
|
||||
-- ---------------------
|
||||
@Drop_Indexes &&1 &&2
|
||||
|
||||
-- -----------------------------------------
|
||||
-- Rename existing table - prefix with 'tmp'
|
||||
-- -----------------------------------------
|
||||
SET VERIFY OFF
|
||||
SET FEEDBACK OFF
|
||||
BEGIN
|
||||
DBMS_Output.Put_Line(' ');
|
||||
DBMS_Output.Put_Line('PROMPT');
|
||||
DBMS_Output.Put_Line('PROMPT Renaming ' || Upper('&&1') || ' to TMP_' || Upper('&&1'));
|
||||
DBMS_Output.Put_Line('RENAME ' || Lower('&&1') || ' TO tmp_' || Lower('&&1'));
|
||||
DBMS_Output.Put_Line('/');
|
||||
END;
|
||||
/
|
||||
|
||||
-- ---------------
|
||||
-- Re-Create table
|
||||
-- ---------------
|
||||
@Table_Structure &&1 &&2
|
||||
|
||||
-- ---------------------
|
||||
-- Re-Create constraints
|
||||
-- ---------------------
|
||||
@Table_Constraints &&1 &&2
|
||||
|
||||
-- ---------------------
|
||||
-- Recreate FKs on table
|
||||
-- ---------------------
|
||||
@FKs_On_Table &&1 &&2
|
||||
|
||||
-- -----------------
|
||||
-- Re-Create indexes
|
||||
-- -----------------
|
||||
@Table_Indexes &&1 &&2
|
||||
|
||||
-- --------------------------
|
||||
-- Build up population insert
|
||||
-- --------------------------
|
||||
SET VERIFY OFF
|
||||
SET FEEDBACK OFF
|
||||
DECLARE
|
||||
|
||||
CURSOR cu_columns IS
|
||||
SELECT Lower(column_name) column_name
|
||||
FROM all_tab_columns atc
|
||||
WHERE atc.table_name = Upper('&&1')
|
||||
AND atc.owner = Upper('&&2');
|
||||
|
||||
BEGIN
|
||||
|
||||
DBMS_Output.Put_Line(' ');
|
||||
DBMS_Output.Put_Line('PROMPT');
|
||||
DBMS_Output.Put_Line('PROMPT Populating ' || Upper('&&1') || ' from TPM_' || Upper('&&1'));
|
||||
DBMS_Output.Put_Line('INSERT INTO ' || Lower('&&1'));
|
||||
DBMS_Output.Put('SELECT ');
|
||||
FOR cur_rec IN cu_columns LOOP
|
||||
IF cu_columns%ROWCOUNT != 1 THEN
|
||||
DBMS_Output.Put_Line(',');
|
||||
END IF;
|
||||
DBMS_Output.Put(' a.' || cur_rec.column_name);
|
||||
END LOOP;
|
||||
DBMS_Output.New_Line;
|
||||
DBMS_Output.Put_Line('FROM tmp_' || Lower('&&1') || ' a');
|
||||
DBMS_Output.Put_Line('/');
|
||||
|
||||
-- --------------
|
||||
-- Drop tmp table
|
||||
-- --------------
|
||||
DBMS_Output.Put_Line(' ');
|
||||
DBMS_Output.Put_Line('PROMPT');
|
||||
DBMS_Output.Put_Line('PROMPT Droping TMP_' || Upper('&&1'));
|
||||
DBMS_Output.Put_Line('DROP TABLE tmp_' || Lower('&&1'));
|
||||
DBMS_Output.Put_Line('/');
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
-- ---------------------
|
||||
-- Recreate FKs to table
|
||||
-- ---------------------
|
||||
@FKs_Ref_Table &&1 &&2
|
||||
|
||||
SET VERIFY OFF
|
||||
SET FEEDBACK OFF
|
||||
BEGIN
|
||||
DBMS_Output.Put_Line(' ');
|
||||
DBMS_Output.Put_Line('-------------------------------------------------------------');
|
||||
DBMS_Output.Put_Line('-- END Re-creation script for ' || Upper('&&1'));
|
||||
DBMS_Output.Put_Line('-------------------------------------------------------------');
|
||||
END;
|
||||
/
|
||||
|
||||
SPOOL OFF
|
||||
PROMPT
|
||||
SET VERIFY ON
|
||||
SET FEEDBACK ON
|
||||
SET TERMOUT ON
|
||||
|
||||
42
timhall/script_creation/role_ddl.sql
Normal file
42
timhall/script_creation/role_ddl.sql
Normal file
@@ -0,0 +1,42 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/role_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Displays the DDL for a specific role.
|
||||
-- Call Syntax : @role_ddl (role)
|
||||
-- Last Modified: 28/01/2006
|
||||
-- -----------------------------------------------------------------------------------
|
||||
|
||||
set long 20000 longchunksize 20000 pagesize 0 linesize 1000 feedback off verify off trimspool on
|
||||
column ddl format a1000
|
||||
|
||||
begin
|
||||
dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'SQLTERMINATOR', true);
|
||||
dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'PRETTY', true);
|
||||
end;
|
||||
/
|
||||
|
||||
variable v_role VARCHAR2(30);
|
||||
|
||||
exec :v_role := upper('&1');
|
||||
|
||||
select dbms_metadata.get_ddl('ROLE', r.role) AS ddl
|
||||
from dba_roles r
|
||||
where r.role = :v_role
|
||||
union all
|
||||
select dbms_metadata.get_granted_ddl('ROLE_GRANT', rp.grantee) AS ddl
|
||||
from dba_role_privs rp
|
||||
where rp.grantee = :v_role
|
||||
and rownum = 1
|
||||
union all
|
||||
select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', sp.grantee) AS ddl
|
||||
from dba_sys_privs sp
|
||||
where sp.grantee = :v_role
|
||||
and rownum = 1
|
||||
union all
|
||||
select dbms_metadata.get_granted_ddl('OBJECT_GRANT', tp.grantee) AS ddl
|
||||
from dba_tab_privs tp
|
||||
where tp.grantee = :v_role
|
||||
and rownum = 1
|
||||
/
|
||||
|
||||
set linesize 80 pagesize 14 feedback on verify on
|
||||
21
timhall/script_creation/sequence_ddl.sql
Normal file
21
timhall/script_creation/sequence_ddl.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/sequence_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for the specified sequence, or all sequences.
|
||||
-- Call Syntax : @sequence_ddl (schema-name) (sequence-name or all)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('SEQUENCE', sequence_name, sequence_owner)
|
||||
FROM all_sequences
|
||||
WHERE sequence_owner = UPPER('&1')
|
||||
AND sequence_name = DECODE(UPPER('&2'), 'ALL', sequence_name, UPPER('&2'));
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
22
timhall/script_creation/synonym_by_object_owner_ddl.sql
Normal file
22
timhall/script_creation/synonym_by_object_owner_ddl.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/synonym_by_object_owner_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for the specified synonym, or all synonyms.
|
||||
-- Search based on owner of the object, not the synonym.
|
||||
-- Call Syntax : @synonym_by_object_owner_ddl (schema-name) (synonym-name or all)
|
||||
-- Last Modified: 08/07/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('SYNONYM', synonym_name, owner)
|
||||
FROM all_synonyms
|
||||
WHERE table_owner = UPPER('&1')
|
||||
AND synonym_name = DECODE(UPPER('&2'), 'ALL', synonym_name, UPPER('&2'));
|
||||
|
||||
SET PAGESIZE 14 FEEDBACK ON VERIFY ON
|
||||
22
timhall/script_creation/synonym_ddl.sql
Normal file
22
timhall/script_creation/synonym_ddl.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/synonym_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for the specified synonym, or all synonyms.
|
||||
-- Search based on owner of the synonym.
|
||||
-- Call Syntax : @synonym_ddl (schema-name) (synonym-name or all)
|
||||
-- Last Modified: 08/07/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('SYNONYM', synonym_name, owner)
|
||||
FROM all_synonyms
|
||||
WHERE owner = UPPER('&1')
|
||||
AND synonym_name = DECODE(UPPER('&2'), 'ALL', synonym_name, UPPER('&2'));
|
||||
|
||||
SET PAGESIZE 14 FEEDBACK ON VERIFY ON
|
||||
21
timhall/script_creation/synonym_public_remote_ddl.sql
Normal file
21
timhall/script_creation/synonym_public_remote_ddl.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/synonym_public_remote_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for public synonyms to remote objects.
|
||||
-- Call Syntax : @synonym_remote_ddl
|
||||
-- Last Modified: 08/07/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('SYNONYM', synonym_name, owner)
|
||||
FROM dba_synonyms
|
||||
WHERE owner = 'PUBLIC'
|
||||
AND db_link IS NOT NULL;
|
||||
|
||||
SET PAGESIZE 14 FEEDBACK ON VERIFY ON
|
||||
22
timhall/script_creation/table_constraints_ddl.sql
Normal file
22
timhall/script_creation/table_constraints_ddl.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/table_constraints_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the UK & PK constraint DDL for specified table, or all tables.
|
||||
-- Call Syntax : @table_constraints_ddl (schema-name) (table-name or all)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('CONSTRAINT', constraint_name, owner)
|
||||
FROM all_constraints
|
||||
WHERE owner = UPPER('&1')
|
||||
AND table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'))
|
||||
AND constraint_type IN ('U', 'P');
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
24
timhall/script_creation/table_ddl.sql
Normal file
24
timhall/script_creation/table_ddl.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/table_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for specified table, or all tables.
|
||||
-- Call Syntax : @table_ddl (schema) (table-name or all)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
-- Uncomment the following lines if you need them.
|
||||
--DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SEGMENT_ATTRIBUTES', false);
|
||||
--DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'STORAGE', false);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('TABLE', table_name, owner)
|
||||
FROM all_tables
|
||||
WHERE owner = UPPER('&1')
|
||||
AND table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'));
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
18
timhall/script_creation/table_grants_ddl.sql
Normal file
18
timhall/script_creation/table_grants_ddl.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/table_grants_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for all grants on the specified table.
|
||||
-- Call Syntax : @table_grants_ddl (schema) (table_name)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT dbms_metadata.get_dependent_ddl('OBJECT_GRANT', UPPER('&2'), UPPER('&1')) from dual;
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
24
timhall/script_creation/table_indexes_ddl.sql
Normal file
24
timhall/script_creation/table_indexes_ddl.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/table_indexes_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the index DDL for specified table, or all tables.
|
||||
-- Call Syntax : @table_indexes_ddl (schema-name) (table-name or all)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
-- Uncomment the following lines if you need them.
|
||||
--DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SEGMENT_ATTRIBUTES', false);
|
||||
--DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'STORAGE', false);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('INDEX', index_name, owner)
|
||||
FROM all_indexes
|
||||
WHERE owner = UPPER('&1')
|
||||
AND table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'));
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
21
timhall/script_creation/table_triggers_ddl.sql
Normal file
21
timhall/script_creation/table_triggers_ddl.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/table_triggers_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for all triggers on the specified table.
|
||||
-- Call Syntax : @table_triggers_ddl (schema) (table_name)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('TRIGGER', trigger_name, owner)
|
||||
FROM all_triggers
|
||||
WHERE table_owner = UPPER('&1')
|
||||
AND table_name = UPPER('&2');
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
20
timhall/script_creation/tablespace_ddl.sql
Normal file
20
timhall/script_creation/tablespace_ddl.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/tablespace_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for the specified tablespace, or all tablespaces.
|
||||
-- Call Syntax : @tablespace_ddl (tablespace-name or all)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('TABLESPACE', tablespace_name)
|
||||
FROM dba_tablespaces
|
||||
WHERE tablespace_name = DECODE(UPPER('&1'), 'ALL', tablespace_name, UPPER('&1'));
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
4
timhall/script_creation/tablespace_structure.sql
Normal file
4
timhall/script_creation/tablespace_structure.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
header("HTTP/1.1 301 Moved Permanently");
|
||||
header("Location: http://oracle-base.com/dba/script_creation/tablespace_ddl.sql");
|
||||
?>
|
||||
21
timhall/script_creation/trigger_ddl.sql
Normal file
21
timhall/script_creation/trigger_ddl.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/trigger_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for specified trigger, or all trigger.
|
||||
-- Call Syntax : @trigger_ddl (schema) (trigger-name or all)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('TRIGGER', trigger_name, owner)
|
||||
FROM all_triggers
|
||||
WHERE owner = UPPER('&1')
|
||||
AND trigger_name = DECODE(UPPER('&2'), 'ALL', trigger_name, UPPER('&2'));
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
70
timhall/script_creation/user_ddl.sql
Normal file
70
timhall/script_creation/user_ddl.sql
Normal file
@@ -0,0 +1,70 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/user_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Displays the DDL for a specific user.
|
||||
-- Call Syntax : @user_ddl (username)
|
||||
-- Last Modified: 07/08/2018
|
||||
-- -----------------------------------------------------------------------------------
|
||||
|
||||
set long 20000 longchunksize 20000 pagesize 0 linesize 1000 feedback off verify off trimspool on
|
||||
column ddl format a1000
|
||||
|
||||
begin
|
||||
dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'SQLTERMINATOR', true);
|
||||
dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'PRETTY', true);
|
||||
end;
|
||||
/
|
||||
|
||||
variable v_username VARCHAR2(30);
|
||||
|
||||
exec :v_username := upper('&1');
|
||||
|
||||
select dbms_metadata.get_ddl('USER', u.username) AS ddl
|
||||
from dba_users u
|
||||
where u.username = :v_username
|
||||
union all
|
||||
select dbms_metadata.get_granted_ddl('TABLESPACE_QUOTA', tq.username) AS ddl
|
||||
from dba_ts_quotas tq
|
||||
where tq.username = :v_username
|
||||
and rownum = 1
|
||||
union all
|
||||
select dbms_metadata.get_granted_ddl('ROLE_GRANT', rp.grantee) AS ddl
|
||||
from dba_role_privs rp
|
||||
where rp.grantee = :v_username
|
||||
and rownum = 1
|
||||
union all
|
||||
select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', sp.grantee) AS ddl
|
||||
from dba_sys_privs sp
|
||||
where sp.grantee = :v_username
|
||||
and rownum = 1
|
||||
union all
|
||||
select dbms_metadata.get_granted_ddl('OBJECT_GRANT', tp.grantee) AS ddl
|
||||
from dba_tab_privs tp
|
||||
where tp.grantee = :v_username
|
||||
and rownum = 1
|
||||
union all
|
||||
select dbms_metadata.get_granted_ddl('DEFAULT_ROLE', rp.grantee) AS ddl
|
||||
from dba_role_privs rp
|
||||
where rp.grantee = :v_username
|
||||
and rp.default_role = 'YES'
|
||||
and rownum = 1
|
||||
union all
|
||||
select to_clob('/* Start profile creation script in case they are missing') AS ddl
|
||||
from dba_users u
|
||||
where u.username = :v_username
|
||||
and u.profile <> 'DEFAULT'
|
||||
and rownum = 1
|
||||
union all
|
||||
select dbms_metadata.get_ddl('PROFILE', u.profile) AS ddl
|
||||
from dba_users u
|
||||
where u.username = :v_username
|
||||
and u.profile <> 'DEFAULT'
|
||||
union all
|
||||
select to_clob('End profile creation script */') AS ddl
|
||||
from dba_users u
|
||||
where u.username = :v_username
|
||||
and u.profile <> 'DEFAULT'
|
||||
and rownum = 1
|
||||
/
|
||||
|
||||
set linesize 80 pagesize 14 feedback on trimspool on verify on
|
||||
21
timhall/script_creation/view_ddl.sql
Normal file
21
timhall/script_creation/view_ddl.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- -----------------------------------------------------------------------------------
|
||||
-- File Name : https://oracle-base.com/dba/script_creation/view_ddl.sql
|
||||
-- Author : Tim Hall
|
||||
-- Description : Creates the DDL for the specified view.
|
||||
-- Call Syntax : @view_ddl (schema-name) (view-name)
|
||||
-- Last Modified: 16/03/2013 - Rewritten to use DBMS_METADATA
|
||||
-- -----------------------------------------------------------------------------------
|
||||
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
|
||||
|
||||
BEGIN
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'SQLTERMINATOR', true);
|
||||
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true);
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT DBMS_METADATA.get_ddl ('VIEW', view_name, owner)
|
||||
FROM all_views
|
||||
WHERE owner = UPPER('&1')
|
||||
AND view_name = DECODE(UPPER('&2'), 'ALL', view_name, UPPER('&2'));
|
||||
|
||||
SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON
|
||||
Reference in New Issue
Block a user