Exporting few partitions from a Partitioned table:
There might scenerios where you dont want to export the entire partitioned table for backup purposes. In this situations you can use simple expdp to do that.. Here is an example of
Here is a sample expdp cmd to export part of entire partitioned tables.
I have a table named AUDIT_LOGONS in my database, which has partitions as below image ,
I want to export a part of it. partitions AUDIT_LOGONS1,AUDIT_LOGONS2 only
oracle@Linux1 $ expdp username/password directory=DPUMP dumpfile=AUDIT_PART1.dmp logfile=AUDIT_PART1.log TABLES=arvind.AUDIT_LOGONS:AUDIT_LOGONS4,arvind.AUDIT_LOGONS:AUDIT_LOGONS3
Export: Release 11.2.0.4.0 - Production on Mon Oct 12 16:29:59 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Password:
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "arvind"."SYS_EXPORT_TABLE_01": arvind/******** directory=DPUMP dumpfile=AUDIT_PART1.dmp logfile=AUDIT_PART1.log TABLES=arvind.AUDIT_LOGONS:AUDIT_LOGONS4,arvind.AUDIT_LOGONS:AUDIT_LOGONS3
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 120 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
:
:
:
:
Dump file set for arvind.SYS_EXPORT_TABLE_01 is:
/u01/app/oracle/dpump/AUDIT_PART1.dmp
Job "arvind"."SYS_EXPORT_TABLE_01" successfully completed at Mon Oct 12 16:32:02 2015 elapsed 0 00:01:56
Thursday, November 19, 2015
ARCHIVE LOG Switch - shell script (for Oracle)
I think many of database admins will agree that it is always good idea to switch log file atleast every 20 mins or so. Especially when you have standby server setup. Doing this will ensure that redo logs are cleared up every 20 mins or so and they are shipped and applied onto standby database.
Script Benefits:
This is a simple shell script that uses plsql for checking the mount state of Database (oracle) and switch the archive log file when the open_mode of database is Read Write. This script can be setup on both Primary and standby DB servers. This will avoid the enabling and disabling process on both servers after switchover/failover. You can setup this on crontab job on both Primary and standby DB servers, This will only switch log file if the DB is on Read Write mode
---------- Script Starts Here -----------
#!/usr/bin/ksh
## ---- Created by Arvind Toorpu
## ---- Create Date 10/15/2015
## ---- This script can be scheduled on both PRIMARY AND STANDBY as it checks the role and switches logs
## ---- only if it is in PRIMARY ROLE
## ---- This script needs to be executed as DBA role user or user that has access to switch log file
## ---- Always good idea to switch logfile atleast every 20mins
## ---- Configure this using crontab
mydate=`date "+%d%b%Y-%H:%M"`;
export ORACLE_HOME="/u01/app/oracle/product/11.2/db_1"
export ORACLE_SID="ORCL"
PATH=$PATH:$ORACLE_HOME/bin;export PATH;
sqlplus -s "/as sysdba" > /u01/app/oracle/admin/bin/logs/arch_switch/ARCH_SWITCH_$mydate.log <<EOF
SET SERVEROUTPUT ON;
SET FEED OFF;
declare
DB_UQ_NAME varchar2(20);
CUR_STATUS varchar2(20);
DB_ROLE varchar2(20);
strQuery varchar2(100);
CURR_ARCH number;
BEGIN
select DB_UNIQUE_NAME,open_mode,DATABASE_ROLE into DB_UQ_NAME,CUR_STATUS,DB_ROLE from v\$database;
select max(SEQUENCE#) into CURR_ARCH from V\$ARCHIVED_LOG;
if CUR_STATUS='READ WRITE' and DB_ROLE='PRIMARY'
then
strQuery :=' alter system switch logfile';
DBMS_OUTPUT.PUT_LINE('DB_UNIQUE_NAME '||DB_UQ_NAME||' is currently in : '||CUR_STATUS ||' mode with Current ARch :'||CURR_ARCH);
EXECUTE immediate strQuery;
DBMS_OUTPUT.PUT_LINE('Switch logfile completed SUCESSFULLY !! ');
else
DBMS_OUTPUT.PUT_LINE('ERROR - DB_UNIQUE_NAME '||DB_UQ_NAME||' is currently in : '||CUR_STATUS||'.CANT SWITCH LOGFILE !!');
end if;
END;
/
EOF
Split Fullname into firstname and last name thru sql - Oracle
Today I was working around some queries and I had a requirement where in the data in table was being stored a FULLNAME. Now I have Split Fullname into First Name and Last Name. I have all the fullnames in the column seperated by a empty space ' '.
We can get the desired output by using the combination of SUBSTR and INSTR.
Lets create a sample table :
create table TESTTAB (ID number, FULLNAME varchar2(100));
Insert some data into it:
Insert into TESTTAB (ID,FULLNAME) values (1,'Jaff Schdt');
Insert into TESTTAB (ID,FULLNAME) values (2,'Bradee Will');
Insert into TESTTAB (ID,FULLNAME) values (3,'Kuck Dahl');
Insert into TESTTAB (ID,FULLNAME) values (5,'Melyssa man');
Insert into TESTTAB (ID,FULLNAME) values (6,'Melyssa man');
Insert into TESTTAB (ID,FULLNAME) values (7,'Shart Elarpre');
Insert into TESTTAB (ID,FULLNAME) values (8,'Rock Dihl');
Insert into TESTTAB (ID,FULLNAME) values (9,'Hia Dodd');
Insert into TESTTAB (ID,FULLNAME) values (10,'Pegy Sith');
select * from TESTTAB;
ID FULLNAME
-- -------------
1 Jaff Schdt
2 Bradee Will
3 Rock Dihl
5 Melyssa man
6 Melyssa man
7 Shart Elarpre
8 Rick Dihl
.
.
sample query :
SELECT
ID,
FULLNAME,
SUBSTR(FULLNAME,0,(INSTR(FULLNAME,' ') -1)) AS FIRST_NAME,
SUBSTR(FULLNAME,(INSTR(FULLNAME,' ') +1)) AS LAST_NAME,
(SUBSTR(FULLNAME,0,(INSTR(FULLNAME,' ') -1))
||SUBSTR(FULLNAME,(INSTR(FULLNAME,' ')))) as CONC_RESLT
FROM
TESTTAB;
Sample Code Ouput :
ID FULLNAME FNAME LNAME CONCAT_RESLT
--- ------------ ------ ------ --------------
1 Jaff Schdt Jaff Schdt Jaff Schdt
2 Bradee Will Bradee Will Bradee Will
3 Kuck Dahl Kuck Dahl Kuck Dahl
5 Melyssa man Melyssa man Melyssa man
6 Melyssa man Melyssa man Melyssa man
7 Shart Elarpre Shart Elarpre Shart Elarpre
8 Rock Dihl Rock Dihl Rock Dihl
.
.
Subscribe to:
Posts (Atom)