Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Pramod.

Asked: March 30, 2017 - 6:46 am UTC

Last updated: August 22, 2018 - 1:53 am UTC

Version: 11.2.0.4.0

Viewed 1000+ times

You Asked

Hi Tom,

I have 2 SQL scripts giving lots of rows :-

---Export Data for fy17 filename: w_camp_hist_f_2016.dmp

select count(*) from olap.w_camp_hist_f,olap.w_day_d where w_camp_hist_f.ld_dt_wid=w_day_d.row_wid and w_day_d.petc_year = 2016;

COUNT(*)
----------
330350

---Export Data for fy17 filename: w_camp_hist_f_2015.dmp

select count(*) from olap.w_camp_hist_f,olap.w_day_d where w_camp_hist_f.ld_dt_wid=w_day_d.row_wid and w_day_d.petc_year = 2015;

COUNT(*)
----------
2087542024

Now my concern is we need to get a expdp command for this rows returned by the 2 SQLs and do a impdp as well

So am not sure how we can create the QUERY CLAUSE for the 2 join tables

expdp olap/******* directory=table_export tables=w_camp_hist_f,w_day_d QUERY=???? DUMPFILE=tables.dmp LOGFILE=exp_table.log

Can you provide me with the QUERY CLAUSE TO BE USED HERE !!

Thanks

and Connor said...

from olap.w_camp_hist_f,olap.w_day_d
where w_camp_hist_f.ld_dt_wid=w_day_d.row_wid
and w_day_d.petc_year = 2016

can be phrased as:

from olap.w_camp_hist_f
where w_camp_hist_f.ld_dt_wid in (
select row_wid
from olap.w_day_d
where w_day_d.petc_year = 2016 )

and once you have that, it can be in a query clause, eg

c:\temp> cat where.par

dumpfile=scott.dmp
directory=TEMP
schemas=SCOTT
query=EMP:"WHERE DEPTNO IN ( SELECT DEPTNO FROM SCOTT.DEPT WHERE DEPTNO >= 20 )"

C:\temp>expdp parfile=where.par

Export: Release 12.2.0.1.0 - Production on Mon Apr 3 11:25:51 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Username: mcdonac/*****

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Starting "MCDONAC"."SYS_EXPORT_SCHEMA_01":  mcdonac/******** parfile=where.par
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SYNONYM/SYNONYM
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."EMP"                               8.656 KB      11 rows
. . exported "SCOTT"."EMP$"                              8.796 KB      15 rows
. . exported "SCOTT"."DEPT"                              6.023 KB       4 rows
. . exported "SCOTT"."SALGRADE"                          5.953 KB       5 rows
. . exported "SCOTT"."BONUS"                                 0 KB       0 rows
Master table "MCDONAC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for MCDONAC.SYS_EXPORT_SCHEMA_01 is:
  C:\TEMP\SCOTT.DMP
Job "MCDONAC"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Apr 3 11:26:22 2017 elapsed 0 00:00:27
 



Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

please help

naveen, August 21, 2018 - 4:41 pm UTC

I have a query like below to do expdp.
but it is not working. please help.
dumpfile=exp_PROD_DWC_OWNER_IN11435529.dmp
directory=DPUMP
log=exp_PROD_DWC_OWNER_IN11435529.log
tables=dwc_owner.idp_details
dwc_owner.prm_details
query="select a.*, b.* from dwc_owner.idp_details a, dwc_owner.prm_details b where a.acct_sched=b.acct_sched and a.original_book_date >'30-APR-2018' and b.updated_on >'30-APR-2018'"
Connor McDonald
August 22, 2018 - 1:53 am UTC

Create a view based on your SQL,

create view mv_view as
select a.*, b.* 
from dwc_owner.idp_details a, dwc_owner.prm_details b 
where a.acct_sched=b.acct_sched 
and a.original_book_date >'30-APR-2018' 
and b.updated_on >'30-APR-2018'


and then use

views_as_tables=my_view

on your datapump command line

complex join query with 5 tables

A reader, August 28, 2018 - 10:04 am UTC

I want to exp the results of 5 tables which need to demand the query below,how can I do it:
select *
from ufzsswxt.T_PM_N_ORDER odr
join ufzsswxt.T_PM_N_ORDER_TRADE trade on odr.ORDER_ID = trade.ORDER_ID
join ufzsswxt.T_PM_N_ORDER_DETAIL dtl on trade.TRADE_ID = dtl.TRADE_ID
LEFT join ufzsswxt.T_PM_N_ORDER_PAY pay ON trade.trade_id = pay.trade_id
left join ufzsswxt.T_PM_N_ORDER_SNAPSHOT odr_snap ON dtl.DETAIL_ID = odr_snap.order_detail_id and dtl.SKU_ID = odr_snap.sku_id
where odr.business_status in ('TO_BE_PAY','TO_BE_SHIP', 'SHIPPING','REFUNDOK','FINISH','AFTER_SALE','CLOSE','SHIPOK')
and odr.CHANNEL_ID in('GDJSYH1','GDJSYH','KHD_QD','XYKJ1','XYKJ2','ZYHLWYK','10085MALL','HD_LTDH')
and odr.create_time >=to_date('2018-07-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and odr.create_time <to_date('2018-08-01 00:00:00','yyyy-mm-dd hh24:mi:ss');

More to Explore

Data Pump

All of the database utilities including Data Pump are explained in the Utilities guide.