To check the parition value
select a.table_owner, a.table_name, a.partition_name, a.high_value from dba_tab_partitions a
where a.table_name in ('DAILY_INVENTORY_FACTS')
and partition_name in (select max(partition_name) from dba_tab_partitions b
where b.table_owner = a.table_owner and b.table_name = a.table_name )
order by a.table_name;
___________________________________________________________________
Create on temp machine.
CREATE TABLE DBMON.TEST_PARTITION_TEMP AS
(
SELECT 1 AS PARTITION_POSITION, TABLE_OWNER, TABLE_NAME, SUBSTR(PARTITION_NAME, 1, (LENGTH(PARTITION_NAME)-3)) AS PARTITION
_NAME,
TO_NUMBER(SUBSTR(PARTITION_NAME, (LENGTH(PARTITION_NAME)-2),3)) AS PARTITION_NUMBER, PARTITION_NAME AS VALIDATION,
TO_LOB(HIGH_VALUE) AS HIGH_VALUE
FROM DBA_TAB_PARTITIONS
WHERE
( TABLE_NAME,PARTITION_POSITION ) IN
(
SELECT TABLE_NAME, MAX(PARTITION_POSITION)
FROM DBA_TAB_PARTITIONS
WHERE
TABLE_OWNER = 'EDIADMIN'
GROUP BY TABLE_NAME
)
);
CREATE TABLE DBMON.TEST_PARTITION AS
SELECT PARTITION_POSITION, TABLE_OWNER, TABLE_NAME, PARTITION_NAME, PARTITION_NUMBER, VALIDATION,
TO_DATE(SUBSTR(HIGH_VALUE,10,11), 'YYYY-MM-DD') AS HIGH_VALUE
FROM DBMON.TEST_PARTITION_TEMP;
SELECT TEMP1.TABLE_OWNER, TEMP1.TABLE_NAME, TEMP1.PARTITION_NAME, TEMP1.HIGH_VALUE, TEMP2.HIGH_VALUE
FROM DBMON.TEST_PARTITION TEMP1, DBMON.TEST_PARTITION_TEMP TEMP2
WHERE
TEMP1.TABLE_NAME = TEMP2.TABLE_NAME
ORDER BY 2;
_________________________________________________________________________
prepare_daily_inventory_facts.sh
script to partitions.
#!/bin/ksh
if [[ $# -ne 1 ]]
then
print "Usage: prepare_daily_inventory_facts.sh <days>"
print "Example: prepare_daily_inventory_facts.sh 1 \n"
exit -1
fi
typeset -i WEEK=$1
typeset -i x=0
SCRIPT_FILE=daily_inventory_facts.sql
cat header.txt > ${SCRIPT_FILE}
while [[ $x -ne $WEEK ]];
do
##################################
# Create the partitions
#
sqlplus /nolog @prepare_daily_inventory_facts.sql > prepare_daily_inventory_facts.sql.out
cat prepare_daily_inventory_facts.sql.out | grep "ALTER" | grep -v TABLE_OWNER >> ${SCRIPT_FILE}
print "Partitions for day: ${x} as added."
x=$x+1
done
cat tail.txt >> daily_inventory_facts.sql
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
prepare_daily_inventory_facts.sql
connect / as sysdba
set time on timing on echo on pagesize 200 linesize 200 feed on
show user
select to_char(sysdate, 'YYYYMMDD HH24:MI:SS') from dual;
select NAME from V$DATABASE;
SELECT 'ALTER TABLE ' || TABLE_OWNER || '.' || TABLE_NAME ||
' ADD PARTITION ' || PARTITION_NAME || TO_CHAR(PARTITION_NUMBER+1) ||
' VALUES LESS THAN (TO_DATE(' || '''' || ' '|| to_char(HIGH_VALUE+1, 'YYYY-MM-DD HH24:MI:SS') || ''
'' ||
', ' || '''' || 'SYYYY-MM-DD HH24:MI:SS' || '''' || ', ' || '''' || 'NLS_CALENDAR=GREGORIAN' || '''
' || '));'
FROM DBMON.TEST_PARTITION
where TABLE_NAME = 'DAILY_INVENTORY_FACTS';
UPDATE DBMON.TEST_PARTITION SET PARTITION_NUMBER = PARTITION_NUMBER+1, HIGH_VALUE=HIGH_VALUE+1
WHERE TABLE_NAME = 'DAILY_INVENTORY_FACTS';
COMMIT;
quit
select a.table_owner, a.table_name, a.partition_name, a.high_value from dba_tab_partitions a
where a.table_name in ('DAILY_INVENTORY_FACTS')
and partition_name in (select max(partition_name) from dba_tab_partitions b
where b.table_owner = a.table_owner and b.table_name = a.table_name )
order by a.table_name;
___________________________________________________________________
Create on temp machine.
CREATE TABLE DBMON.TEST_PARTITION_TEMP AS
(
SELECT 1 AS PARTITION_POSITION, TABLE_OWNER, TABLE_NAME, SUBSTR(PARTITION_NAME, 1, (LENGTH(PARTITION_NAME)-3)) AS PARTITION
_NAME,
TO_NUMBER(SUBSTR(PARTITION_NAME, (LENGTH(PARTITION_NAME)-2),3)) AS PARTITION_NUMBER, PARTITION_NAME AS VALIDATION,
TO_LOB(HIGH_VALUE) AS HIGH_VALUE
FROM DBA_TAB_PARTITIONS
WHERE
( TABLE_NAME,PARTITION_POSITION ) IN
(
SELECT TABLE_NAME, MAX(PARTITION_POSITION)
FROM DBA_TAB_PARTITIONS
WHERE
TABLE_OWNER = 'EDIADMIN'
GROUP BY TABLE_NAME
)
);
CREATE TABLE DBMON.TEST_PARTITION AS
SELECT PARTITION_POSITION, TABLE_OWNER, TABLE_NAME, PARTITION_NAME, PARTITION_NUMBER, VALIDATION,
TO_DATE(SUBSTR(HIGH_VALUE,10,11), 'YYYY-MM-DD') AS HIGH_VALUE
FROM DBMON.TEST_PARTITION_TEMP;
SELECT TEMP1.TABLE_OWNER, TEMP1.TABLE_NAME, TEMP1.PARTITION_NAME, TEMP1.HIGH_VALUE, TEMP2.HIGH_VALUE
FROM DBMON.TEST_PARTITION TEMP1, DBMON.TEST_PARTITION_TEMP TEMP2
WHERE
TEMP1.TABLE_NAME = TEMP2.TABLE_NAME
ORDER BY 2;
_________________________________________________________________________
prepare_daily_inventory_facts.sh
script to partitions.
#!/bin/ksh
if [[ $# -ne 1 ]]
then
print "Usage: prepare_daily_inventory_facts.sh <days>"
print "Example: prepare_daily_inventory_facts.sh 1 \n"
exit -1
fi
typeset -i WEEK=$1
typeset -i x=0
SCRIPT_FILE=daily_inventory_facts.sql
cat header.txt > ${SCRIPT_FILE}
while [[ $x -ne $WEEK ]];
do
##################################
# Create the partitions
#
sqlplus /nolog @prepare_daily_inventory_facts.sql > prepare_daily_inventory_facts.sql.out
cat prepare_daily_inventory_facts.sql.out | grep "ALTER" | grep -v TABLE_OWNER >> ${SCRIPT_FILE}
print "Partitions for day: ${x} as added."
x=$x+1
done
cat tail.txt >> daily_inventory_facts.sql
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
prepare_daily_inventory_facts.sql
connect / as sysdba
set time on timing on echo on pagesize 200 linesize 200 feed on
show user
select to_char(sysdate, 'YYYYMMDD HH24:MI:SS') from dual;
select NAME from V$DATABASE;
SELECT 'ALTER TABLE ' || TABLE_OWNER || '.' || TABLE_NAME ||
' ADD PARTITION ' || PARTITION_NAME || TO_CHAR(PARTITION_NUMBER+1) ||
' VALUES LESS THAN (TO_DATE(' || '''' || ' '|| to_char(HIGH_VALUE+1, 'YYYY-MM-DD HH24:MI:SS') || ''
'' ||
', ' || '''' || 'SYYYY-MM-DD HH24:MI:SS' || '''' || ', ' || '''' || 'NLS_CALENDAR=GREGORIAN' || '''
' || '));'
FROM DBMON.TEST_PARTITION
where TABLE_NAME = 'DAILY_INVENTORY_FACTS';
UPDATE DBMON.TEST_PARTITION SET PARTITION_NUMBER = PARTITION_NUMBER+1, HIGH_VALUE=HIGH_VALUE+1
WHERE TABLE_NAME = 'DAILY_INVENTORY_FACTS';
COMMIT;
quit
______________________________________________________________________
header .txt
connect / as sysdba
set time on timing on echo on pagesize 200 linesize 200 feed on
show user
select to_char(sysdate, 'YYYYMMDD HH24:MI:SS') from dual;
select NAME from V$DATABASE;
_________________________________________________
tail.txt
quit;
_________________________-
daily_inventory_facts.sql
ALTER TABLE DSSADMIN.DAILY_INVENTORY_FACTS ADD PARTITION DIF_PART05859 VALUES LESS THAN (TO_DATE(' 2019-07-23 00:00:0
0', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'));
ALTER TABLE DSSADMIN.DAILY_INVENTORY_FACTS ADD PARTITION DIF_PART05860 VALUES LESS THAN (TO_DATE(' 2019-07-24 00:00:0
0', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'));
No comments:
Post a Comment