Anda di halaman 1dari 24

LOGIC WORKS02 AUTHOR JP VIJAYKUMAR CASE LOGIC 11 ************* --THE PRODUCTION JOB SHOULD RUN ON THE FIRST BUSINESS

DAY OF EVERY MONTH. THE JOB SHOULD NOT RUN ON A SATURDAY OR A SUNDAY. --THE PRODUCTION JOB SHOULD RUN EVERY ALTERNATE DAY. CASE LOGIC 12 ************* --FIND THE TABLE COLUMNS THAT CAN NOT HOLD THE LARGE VALUES IN NUMBER DATA TYPE FIELDS. MOST OF THE NUMBER DATA TYPE COLUMNS WHERE DEFINED AS NUMBER(2), NUMBER(1) ETC . CASE LOGIC 13 ************* --CASE 01-A TABLE HAD DATA, HAVING MOST COLUMNS IN EACH ROW ARE NULLS. HOW TO FIND THE ROWS THAT ARE HAVING ANY OR ALL NULL VALUE IN COL1-COL4 IN ONE TABLE THERE MAY OR MAY NOT BE DATA. --CASE 02-THE BUSINESS WANTS TO DISPLAY "EMPTY" WHEN THERE ARE NO ROWS IN THE TA BLE. DISPLAY THE DATA, WHEN THERE IS DATA. CASE LOGIC 14 ************* --Veeksha went to the first temple. The priest in the first temple gave Veeksha, equal number of flowers, Veeksha had with her. Veeksha offered some flowers in prayer to God in the first temple. Veeksha went to the second temple. The priest in the second temple gave Veeksha, equal number of flowers, Veeksha had with her. Veeksha offered some flowers in prayer to God in the second temple. Veeksha went to the third temple. The priest in the third temple gave Veeksha, equal number of flowers, Veeksha had with her. Veeksha offered some flowers in prayer to God in the third temple. Veeksha offered equal number of flowers in each of the three temples. When Veeksha came out of the third temple, she had no flowers with her. How many flowers, Veeksha had, when she went to the first temple? How many flowers, Veeksha offerred in each of the three temples? CASE LOGIC 15 ************* --FINDING DUPLICATE INDEXES ON TABLES IN ORACLE DATABASE WITH COLUMNS DETAILS CASE LOGIC 16 ************* --Automating awr report generation for a range of snapids. CASE LOGIC 17 *************

--HANDLING THE FOLLOWING ORA ERRORS. ORA-00955: name is already used by an existing object ORA-22855: optional name for LOB storage segment incorrectly specified CASE LOGIC 18 ************* --Automating awr report generation in interactive mode. CASE LOGIC 19 ************* --In a large datawarehouse, I just want to gather stats on the current partition s only. --For this, I want to filter historical partitions. --My procedure finds all non partitioned tables, all partitioned, that are parti tioned on hash and list, and range partitions, that are not partitioned on date parti tions and only the current partitions, that are partitioned on range. CASE LOGIC 20 DATE 03-14-11 ************* --Finding init.ora parameters that are differently setup across the instances in a RAC environment -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-****************SOLUTION DETAILS**************************** -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 11 DATE 06-14-10 ************* --01 PROBLEM_DEFINITION: --THE PRODUCTION JOB SHOULD RUN ON THE FIRST BUSINESS DAY OF EVERY MONTH. --THE JOB SHOULD NOT RUN ON A SATURDAY OR A SUNDAY. --AS PER THE ABOVE CRONTAB SETTING, CHANCES ARE THAT OUR JOB MAY RUN MULTIPLE TI MES. --THE FOLLOWING SHELL SCRIPT LOGIC WILL AVOID MULTIPLE RUNS OF THE JOB. METHOD 01 --------#!/usr/bin/ksh export DAY=`date awk '{print $1}'` export DATE=`date awk '{print $3}'` echo $DAY $DATE if n [[ $DAY != "Sat" ]] && [[ $DAY != "Sun" ]] && [[ $DATE -eq "1" ]]; the echo "run the job" date +%Y%m%d%H%M%S > job_executed

elif [[ $DAY != "Sat" ]] && [[ $DAY != "Sun" ]] && [[ $DATE -eq "2" ]] && [ [ ! -f job_executed ]]; then echo "run the job" date +%Y%m%d%H%M%S > job_executed elif [[ $DAY != "Sat" ]] && [[ $DAY != "Sun" ]] && [[ $DATE -eq "3" ]] && [ [ ! -f job_executed ]]; then echo "run the job" date +%Y%m%d%H%M%S > job_executed else echo "job did not run" exit fi .. .. .. exit 00 10 * 1-3 * /home/oracle/scripts/test_report.sh >/home/oracle/logs/test_report .log 2>&1 METHOD 02 --------#!/usr/bin/ksh export DAY=`date awk '{print $1}'` export DATE=`date awk '{print $3}'` echo $DAY $DATE if en elif else echo "job did not run `date` " exit fi .. .. .. exit 00 10 * 1-3 * /home/oracle/scripts/test_report.sh >/home/oracle/logs/test_report .log 2>&1 METHOD 03 --------In this method, I need not do any scripting logic. I open three scheduled jobs, as shown in here: 00 10 * 1 1-5 /home/oracle/scripts/test_report.sh >/home/oracle/logs/test_report .log 2>&1 00 10 * 2-3 1 /home/oracle/scripts/test_report.sh >/home/oracle/logs/test_report .log 2>&1 Out of the two cron schedules, only one condition is true, in any month. And tha [[ $DAY != "Sat" ]] && [[ $DAY != "Sun" ]] && [[ $DATE -eq 1 ]]; th echo "run the job `date` " [[ $DAY = "Mon" ]] && [[ $DATE -eq "2" echo "run the job `date` " $DATE -eq "3" ]]; then

t true condition will execute my job for that month. ******************************************************************* --02 PROBLEM_DEFINITION: --THE PRODUCTION JOB SHOULD RUN EVERY ALTERNATE DAY. 00 08 * * * /home/oracle/scripts/test_report.sh >/home/oracle/logs/test_report.l og 2>&1 --THIS CAN NOT BE SCHEDULED THROUGH CRON COMMAND WITH THE AVAILABLE OPTIONS. --INSTEAD I SCHEDULE THE SCRIPT TO RUN EVERYDAY AND MODIFIED MY SHELL SCRIPT LOG IC AS FOLLOWING: #!/usr/bin/ksh if elif [[ ! -f job_executed ]]; then echo "run the job" date +%Y%m%d%H%M%S > job_executed [[ -f job_execute ]]; then echo "job did not run" rm -f job_executed exit

fi .. .. .. exit -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 12 DATE 07-14-10 ************* --PROBLEM_DEFINITION: --FIND THE TABLE COLUMNS THAT CAN NOT HOLD THE LARGE VALUES IN NUMBER DATA TYPE FIELDS. --MOST OF THE NUMBER DATA TYPE COLUMNS WHERE DEFINED AS NUMBER(2), NUMBER(1) ETC . declare v_num number; v_len number; begin dbms_output.put_line('OWNER TABLE_NAME COLUMN_NAME DATA_PRECISION MAX_VALU E MAX_VALUE_LENGTH'); for c1 in (select owner,table_name,column_name,data_precision from dba_tables where owner='SCOTT' and data_type='NUMBER') loop execute immediate 'select nvl(max(' c1.column_name '),0),nvl(length(max(' c1. column_name ')),0) from ' c1.owner '.' c1.table_name into v_num,v_len; if ((c1.date_precision - v_len ) <= 2) then dbms_output.put_line(c1.owner ' ' c1.table_name ' ' c1.data_precision '**MA XED OUT**' v_num ' ' v_len); end if;

end loop; end; / -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 13 DATE 08-14-10 ************* --01 PROBLEM_DEFINITION: --A TABLE HAD DATA, HAVING MOST COLUMNS IN EACH ROW ARE NULLS. --HOW TO FIND THE ROWS THAT ARE HAVING ANY OR ALL NULL VALUE IN COL1-COL4. create table jp.temp_jp(empno number, col1 char(1),col2 char(2),col3 char(4)) ta blespace users; insert into jp.temp_jp(empno,col1,col3,col4) values(1,'X','X','X'); insert into jp.temp_jp(empno,col1,col2,col3,col4) values(2,'X','X','X','X'); insert into jp.temp_jp(empno,col1,col2,col4) values(3,'X','X','X'); insert into jp.temp_jp(empno,col1,col2,col3) values(4,'X','X','X'); insert into jp.temp_jp(empno,col1,col4) values(5,'X','X'); insert into jp.temp_jp(empno,col3,col4) values(6,'X','X'); insert into jp.temp_jp(empno,col3) values(7,'X'); insert into jp.temp_jp(empno,col4) values(8,'X'); insert into jp.temp_jp(empno) values(9); commit; select * from jp.temp_jp; EMPNO C C C C ---------- - - - 1 X X X 2 X X X X 3 X X X 4 X X X 5 X X 6 X X 7 X 8 X 9 9 rows selected. METHOD 01 --------select * from jp.temp_jp where col1 is null or col2 is null or col3 is null or col4 is null / EMPNO C C C C ---------- - - - 1 X X X 3 X X X 4 X X X 5 X X 6 X X 7 X 8 X

9 8 rows selected. select * from jp.temp_jp where col1 is null and col2 is null and col3 is null and col4 is null / EMPNO C C C C ---------- - - - 9 METHOD 02 --------select * from jp.temp_jp where decode(col1,'X',1,0) decode(col2,'X',1,0) decode(col3,'X',1,0) decode(col4,'X',1,0) / EMPNO C C C C ---------- - - - 1 X X X 3 X X X 4 X X X 5 X X 6 X X 7 X 8 X 9 8 rows selected.

+ + + < 4

-----------------------------------------------------------02 PROBLEM_DEFINITION: --IN ONE TABLE THERE MAY OR MAY NOT BE DATA. --THE BUSINESS WANTS TO DISPLAY "EMPTY" WHEN THERE ARE NO ROWS IN THE TABLE. --DISPLAY THE DATA, WHEN THERE IS DATA. desc jp.temp_jp1; Name Null? Type ----------------------------------------- -------- ---------------------------COL1 NUMBER truncate table jp.temp_jp1; select col1 from jp.temp_jp1; no rows selected select nvl(col1,0) from jp.temp_jp1; no rows selected select nvl((select * from jp.temp_jp1),0) col1 from dual; COL1 ---------0

select decode(nvl((select * from jp.temp_jp1),0),0,'EMPTY', nvl((select * from jp.temp_jp1),0)) col1 from dual; COL1 ---------------------------------------EMPTY truncate table jp.temp_jp1; Table truncated. insert into jp.temp_jp1 values (1); 1 row created. commit; Commit complete. select decode(nvl((select * from jp.temp_jp1),0),0,'EMPTY', nvl((select * from jp.temp_jp1),0)) col1 from dual; COL1 ---------------------------------------1 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 14 DATE 09-14-10 ************* --PROBLEM_DEFINITION: Veeksha went to the first temple. The priest in the first temple gave Veeksha, equal number of flowers, Veeksha had with her. Veeksha offered some flowers in prayer to God in the first temple. Veeksha went to the second temple. The priest in the second temple gave Veeksha, equal number of flowers, Veeksha had with her. Veeksha offered some flowers in prayer to God in the second temple. Veeksha went to the third temple. The priest in the third temple gave Veeksha, equal number of flowers, Veeksha had with her. Veeksha offered some flowers in prayer to God in the third temple. Veeksha offered equal number of flowers in each of the three temples. When Veeksha came out of the third temple, she had no flowers with her. How many flowers, Veeksha had, when she went to the first temple? How many flowers, Veeksha offerred in each of the three temples? --01 SOLUTION Let us say, Veeksha had x number of flowers, when she went to the first temple . The priest in the first temple, offered equal number of flowers to Veeksha. 2x

flowers. Veeksha offered some flowers in prayer to God in the first temple, say y. When Veeksha left the first temple, Veeksha had 2x - y flowers. Veeksha went to the second temple, with 2x - y flowers. The priest in the second temple gave her equal number of flowers, Veeksha had. ie 4x - 2y flowers. As per the problem definition, Veeksha offered equal number of flowers in all the three temples. So Veeksha offered y flowers in prayer to God in the second temple. When Veeksha left the second temple, Veeksha had 4x - 3y flowers. Veeksha went to the third temple with 4x - 3y flowers. The priest in the third temple gave her equal number of flowers, Veeksha had. ie 8x - 6y flowers. As per the problem definition, Veeksha offered equal number of flowers in all the three temples. So Veeksha offered y flowers in prayer to God in the third temple. As per the problem definition, Veeksha had no flowers left, when she came out of the third temple. That means 8x - 6y = y 8x = 7y x = 7y/8 So Veeksha started with 7 flowers and offered 8 flowers in each temple. Any multiple with 7 can be the starting number and any multiple with 8 will be the number of flowers offered in each of the three temples. To explain, I wrote the following pl/sql procedure: set serverout on size 1000000 declare a number:=7; b number:=8; x number; y number; begin for i in 1..10 loop x:=x*i; y:=y*i; dbms_output.put_line('Number of flowers Veeksha had at the begining : ' x); dbms_output.put_line('Number of flowers Veeksha offered in each temple : ' y); dbms_output.put_line('Number of flowers Veeksha had after leaving first temple : ' 2*x - y); dbms_output.put_line('Number of flowers Veeksha had after leaving second temple : ' 4*x - 3*y);

dbms_output.put_line('Number of flowers Veeksha had after leaving third temple : ' 8*x - 7*y); dbms_output.put_line(' '); end loop; end; / Number of flowers Veeksha had at the begining : 7 Number of flowers Veeksha offered in each temple : 8 declare * ERROR at line 1: ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at line 15 ------------------------------------------------------To resolve this error, I modified my script and executed as follows: ------------------------------------------------------set serverout on size 1000000 declare a number:=7; b number:=8; x number; y number; begin for i in 1..10 loop --dbms_output.put_line('Loop varaible value : ' i); x:=a*i; y:=b*i; dbms_output.put_line('Number of flowers Veeksha had at the begining : ' x); dbms_output.put_line('Number of flowers Veeksha offered in each temple : ' y); dbms_output.put_line('Number of flowers Veeksha had after leaving first temple : ' (2*x - y)); dbms_output.put_line('Number of flowers Veeksha had after leaving second temple : ' (4*x - 3*y)); dbms_output.put_line('Number of flowers Veeksha had after leaving third temple : ' (8*x - 7*y)); dbms_output.put_line(' '); end loop; end; SQL> set serverout on size 1000000 SQL> declare a number:=7; 2 3 b number:=8; 4 5 x number; 6 y number; 7 8 begin 9

10 for i in 1..10 loop 11 --dbms_output.put_line('Loop varaible value : ' i); 12 x:=a*i; 13 y:=b*i; 14 dbms_output.put_line('Number of flowers Veeksha had at the begining : ' x); 15 dbms_output.put_line('Number of flowers Veeksha offered in each temple : ' y); 16 17 dbms_output.put_line('Number of flowers Veeksha had after leaving first tem ple : ' (2*x - y)); 18 dbms_output.put_line('Number of flowers Veeksha had after leaving second te mple : ' (4*x - 3*y)); dbms_output.put_line('Number of flowers Veeksha had after leaving third temple : ' (8*x - 7*y)); 19 20 dbms_output.put_line(' '); 21 end loop; 22 23 end; 24 25 / Number of flowers Veeksha had at the begining : 7 Number of flowers Veeksha offered in each temple : 8 Number of flowers Veeksha had after leaving first temple : 6 Number of flowers Veeksha had after leaving second temple : 4 Number of flowers Veeksha had after leaving third temple : 0 Number of flowers Veeksha had at the begining : 14 Number of flowers Veeksha offered in each temple : 16 Number of flowers Veeksha had after leaving first temple : 12 Number of flowers Veeksha had after leaving second temple : 8 Number of flowers Veeksha had after leaving third temple : 0 Number of flowers Veeksha had at the begining : 21 Number of flowers Veeksha offered in each temple : 24 Number of flowers Veeksha had after leaving first temple : 18 Number of flowers Veeksha had after leaving second temple : 12 Number of flowers Veeksha had after leaving third temple : 0 Number of flowers Veeksha had at the begining : 28 Number of flowers Veeksha offered in each temple : 32 Number of flowers Veeksha had after leaving first temple : 24 Number of flowers Veeksha had after leaving second temple : 16 Number of flowers Veeksha had after leaving third temple : 0 Number of flowers Veeksha had at the begining : 35 Number of flowers Veeksha offered in each temple : 40 Number of flowers Veeksha had after leaving first temple : 30 Number of flowers Veeksha had after leaving second temple : 20 Number of flowers Veeksha had after leaving third temple : 0 Number of flowers Veeksha had at the begining : 42 Number of flowers Veeksha offered in each temple : 48 Number of flowers Veeksha had after leaving first temple : 36 Number of flowers Veeksha had after leaving second temple : 24 Number of flowers Veeksha had after leaving third temple : 0 Number of flowers Veeksha had at the begining : 49 Number of flowers Veeksha offered in each temple : 56 Number of flowers Veeksha had after leaving first temple : 42 Number of flowers Veeksha had after leaving second temple : 28 Number of flowers Veeksha had after leaving third temple : 0 Number of flowers Veeksha had at the begining : 56 Number of flowers Veeksha offered in each temple : 64 Number of flowers Veeksha had after leaving first temple : 48

Number Number Number Number Number Number Number Number Number Number Number Number

of of of of of of of of of of of of

flowers flowers flowers flowers flowers flowers flowers flowers flowers flowers flowers flowers

Veeksha Veeksha Veeksha Veeksha Veeksha Veeksha Veeksha Veeksha Veeksha Veeksha Veeksha Veeksha

had after leaving second temple had after leaving third temple had at the begining : 63 offered in each temple had after leaving first temple had after leaving second temple had after leaving third temple had at the begining : 70 offered in each temple had after leaving first temple had after leaving second temple had after leaving third temple

: 32 : 0 : : : : : : : : 72 54 36 0 80 60 40 0

PL/SQL procedure successfully completed. Happy scripting. -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 15 DATE 09-22-10 ************* --PROBLEM_DEFINITION: FINDING DUPLICATE INDEXES ON TABLES IN ORACLE DATABASE WITH COLUMNS DETAILS set serverout on size 1000000 timing on linesize 200 declare v_str varchar2(4000); begin for c1 in (select table_owner,table_name,column_name,column_position,count(*) fr om dba_ind_columns where table_owner NOT IN ('DBSNMP','EXFSYS','OUTLN','PERFSTAT','SYS', 'SYSMAN','SYSTEM','TOAD','TSMSYS','WMSYS','XDB') and column_position = 1 group by table_owner,table_name,column_name,column_position having count(*) > 1 order by 1,2) loop for c2 in ( select owner,index_name,table_owner,table_name from dba_indexes where (owner,index_name,table_owner,table_name) in (select index_owner,index_name,table_owner,table_name from dba_ ind_columns where table_owner = c1.table_owner and table_name = c1.table_name and column_name = c1.column_name and column_position = 1) ) loop v_str:=' '; for c3 in (select column_name from dba_ind_columns where index_owner = c2.owner and index_name = c2.index_name and table_owner = c2.table_owner and table_name = c2.table_name order by index_name,column_position) loop if (v_str = ' ') then v_str:=v_str c3.column_name;

else v_str:=v_str ':' c3.column_name; end if; end loop; dbms_output.put_line(c1.table_owner ' ' c1.table_name ' ' c2.index_name ' ' v_str); commit; end loop; end loop; end; / -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 16 DATE 10-04-10 ************* --PROBLEM_DEFINITION: Automating awr report generation for a range of snapids. set pagesize 0 linesize 200 timing on serverout on size 1000000 declare v_dbid number:=1234; --SUBSTITUTE WITH YOUR DBID v_inst number:=2; --SUBSTITUTE WITH YOUR INSTID DEFAULT 1 v_bnum number:=091409; --SUBSTITUTE WITH BEGIN SNAPID v_enum number:=100410; --SUBSTITUTE WITH END SNAPID v_next number; v_str varchar2(1000); begin while (v_bnum <=v_enum) loop v_next:=v_bnum+1; dbms_output.put_line('spool sept21_' v_dbid '_' v_inst '_' v_bnum '_' v_n ext '.html'); dbms_output.put_line('SELECT output FROM TABLE (dbms_workload_repository.awr_re port_html (' v_dbid ',' v_inst ',' v_bnum ',' v_next '));'); dbms_output.put_line('spool off'); v_bnum:=v_bnum+1; end loop; end; / spool sept21_1234_2_091409_091410.html SELECT output FROM TABLE (dbms_workload_repository.awr_report_html (1234,2,0914 09,091410)); spool off ................. ................. spool sept21_1234_2_100409_100410.html SELECT output FROM TABLE (dbms_workload_repository.awr_report_html (1234,2,1004 09,100410)); spool off PL/SQL procedure successfully completed. Elapsed: 00:00:00.01

Generally, we take very few awr reports randomly during the problem periods for analyzing performance issues. In one application, I have to generate awr reports for a large time range every hour from the two nodes of a RAC environment. This handy script saved my time and the trouble. Spool the output from the pl/sql procedure into jp.log and run the file. It generated a range of files for node 1. I modified the script for node 2. You need to modify the following parameters in the pl/sql procedure to generate the awr reports: 01 The db_id for all the instances in rac environment. 02 The instance id. For a stand alone db, the instance id is 1. For RAC environements, you need to take awr reports for all the insta nces. 03 You need to manually set the the snapids v_bnum and v_enum 04 I spooled the awr reports with specific name, so that I can identify and email them. You need to change the file name in the pl/sql procedure and in the s hell script. Due to size problem I could not send all the files in one tar/gzip file. The following shell script does the job. ----------------------------------------------------#!/bin/ksh main() { ls -1tr sept21_1234_2*html while read FILE do echo mutt -s "awr report from PRODDB node2 on 10-04-10 $FILE" -a ${FILE} "ve eksha.dasika@mycorp.com" done } cd /apps/oracle main ------------------------------------------------------References: http://www.dba-oracle.com/oracle10g_tuning/t_generating_awr_report.htm -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 17 DATE 11-03-10 MODIFIED 11-15-10

11-19-10 ************* --HANDLING THE FOLLOWING ORA ERRORS. ORA-00955: name is already used by an existing object ORA-22855: optional name for LOB storage segment incorrectly specified SQL> select * from v$version; BANNER ---------------------------------------------------------------Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production TNS for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production CONNECT SCOTT/TIGER Connected. drop table scott.aud$; drop table scott.aud$ * ERROR at line 1: ORA-00942: table or view does not exist CREATE TABLE scott."AUD$" ("SESSIONID" NUMBER NOT NULL ENABLE, "ENTRYID" NUMBER NOT NULL ENABLE, "STATEMENT" NUMBER NOT NULL ENABLE, "TIMESTAMP#" DATE, "USERID" VARCHAR2(30), "USERHOST" VARCHAR2(128), "TERMINAL" VARCHAR2(255), "ACTION#" NUMBER NOT NULL ENABLE, "RETURNCODE" NUMBER NOT NULL ENABLE, "OBJ$CREATOR" VARCHAR2(30), "OBJ$NAME" VARCHAR2(128), "AUTH$PRIVILEGES" VARCHAR2(16), "AUTH$GRANTEE" VARCHAR2(30), "NEW$OWNER" VARCHAR2(30), "NEW$NAME" VARCHAR2(128), "SES$ACTIONS" VARCHAR2(19), "SES$TID" NUMBER, "LOGOFF$LREAD" NUMBER, "LOGOFF$PREAD" NUMBER, "LOGOFF$LWRITE" NUMBER, "LOGOFF$DEAD" NUMBER, "LOGOFF$TIME" DATE, "COMMENT$TEXT" VARCHAR2(4000), "CLIENTID" VARCHAR2(64), "SPARE1" VARCHAR2(255), "SPARE2" NUMBER, "OBJ$LABEL" RAW(255), "SES$LABEL" RAW(255), "PRIV$USED" NUMBER, "SESSIONCPU" NUMBER, "NTIMESTAMP#" TIMESTAMP (6), "PROXY$SID" NUMBER, "USER$GUID" VARCHAR2(32), "INSTANCE#" NUMBER, "PROCESS#" VARCHAR2(16), "XID" RAW(8), "AUDITID" VARCHAR2(64), "SCN" NUMBER, "DBID" NUMBER, "SQLBIND" CLOB, "SQLTEXT" CLOB, "OBJ$EDITION" VARCHAR2(30)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING NOCOMPRESS LOB ("SQLBIND") STORE AS BASICFILE (TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) LOB ("SQLTEXT") STORE AS BASICFILE (TABLESPACE USERS ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) ; BUFFER_POOL DEFAULT)) LOB ("SQLTEXT") STORE AS BASICFILE (TABLESPACE * ERROR at line 25: ORA-00955: name is already used by an existing object

CREATE TABLE scott."AUD$" ("SESSIONID" NUMBER NOT NULL ENABLE, "ENTRYID" NUMBER NOT NULL ENABLE, "STATEMENT" NUMBER NOT NULL ENABLE, "TIMESTAMP#" DATE, "USERID" VARCHAR2(30), "USERHOST" VARCHAR2(128), "TERMINAL" VARCHAR2(255), "ACTION#" NUMBER NOT NULL ENABLE, "RETURNCODE" NUMBER NOT NULL ENABLE, "OBJ$CREATOR" VARCHAR2(30), "OBJ$NAME" VARCHAR2(128), "AUTH$PRIVILEGES" VARCHAR2(16), "AUTH$GRANTEE" VARCHAR2(30), "NEW$OWNER" VARCHAR2(30), "NEW$NAME" VARCHAR2(128), "SES$ACTIONS" VARCHAR2(19), "SES$TID" NUMBER, "LOGOFF$LREAD" NUMBER, "LOGOFF$PREAD" NUMBER, "LOGOFF$LWRITE" NUMBER, "LOGOFF$DEAD" NUMBER, "LOGOFF$TIME" DATE, "COMMENT$TEXT" VARCHAR2(4000), "CLIENTID" VARCHAR2(64), "SPARE1" VARCHAR2(255), "SPARE2" NUMBER, "OBJ$LABEL" RAW(255), "SES$LABEL" RAW(255), "PRIV$USED" NUMBER, "SESSIONCPU" NUMBER, "NTIMESTAMP#" TIMESTAMP (6), "PROXY$SID" NUMBER, "USER$GUID" VARCHAR2(32), "INSTANCE#" NUMBER, "PROCESS#" VARCHAR2(16), "XID" RAW(8), "AUDITID" VARCHAR2(64), "SCN" NUMBER, "DBID" NUMBER, "SQLBIND" CLOB, "SQLTEXT" CLOB, "OBJ$EDITION" VARCHAR2(30)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING NOCOMPRESS LOB ("SQLBIND","SQLTEXT") STORE AS BASICFILE (TABLESPACE USERS ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) ; LOB ("SQLBIND","SQLTEXT") STORE AS BASICFILE (TABLESPACE * ERROR at line 22: ORA-22855: optional name for LOB storage segment incorrectly specified CREATE TABLE scott."AUD$" ("SESSIONID" NUMBER NOT NULL ENABLE, "ENTRYID" NUMBER NOT NULL ENABLE, "STATEMENT" NUMBER NOT NULL ENABLE, "TIMESTAMP#" DATE, "USERID" VARCHAR2(30), "USERHOST" VARCHAR2(128), "TERMINAL" VARCHAR2(255), "ACTION#" NUMBER NOT NULL ENABLE, "RETURNCODE" NUMBER NOT NULL ENABLE, "OBJ$CREATOR" VARCHAR2(30), "OBJ$NAME" VARCHAR2(128), "AUTH$PRIVILEGES" VARCHAR2(16), "AUTH$GRANTEE" VARCHAR2(30), "NEW$OWNER" VARCHAR2(30), "NEW$NAME" VARCHAR2(128), "SES$ACTIONS" VARCHAR2(19), "SES$TID" NUMBER, "LOGOFF$LREAD" NUMBER, "LOGOFF$PREAD" NUMBER, "LOGOFF$LWRITE" NUMBER, "LOGOFF$DEAD" NUMBER, "LOGOFF$TIME" DATE, "COMMENT$TEXT" VARCHAR2(4000), "CLIENTID" VARCHAR2(64), "SPARE1" VARCHAR2(255), "SPARE2" NUMBER, "OBJ$LABEL" RAW(255), "SES$LABEL" RAW(255), "PRIV$USED" NUMBER, "SESSIONCPU" NUMBER, "NTIMESTAMP#" TIMESTAMP (6), "PROXY$SID" NUMBER, "USER$GUID" VARCHAR2(32), "INSTANCE#" NUMBER, "PROCESS#" VARCHAR2(16), "XID" RAW(8), "AUDITID" VARCHAR2(64), "SCN" NUMBER, "DBID" NUMBER, "SQLBIND" CLOB, "SQLTEXT" CLOB, "OBJ$EDITION" VARCHAR2(30)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING NOCOMPRESS LOB ("SQLBIND","SQLTEXT") STORE AS (TABLESPACE USERS ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) / Table created.

CONNECT SCOTT/TIGER Connected. DROP TABLE AUD$; Table dropped. CREATE TABLE scott."AUD$" ("SESSIONID" NUMBER NOT NULL ENABLE, "ENTRYID" NUMBER NOT NULL ENABLE, "STATEMENT" NUMBER NOT NULL ENABLE, "TIMESTAMP#" DATE, "USERID" VARCHAR2(30), "USERHOST" VARCHAR2(128), "TERMINAL" VARCHAR2(255), "ACTION#" NUMBER NOT NULL ENABLE, "RETURNCODE" NUMBER NOT NULL ENABLE, "OBJ$CREATOR" VARCHAR2(30), "OBJ$NAME" VARCHAR2(128), "AUTH$PRIVILEGES" VARCHAR2(16), "AUTH$GRANTEE" VARCHAR2(30), "NEW$OWNER" VARCHAR2(30), "NEW$NAME" VARCHAR2(128), "SES$ACTIONS" VARCHAR2(19), "SES$TID" NUMBER, "LOGOFF$LREAD" NUMBER, "LOGOFF$PREAD" NUMBER, "LOGOFF$LWRITE" NUMBER, "LOGOFF$DEAD" NUMBER, "LOGOFF$TIME" DATE, "COMMENT$TEXT" VARCHAR2(4000), "CLIENTID" VARCHAR2(64), "SPARE1" VARCHAR2(255), "SPARE2" NUMBER, "OBJ$LABEL" RAW(255), "SES$LABEL" RAW(255), "PRIV$USED" NUMBER, "SESSIONCPU" NUMBER, "NTIMESTAMP#" TIMESTAMP (6), "PROXY$SID" NUMBER, "USER$GUID" VARCHAR2(32), "INSTANCE#" NUMBER, "PROCESS#" VARCHAR2(16), "XID" RAW(8), "AUDITID" VARCHAR2(64), "SCN" NUMBER, "DBID" NUMBER, "SQLBIND" CLOB, "SQLTEXT" CLOB, "OBJ$EDITION" VARCHAR2(30)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING NOCOMPRESS LOB ("SQLBIND") STORE AS (TABLESPACE USERS ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) lob ("SQLTEXT") STORE AS (TABLESPACE USERS ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) / Table created. CONNECT SCOTT/TIGER Connected. DROP TABLE AUD$; Table dropped. SQL> CREATE TABLE scott."AUD$" AS SELECT * FROM SYS.AUD$ WHERE 1=2; Table created. SQL> select table_name from dba_tables where owner='SCOTT'; TABLE_NAME -----------------------------AUD$ CONNECT SCOTT/TIGER Connected. DROP TABLE AUD$; Table dropped.

SQL> ********************************************************************** SQL> SQL> CREATE TABLE "AUD$" ("SESSIONID" NUMBER NOT NULL ENABLE, 2 "ENTRYID" NUMBER NOT NULL ENABLE, "STATEMENT" NUMBER NOT NULL ENABLE, 3 "TIMESTAMP#" DATE, "USERID" VARCHAR2(30), "USERHOST" VARCHAR2(128), 4 "TERMINAL" VARCHAR2(255), "ACTION#" NUMBER NOT NULL ENABLE, 5 "RETURNCODE" NUMBER NOT NULL ENABLE, "OBJ$CREATOR" VARCHAR2(30), 6 "OBJ$NAME" VARCHAR2(128), "AUTH$PRIVILEGES" VARCHAR2(16), 7 "AUTH$GRANTEE" VARCHAR2(30), "NEW$OWNER" VARCHAR2(30), "NEW$NAME" 8 VARCHAR2(128), "SES$ACTIONS" VARCHAR2(19), "SES$TID" NUMBER, 9 "LOGOFF$LREAD" NUMBER, "LOGOFF$PREAD" NUMBER, "LOGOFF$LWRITE" NUMBER, 10 "LOGOFF$DEAD" NUMBER, "LOGOFF$TIME" DATE, "COMMENT$TEXT" 11 VARCHAR2(4000), "CLIENTID" VARCHAR2(64), "SPARE1" VARCHAR2(255), 12 "SPARE2" NUMBER, "OBJ$LABEL" RAW(255), "SES$LABEL" RAW(255), 13 "PRIV$USED" NUMBER, "SESSIONCPU" NUMBER, "NTIMESTAMP#" TIMESTAMP (6), 14 "PROXY$SID" NUMBER, "USER$GUID" VARCHAR2(32), "INSTANCE#" NUMBER, 15 "PROCESS#" VARCHAR2(16), "XID" RAW(8), "AUDITID" VARCHAR2(64), "SCN" 16 NUMBER, "DBID" NUMBER, "SQLBIND" CLOB, "SQLTEXT" CLOB, "OBJ$EDITION" 17 VARCHAR2(30)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 18 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST 19 GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING NOCOMPRESS 20 LOB ("SQLBIND") STORE AS BASICFILE (TABLESPACE "USERS" ENABLE 21 STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 22 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 23 BUFFER_POOL DEFAULT)) LOB ("SQLTEXT") STORE AS BASICFILE (TABLESPACE 24 USERS ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING 25 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST 26 GROUPS 1 BUFFER_POOL DEFAULT)) ; BUFFER_POOL DEFAULT)) LOB ("SQLTEXT") STORE AS BASICFILE (TABLESPACE * ERROR at line 23: ORA-00955: name is already used by an existing object

SQL> select * from v$version; BANNER -------------------------------------------------------------------------------Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production show user USER is "VEEKSHA" drop table aud$; Table dropped. SQL> CREATE TABLE "AUD$" ("SESSIONID" NUMBER NOT NULL ENABLE, 2 "ENTRYID" NUMBER NOT NULL ENABLE, "STATEMENT" NUMBER NOT NULL ENABLE, 3 "TIMESTAMP#" DATE, "USERID" VARCHAR2(30), "USERHOST" VARCHAR2(128), 4 "TERMINAL" VARCHAR2(255), "ACTION#" NUMBER NOT NULL ENABLE, 5 "RETURNCODE" NUMBER NOT NULL ENABLE, "OBJ$CREATOR" VARCHAR2(30),

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

"OBJ$NAME" VARCHAR2(128), "AUTH$PRIVILEGES" VARCHAR2(16), "AUTH$GRANTEE" VARCHAR2(30), "NEW$OWNER" VARCHAR2(30), "NEW$NAME" VARCHAR2(128), "SES$ACTIONS" VARCHAR2(19), "SES$TID" NUMBER, "LOGOFF$LREAD" NUMBER, "LOGOFF$PREAD" NUMBER, "LOGOFF$LWRITE" NUMBER, "LOGOFF$DEAD" NUMBER, "LOGOFF$TIME" DATE, "COMMENT$TEXT" VARCHAR2(4000), "CLIENTID" VARCHAR2(64), "SPARE1" VARCHAR2(255), "SPARE2" NUMBER, "OBJ$LABEL" RAW(255), "SES$LABEL" RAW(255), "PRIV$USED" NUMBER, "SESSIONCPU" NUMBER, "NTIMESTAMP#" TIMESTAMP (6), "PROXY$SID" NUMBER, "USER$GUID" VARCHAR2(32), "INSTANCE#" NUMBER, "PROCESS#" VARCHAR2(16), "XID" RAW(8), "AUDITID" VARCHAR2(64), "SCN" NUMBER, "DBID" NUMBER, "SQLBIND" CLOB, "SQLTEXT" CLOB, "OBJ$EDITION" VARCHAR2(30)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING NOCOMPRESS LOB ("SQLBIND") STORE AS BASICFILE (TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) LOB ("SQLTEXT") STORE AS BASICFILE (TABLESPACE USERS ENABLE STORAGE IN ROW CHUNK 8192 RETENTION NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) ;

Table created. -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 18 DATE 11-22-10 ************* --Automating awr report generation in interactive mode. whenever sqlerror exit sql.sqlcode; set verify off feedback off head on echo off serverout on size 1000000 linesize 200 pagesize 1000 set pagesize 10000 linesize 120 feedback off echo off column BEGIN_INTERVAL_TIME format a25 column END_INTERVAL_TIME format a25 SELECT SNAP_ID,BEGIN_INTERVAL_TIME,END_INTERVAL_TIME FROM DBA_HIST_SNAPSHOT orde r by 1; select (select name from v$database) db_name, extract( day from snap_interval) *24*60+extract( hour from snap_interval) *60 + extract( minute from snap_interval ) "Snapshot Interval", extract( day from retention) *24*60+ extract( hour from retention) *60+ extract( minute from retention ) "Retention Interval" from dba_hist_wr_control; --SELECT MIN(SNAP_ID) , MAX(SNAP_ID) FROM DBA_HIST_SNAPSHOT; define BEGIN_SNAPID = 0; define END_SNAPID = 0; define INTERVAL = 2; ACCEPT BEGIN_SNAPID PROMPT 'ENTER BEGIN_SNAPID:' ACCEPT END_SNAPID PROMPT 'ENTER END_SNAPID:' PROMPT 'IF INVERVAL IS 30 MTS, FOR A 30 MT AWR REPORT ENTER 1, FOR A 60 MT REPOR T ENTER 2' PROMPT 'IF INTERVAL IS 60 MTS, FOR A 60 MT AWR REPORT ENTER 1'

ACCEPT INTERVAL set head off set pagesize 0 linesize 200 serverout on size 1000000 linesize 200 timing off ec ho off feedback off spool /apps/oracle/jp.log declare v_bnum number; v_enum number; v_intl number ; v_dbid number; v_name varchar2(10); v_next number; v_date varchar2(10); begin execute immediate 'select nvl(''' '&interval' ''',0) from dual' into v_intl; execute immediate 'select name,dbid from v$database' into v_name,v_dbid; execute immediate 'select to_char(sysdate,''' 'yyyymmddhh24' ''') from dual' i nto v_date; for c1 in (select inst_id from gv$instance )loop begin execute immediate 'select nvl(''' '&begin_snapid' ''',0) from dual' into v_bnu m; execute immediate 'select nvl(''' '&end_snapid' ''',0) from dual' into v_enum; while (v_bnum <v_enum) loop begin v_next:=v_bnum+v_intl; --CHECK THE INTERVAL OF THE DB. CHECK THE INTERVAL OF AW R REPORTS GENERATED dbms_output.put_line('spool ' v_name '_' v_dbid '_' v_date '_' c1.inst_id '_' v_bnum '_' v_next '.html'); dbms_output.put_line('SELECT output FROM TABLE (dbms_workload_repository.awr_re port_html (' v_dbid ',' c1.inst_id ',' v_bnum ',' v_next '));'); dbms_output.put_line('spool off'); v_bnum:=v_next; exception when others then dbms_output.put_line(sqlerrm); end; end loop; exception when others then dbms_output.put_line(sqlerrm); end; end loop; end; / spool off undefine BEGIN_SNAPID undefine END_SNAPID undefine INTERVAL --To generate the required range of awr reports:

--connect to sqlplus @/apps/oracle/jp.log ------------------------------------------------------References: http://www.dba-oracle.com/oracle10g_tuning/t_generating_awr_report.htm -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 19 DATE 03-14-11 ************* --In a large datawarehouse, I just want to gather stats on the current partition s only. --For this, I want to filter historical partitions. --My procedure finds all non partitioned tables, all partitioned, that are parti tioned on hash and list, and range partitions, that are not partitioned on date parti tions and only the current partitions, that are partitioned on range. CREATE TABLE hash_part_jp ( prof_history_id NUMBER(10), person_id NUMBER(10) NOT NULL, organization_id NUMBER(10) NOT NULL, record_date DATE NOT NULL, prof_hist_comments VARCHAR2(2000)) PARTITION BY HASH (prof_history_id) PARTITIONS 4 STORE IN (users); CREATE TABLE list_part_jp ( deptno NUMBER(10), deptname VARCHAR2(20), quarterly_sales NUMBER(10,2), state VARCHAR2(2)) PARTITION BY LIST (state) ( PARTITION q1_northwest VALUES PARTITION q1_southwest VALUES PARTITION q1_northeast VALUES PARTITION q1_southeast VALUES PARTITION q1_northcent VALUES PARTITION q1_southcent VALUES

('OR', ('AZ', ('NY', ('FL', ('MN', ('OK',

'WA') 'CA', 'VT', 'GA') 'WI') 'TX')

TABLESPACE users, 'NM') TABLESPACE users, 'NJ') TABLESPACE users, TABLESPACE users, TABLESPACE users, TABLESPACE users);

drop table range_part1_jp; CREATE TABLE range_part1_jp ( prof_history_id NUMBER(10), person_id NUMBER(10) NOT NULL, organization_id NUMBER(10) NOT NULL, record_date DATE NOT NULL) PARTITION BY RANGE (record_date) ( PARTITION yr0 VALUES LESS THAN (TO_DATE('01-JAN-2007','DD-MON-YYYY')) TABLESPACE users, PARTITION yr8 VALUES LESS THAN (TO_DATE('01-JAN-2008','DD-MON-YYYY')) TABLESPACE users, PARTITION yr9 VALUES LESS THAN (MAXVALUE) TABLESPACE users);

drop table range_part2_jp; CREATE TABLE range_part2_jp ( prof_history_id NUMBER(10), person_id NUMBER(10) NOT NULL, organization_id NUMBER(10) NOT NULL, record_date DATE NOT NULL) PARTITION BY RANGE (prof_history_id) ( PARTITION p1 VALUES LESS THAN (1000) TABLESPACE users, PARTITION p2 VALUES LESS THAN (2000) TABLESPACE users, PARTITION p3 VALUES LESS THAN (3000) TABLESPACE users, PARTITION p4 VALUES LESS THAN (4000) TABLESPACE users, PARTITION pm VALUES LESS THAN (MAXVALUE) TABLESPACE users); drop table range_part3_jp; CREATE TABLE range_part3_jp ( prof_history_id NUMBER(10), person_id NUMBER(10) NOT NULL, organization_id NUMBER(10) NOT NULL, record_date DATE NOT NULL) PARTITION BY RANGE (record_date) ( PARTITION pt06 VALUES LESS THAN (TO_DATE('01-JAN-2006','DD-MON-YYYY')) TABLESPACE users, PARTITION pt07 VALUES LESS THAN (TO_DATE('01-JAN-2007','DD-MON-YYYY')) TABLESPACE users, PARTITION pt08 VALUES LESS THAN (TO_DATE('01-JAN-2008','DD-MON-YYYY')) TABLESPACE users, PARTITION pt09 VALUES LESS THAN (TO_DATE('01-JAN-2009','DD-MON-YYYY')) TABLESPACE users, PARTITION pt10 VALUES LESS THAN (TO_DATE('01-JAN-2010','DD-MON-YYYY')) TABLESPACE users, PARTITION pt11 VALUES LESS THAN (TO_DATE('01-JAN-2011','DD-MON-YYYY')) TABLESPACE users); create table temp_jp(col1 number) tablespace users; set serverout on size 1000000 timing on declare v_data all_tab_columns.data_type%TYPE; v_part all_tab_partitions.partition_name%TYPE; begin for c1 in (select t.owner,t.table_name,decode(p.partitioning_type,'','NULL',p.pa rtitioning_type) partitioning_type, nvl(partition_count,0) partition_count from all_tables t, all_part_tables p where t.owner = p.owner(+) and t.table_name = p.table_name(+) and t.owner in ('VEEKSHA')) loop begin select tc.data_type,tp.partition_name into v_data, v_part

from all_tab_partitions tp, all_part_key_columns pkc, all_tab_columns tc where tp.table_owner = pkc.owner and pkc.owner = tc.owner and tp.table_name = pkc.name

and and and and and

pkc.name pkc.column_name tp.partition_position pkc.owner pkc.name

= = = = =

tc.table_name tc.column_name c1.partition_count c1.owner c1.table_name;

exception when others then v_data:=null; end; if ((c1.partitioning_type = 'RANGE') AND (v_data = 'DATE')) then dbms_output.put_line(c1.owner ' ' c1.table_name ' RANGE PARTITION ON DATE KEY '); dbms_output.put_line('******' v_part ' ' v_data); else dbms_output.put_line(c1.owner ' ' c1.table_name ' ' c1.partitioning_type ' ' c1.partition_count); end if; end loop; end; / VEEKSHA HASH_PART_JP HASH 4 VEEKSHA LIST_PART_JP LIST 6 VEEKSHA RANGE_PART1_JP RANGE PARTITION ON DATE KEY ******YR9 DATE VEEKSHA RANGE_PART2_JP RANGE 5 VEEKSHA RANGE_PART3_JP RANGE PARTITION ON DATE KEY ******PT11 DATE VEEKSHA TEMP_JP NULL 0 VEEKSHA RUN_STATS_JP NULL 0 VEEKSHA AUD$ NULL 0 PL/SQL procedure successfully completed. Elapsed: 00:00:00.40 select tc.owner,tc.table_name ,tc.column_name,tc.data_type,tp.partition_name,tp. partition_position from all_tab_partitions tp, all_part_key_columns pkc, all_tab_columns tc where tp.table_owner = pkc.owner and pkc.owner = tc.owner and tp.table_name = pkc.name and pkc.name = tc.table_name and pkc.column_name = tc.column_name and tc.data_type = 'DATE' and tp.partition_position = 4 and pkc.owner = 'VEEKSHA' and pkc.name = 'RANGE_PART3_JP' --decode(substr(high_value,1,40),'MAXVALUE','MAXVALUE',max(substr(high_value,1,4 0))) select table_owner,table_name, high_value from all_tab_partitions where table_name like 'RANGE%JP' and dbms_log.substr(high_value,8,1) = 'MAXVALUE' order by 1;

select table_owner,table_name, partition_name,partition_position, high_value from all_tab_partitions where table_name like 'RANGE%JP' and to_char(substr(high_value,1,8)) = 'MAXVALUE' order by 1; select table_owner,table_name, high_value from all_tab_partitions where table_name like 'RANGE%JP' and substr(high_value,1,8) = 'MAXVALUE' order by 1; DESC ALL_PART_KEY_COLUMNS desc all_part_tables http://psoug.org/reference/library.html http://asktom.oracle.com/pls/asktom/f?p=100:11:5594580069759891::::P11_QUESTION_ ID:665224430110 http://www.scribd.com/doc/49619357/Gather-Table-Statistics-In-Parallel -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*CASE LOGIC 20 DATE 03-14-11 ************* --Finding init.ora parameters that are differently setup across the instances in a RAC environment set serverout on size 1000000 timing on declare v_nam varchar2(80):=''; v_val varchar2(512):=''; v_ins number; begin for c1 in (select inst_id,name,value from gv$parameter where name not in ('instance_number','instance_name','thread','undo_t ablespace','spfile', 'service_names','local_listener') order by name,inst_id) loop if (c1.inst_id = 1) then v_ins:=c1.inst_id; v_nam:=c1.name; v_val:=c1.value; elsif (c1.inst_id <> 1 AND c1.name = v_nam AND c1.value <> v_val) then dbms_output.put_line(v_ins ' ' c1.name ' ' v_val ' ' c1.inst_id ' ' c1.v alue); end if; end loop; end; / 1 db_file_multiblock_read_count 99 2 128 1 shared_pool_reserved_size 32086425 2 22858956 PL/SQL procedure successfully completed. --The same results are produced with the following sql query: column name format a30 column value format a10 select inst_id, name, value from gv$parameter where name in (select distinct nam

e from ( select name,value,count(1) from gv$parameter where name NOT IN ('instance_number','instance_name','thread','undo_tablespace','spfile','service_ names','local_listener') group by name,value having count(1) < (select count(1) from gv$instance)) ) orde r by name,inst_id; INST_ID NAME VALUE ---------- ------------------------------ ---------1 db_file_multiblock_read_count 99 2 db_file_multiblock_read_count 128 1 shared_pool_reserved_size 32086425 2 shared_pool_reserved_size 22858956