HOW TO

How to get the DDL of an dbms scheduler job

The easy way to get the ddl of an dbms scheduler job is : select dbms_metadata.get_ddl(‘PROCOBJ’,’JOB_NAME’,’JOB_OWNER’) from dual; set pagesize 299 set long 999 select dbms_metadata.get_ddl(‘PROCOBJ’,’DBACLASS_PURGE’,’DBAUSER’) from dual; DBMS_METADATA.GET_DDL(‘PROCOBJ’,’DBACLASS_PURGE’,’DBAUSER’) ——————————————————————————– BEGIN dbms_scheduler.create_job(‘”DBACLASS_PURGE”‘, job_type=>’STORED_PROCEDURE’, job_action=> ‘DBAUSER.DBA_CREATE_DBACIRCUIT_PATH’ , number_of_arguments=>0, start_date=>TO_TIMESTAMP_TZ(’06-JUN-2017 06.58.16.001208000 AM ASIA/BAHRAIN’,’DD -MON-RRRR HH.MI.SSXFF AM TZR’,’NLS_DATE_LANGUAGE=english’), repeat_interval=> ‘FREQ=HOURLY;INTERVAL=2;’ , end_date=>NULL, job_class=>'”DEFAULT_JOB_CLASS”‘, enabled=>FALSE, auto_drop=>FALSE,comments=> ‘DBACLASS_PURGE’ ); dbms_scheduler.enable(‘”DBACLASS_PURGE”‘); […]

How to modify awr snapshot interval setting

We can change the snap_interval and retention period for the automatic awr snapshot collection, using modify_snapshot_settings function. The default settings for ‘interval’ and ‘retention’ are 60 minutes and 8 days . DEFAULT SETTING: select snap_interval, retention from dba_hist_wr_control; SNAP_INTERVAL RETENTION ————————————————————————— ————————————————————————— +00000 01:00:00.0 +00008 00:00:00.0 Modify the snapshot setting:( snap_interval 30 min and retention […]

How to create awr snapshot manually

Automatic Workload Repository (AWR) is a collection of database statistics owned by the SYS user. By default snapshot are generated once every 60min . But In case we wish to generate awr snapshot manually, then we can run the below script.  This is usually useful, when we need to generate an awr report for a non-standard window with smaller interval. Lets say, we want to generate a report […]

How to generate AWR report in oracle

The Automatic Workload Repository (AWR) collects and maintains statistics of the database. We can generate awr report for a particular time frame in the past using the script awrrpt.sql ( located under $ORACLE_HOME/rdbms/admin) script – @$ORACLE_HOME/rdbms/admin/awrrpt.sql conn / as sysdba SQL> @$ORACLE_HOME/rdbms/admin/awrrpt.sql Specify the Report Type ~~~~~~~~~~~~~~~~~~~~~~~ AWR reports can be generated in the following […]

How to flush a sql statement from shared pool

                                  If you flush the shared pool, all the statements in cursor will be flushed. So if you want a sql query to do hard parsing, then you can flush the particular sql statement from shared pool. STEPS: 1. […]

How to get the bind values of a sql query

                   If you have the sql_id of the sql query , then you can get the bind values of the bind variables, from v$sql_bind_capture. Script: SELECT sql_id, b. LAST_CAPTURED, t.sql_text sql_text, b.HASH_VALUE, b.name bind_name, b.value_string bind_value FROM gv$sql t JOIN gv$sql_bind_capture b using (sql_id) WHERE b.value_string is […]

How to move lob segment to another tablespace

Follow below steps from moving lob segment from one tablespace to another. SQL> ;   1*  select table_name,COLUMN_NAME,SEGMENT_NAME,TABLESPACE_NAME from dba_lobs where OWNER=’DBACLASS’ SQL> / TABLE_NAME     COLUMN_NAME  SEGMENT_NAME                       TABLESPACE_NAME ————– ———— ———————————- —————————— FD_BREL_AUDIT PAYLOAD      SYS_LOB0000100201C00011$$          WEBMDATA   SQL> alter table DBACLASS.FD_BREL_AUDIT move lob (PAYLOAD) store as SYS_LOB0000100201C00011$$ ( tablespace USERS); Table altered.   SQL>  select […]

ORA-01940: cannot drop a user that is currently connected

 While dropping a user in oracle database , you may face below error. ORA-01940 Problem: SQL> drop user SCOTT cascade 2 / drop user SCOTT cascade * ERROR at line 1: ORA-01940: cannot drop a user that is currently connected Solution: 1. Find the sessions running from this userid: SQL> SELECT SID,SERIAL#,STATUS from v$session where […]

How to change the oracle database name using nid utility

  Follow below steps for changing the oracle database name using nid utility. We will change the database name from P2PRMD2 to P1D2ST. 1. Mount the database SQL> STARTUP MOUNT ORACLE instance started. Total System Global Area 8754618368 bytes Fixed Size 4646288 bytes Variable Size 3556776560 bytes Database Buffers 5033164800 bytes Redo Buffers 160030720 bytes […]

How to find when a table was last modified in oracle

    If you want to find, when a table was last modified like insert,update ,delete, then use the dictionary table dba_tab_modifications. SCENARIO: 1. Insert into test data: SQL[SCOTT@TDB01]SQL>>]insert into TEST values (10); 1 row created. SQL[SCOTT@TDB01]SQL>>]commit; Commit complete. 2. Check dba_tab_modification: SQL[SYS@TCRMDB01]SQL>>]select INSERTS,UPDATES,DELETES,TRUNCATED,TIMESTAMP from dba_tab_modifications where TABLE_NAME=’TEST’ and TABLE_OWNER=’SCOTT’; no rows selected   As […]