Locations of visitors to this page
Showing posts with label etl. Show all posts
Showing posts with label etl. Show all posts

Tuesday, August 16, 2011

ODI FAQ

去年DW项目实施时写的一些常见问题,主要针对ODI 10g版本,内容较陈旧,仅供参考


===一个变量可以在多个Scenario中使用而不产生冲突吗?===
可以

Recommendations For Working With ODI Variables In Startscen And OdiStartScen Calls ID 423737.1
https://support.oracle.com/CSP/main/article?cmd=show&id=423737.1&type=NOT

If the same Variable is used in multiple simultaneously running Scenarios, it must have the 'Action' parameter set to 'Not Persistent' to avoid Variable value collision from concurrent Scenarios.

===如何处理目录下的所有文件===

ODI Series – Processing all files in a directory: http://john-goodwin.blogspot.com/2009/06/odi-series-processing-all-files-in.html
How to refresh ODI variables from file – Part 1 – Just one value: http://odiexperts.com/?p=243
How to refresh ODI variables from file – Part 2 – Getting all lines, once at time: http://odiexperts.com/?p=273
Getting one or several unknown files from a directory: http://odiexperts.com/?p=1426

===如何删除ODI日志===
How To Avoid Saturating The ODI Log Tables ID 423934.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=423934.1
Session And Scenario Execution Log Tables Used By ODI ID 424663.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=424663.1
Programming ODI To Automatically Purge The Operator Journal ID 423839.1 https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=423839.1
How To Manually Delete A Scenario And Its Related Reports In The ODI Repository With SQL ID 424661.1 https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=424661.1
ODI snippets: Purge Log and shrink space: http://www.business-intelligence-quotient.com/?p=539

===ODI User Function怎么用?===
ODI User Functions: A Case Study: http://blogs.oracle.com/dataintegration/2009/09/odi_user_functions_a_case_stud.html
http://john-goodwin.blogspot.com/2009/06/odi-series-quick-look-at-user-functions.html

===如何并行执行过程===
Parallel Processing in ODI: http://blogs.oracle.com/dataintegration/2009/11/parallel_processing_in_odi.html
How To Run ODI Processes In Parallel And Using OdiWaitForChildSession ID 443858.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=443858.1
Asynchronous -Parallel Execution: http://odiexperts.com/?p=1180

===ODI的学习资源有哪些===
Oracle Data Integrator: http://www.oracle.com/technology/products/oracle-data-integrator/index.html
Oracle Data Integrator Release 10.1.3.6 Documentation Library: http://download.oracle.com/docs/cd/E15985_01/index.htm
Oracle Data Integrator Downloads: http://www.oracle.com/technology/software/products/odi/index.html
Oracle Data Integrator应用指南: http://www.docin.com/p-32319219.html
Oracle Data Integrator/Sunopsis, Releases and Patches ID 456313.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=456313.1
My Oracle Support searching keyword odi: http://support.oracle.com/
Data Integration Forum: http://forums.oracle.com/forums/forum.jspa?forumID=374
Developing a Knowledge Module in Oracle Data Integrator: http://www.oracle.com/technology/pub/articles/bethke-odi.html
ODI Resources for Beginners: Getting Started with Oracle Data Integrator: http://www.business-intelligence-quotient.com/?p=379
Oracle Data Integration Resource Kit. Included is the State of the Data Integration Market White Paper, in addition to additional key Data Integration resources.: http://www.oracle.com/webapps/dialogue/dlgpage.jsp
Oracle by Example Series: Oracle Data Integrator: http://www.oracle.com/technology/obe/fusion_middleware/odi/index.html
http://www.oracle.com/technology/obe/fusion_middleware/ODI/index.html
Data Integration and Management: http://blogs.oracle.com/dataintegration/
ODI EXPERTS: http://odiexperts.com/
More to life than this...: http://john-goodwin.blogspot.com/
BI-Quotient: http://www.business-intelligence-quotient.com/
Rittman Mead: http://www.rittmanmead.com
Business Intelligence – Oracle: http://oraclebizint.wordpress.com/category/oracle-data-integrator/

Oracle Czech BI/DW Blog: http://bidwcz.blogspot.com/
Technology & Other Worldly Issues: http://askankit.blogspot.com/

https://dbinfo.no.sohu.com:4443/apex/p?n=8247611144080585
https://dbinfo.no.sohu.com:4443/apex/p?n=8247701710096829
Note: The repository structure changes slightly between major versions and in particular from 11g onwards.
In this case, it is recommended to use the SDK instead of querying the repository tables directly.


===如何对数据源UNION操作===
Is It Possible To Use A UNION Operation Of Two Datastores As A Source For An ODI Integration Interface? ID 423731.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=423731.1
KM FOR UNION BASED ON IKM SQL CNTRL APPEND: http://odiexperts.com/?p=1164

===ODI授权===
Q:

开发想修改md_xxx中dm_agent,想定义为缓慢变化维,我用security manager通过profile给他授予了Object,Model Folder,Model,Sub-Model,Datastore 的所有权限,然后把md_xxx拖到了该用户下instances目录下,指定repository为wk_dev。增加这些权限后,开发说还是报错:com.sunopsis.core.SecurityAccessException: You are not authorized to Edit the Object:SNP_JOIN : DM_AGENT_FK_CHANNEL / 6001
难道我还得把相应的datastore也拖到用户下? ODI授个权怎么就这么麻烦呢? 这种操作到底需要授予哪些权限?

A:

we don't know

===如何用动态文件名===
Using A Dynamically Specified File Name Or Directory Name With ODI ID 423635.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=423635.1
Using Parameters in ODI: The Dynamic File Name Example: http://blogs.oracle.com/dataintegration/2009/04/using_parameters_in_odi_the_dy_1.html

===Operator中如何显示出变量值?===
Find the Value of the Variable in Operator ?: http://odiexperts.com/?p=855
ODI Variables and the Operator Module: http://www.business-intelligence-quotient.com/?p=762

One Comment on “ODI Variables and the Operator Module”

  1.
    #1 Craig Stewart said at 3:18 pm on March 17th, 2010:

    Uli
    Another great article – another snippet to follow-up. If the variable has been passed into the execution as a parameter, then if you use odiRef.getSession(”SESS_PARAMS” ) it will printout the values of the parameters. To make this readable in the execution, I usually put in a procedure with a Java Beanshell step, with the code:
    /* */
    As it is in /* */ comments, it is ignored, and does not look like an error/kludge, but prints out neatly in the log.
    Shame there is no similar thing for the variables set dynamically!
    Craig


Using Jython Scripting Features In ODI FAQ ID 566475.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=566475.1#aref78
10. Displaying ODI Variables Values In ODI Operator Log

Is there any technique whereby it is possible, in the ODI Operator Log, to display the values of ODI Variables which have been initialized from runtime parameters when launching Scenarios?
Such a technique would allow the recording of Variable values during runtime and would be useful for execution audit operations.

Two alternative solutions are possible:

In the case of OdiStartScen (SnpsStartScen) tool, it is possible to specify the name of the Session with the "-SESSION_NAME" parameter. In this case, pass the value of the ODI Variable to this parameter for display in ODI Journal.

A Jython script step such as the following, in a Knowledge Module, will allow the display of the ODI Variable value in the Execution tab of the step :
a = 'Table = '+ '#YOURVARIABLE'
raise(a)


Such a Jython script will require the "Ignore errors" checkbox to be checked in the Knowledge Module step. Do not forget that such an Integration Interface must be called from an ODI Package including steps which Declare and Refresh the ODI Variable.

Variable values cannot be displayed in this case because the Agent records data in ODI Operator Log before the ODI process that substitutes Variables by their values, and before sending the values to the technology be be directly used or bound.


===如何重新生成scenario===
ODI: Automating deployment of scenarios to production in Oracle Data Integrator: http://www.business-intelligence-quotient.com/?p=340
What Will Each Generation Mode (Replace, Re-generate, Creation) Of ODI Project "Generate All Scenarios" Option Do? ID 555709.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=555709.1
Generate Multiple Scenarios: http://odiexperts.com/?p=456
In ODI What Is The Difference Between Generation And Regeneration Of A Scenario ID 733103.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=733103.1

How To Ensure That The Regeneration Of An ODI Scenario Is Successful? ID 804583.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=804583.1

===生成场景报错ORA-12899===
Q:

生成场景时报如下错误
java.sql.SQLException: ORA-12899: value too large for column "W_DEV"."SNP_SCEN_STEP"."VAR_VALUE" (actual: 265, maximum: 250)
如何解决?

A:

变量赋值不能超过250字符。可以将一个大的变量分成多个小的变量,最后再拼到一起。

===用OdiFileWait报错===
Q:

程序中使用OdiFileWait检查文件是否存在,文件可以被ls看到,目录权限drwxr-xr-x,文件权限-rw-r--r--,但是OdiFileWait总报错说No File Found.

A:

# TIMEOUT时间太短,应该设置长一些,比如10000ms
# 文件名PATTERN中不能带目录名,比如#v_dirname/#v_filename,只能是纯文件名
# 改用别的方式检查文件是否存在,比如OdiOSCommand, sh -c "test -f #v_dirname/#v_filename"

===SQLLDR导数据的字段顺序出错===
Q:

用LKM File to Oracle (SQLLDR)导数据,报错字段格式不对。检查日志和生成的控制文件,发现控制文件中字段的顺序变了,跟文件中不一致

A:

因为在Interface配置的Target Datastore有些字段execute on source,有些execute on staging。KM生成的控制文件中,字段顺序自动发生了变化,execute on source的字段在前,execute on staging的在后。所以相关字段统一使用execute on source或staging...,顺序才不会变。

===IKM插入数据报错 ORA-01031: insufficient privileges===
Q:

IKM SQL Control Append在Insert new rows这步报错
1031 : 42000 : java.sql.SQLException: ORA-01031: insufficient privileges

java.sql.SQLException: ORA-01031: insufficient privileges


执行的语句是
insert /*+ append */ into  ods.ODS_ORACLE_TABXXX
(
….
from  ODI_WORK.I$_ODS_ORACLE_TABXXX


直接用sqlplus以odi work用户在ods数据库上执行同样语句,报错
    ,ods.seq_ods_oracle_tabxxx_id.nextval,
          *
ERROR at line 88:
ORA-01031: insufficient privileges


A:

ods库上的odi work用户没有相应权限,需要手工授予
grant select any sequence to ODI_WORK;


===如何实现反连接?===
Q:

ODI中如何实现not in, not exists
比如:
select * from t1 where not exists (select null from t2 where t2.c1=t1.c1)


A:

How To Set Up Negative Join Operations In An ODI Integration Interface ? ID 742144.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=742144.1
Using Oracle Outer Join Operations Such As LIKE, IN, NOT IN, IS NULL ...In ODI Integration Interfaces. ID 424034.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=424034.1

比如
select * from t1 where not exists (select null from t2 where t2.c1=t1.c1)

用left outer join实现:
Interface->Diagram->Sources

* t1 left outer join t2
** 注意不能选中left outer join复选框, 必须手工写(+)号
**Implementation填t1.c1=t2.c1(+), 设置为execute on staging
* t2增加filter, Implementation填t2.c1 is null, 设置为execute on staging

===刷新变量出错No value to affect to this variable for DefDate===
Q:

Package中刷新变量,报错Error: No value to affect to this variable for DefDate
意思是说select刷新语句没有返回结果。
然而数据库中运行select语句可以查到记录,有返回结果。

Package是按照Best practice,先声明变量,再刷新的,使用上应该没有错。

刷新语句是:
select to_char(t1_id) from admin_odi.t1
where name='#v_t1_name'

* 将where子句改成where name='p_city_day',也报同样错。
* 如果注释掉where子句,改成select to_char(p1_id) from admin_odi.t1,则刷新成功,取得第一条记录的结果。

A:

* 原因不明。
* 删掉Diagram中变量声明和刷新的步骤,重新定义这2步,即可。

===调用场景参数中带双引号的转义===
Q:

用如下命令调用一个场景失败,报Unmatching quotes错误
OdiStartScen "-SCEN_NAME=T1_INVOKER" "-SCEN_VERSION=001" "-TEST_XIEWEN.v_t1_name=p_city_day" "-TEST_XIEWEN.v_scen_name=P_CITY_DAY" "-TEST_XIEWEN.v_scen_params=\"-ODS_FROM_ONLINE_CITY.v_start_date=#TEST_XIEWEN.v_start_date\" \"-ODS_FROM_ONLINE_CITY.v_end_date=#TEST_XIEWEN.v_end_date\" \"-ODS_FROM_ONLINE_CITY.v_date_format=#TEST_XIEWEN.v_date_format\""


应如何转义双引号?

A:

现在用的方法是,先用一段特殊字符代表双引号,在被调用的场景中再将特殊字符替换回双引号

调用场景时,特殊字符\\u0022代表双引号:
OdiStartScen "-SCEN_NAME=T1_INVOKER" "-SCEN_VERSION=001" "-TEST_XIEWEN.v_t1_name=p_city_day" "-TEST_XIEWEN.v_scen_name=P_CITY_DAY" "-TEST_XIEWEN.v_scen_params=\\u0022-ODS_FROM_ONLINE_CITY.v_start_date=#TEST_XIEWEN.v_start_date\\u0022 \\u0022-ODS_FROM_ONLINE_CITY.v_end_date=#TEST_XIEWEN.v_end_date\\u0022 \\u0022-ODS_FROM_ONLINE_CITY.v_date_format=#TEST_XIEWEN.v_h1\\u0022"


场景中再替换回双引号:
select replace(q'{#v_scen_params}','\\u0022','"') from dual



===改resource name后interface取的还是旧表名===
Q:

为了测试用,将一个表data store的resource name改成另一个临时建的新表名,点refresh number of rows显示行数也和新表名相符, 然而运行interface,取到的还是旧表数据。为什么?

A:

* LKM Oracle to Oracle (DBLINK)_corp使用了odiRef.getSrcTablesList("", "[SCHEMA].[TABLE_NAME]获得源表表名
** TABLE_NAME表示逻辑表名,RES_NAME才表示物理表名
** TABLE_NAME Logical name of the source datastore
** RES_NAME Physical access name of the resource.......
* 所以修改resource name不管用,必须修改data store的名字。

===Historize变量没取到最新值===
Q:

有一个Historize变量v_etl_sysdate每天都刷新为当天的日期,通过变量的历史可以看到。

package查看这个变量,得到的不是最后一次刷新的值(2010-07-16),是历史记录中的第一个值(2010-04-09)。
SQL> select * from SNP_VAR_DATA where var_name='S2ODS.v_etl_sysdate' order by FIRST_DATE;

VAR_NAME
------------------------------------------------------------------------------------------------------------------------------------------------------
CONTEXT_CODE                                          I_VAL VAR_D
---------------------------------------------------------------------- ---------- -------------------
VAR_V
------------------------------------------------------------------------------------------------------------------------------------------------------
  VAR_N FIRST_DATE      FIRST_I_USER LAST_DATE      LAST_I_USER I_TXT_VAR_T
---------- ------------------- ------------ ------------------- ----------- -----------
S2ODS.v_etl_sysdate
EMPDATAB                                              6591
2010-04-09
      2010-04-09 00:29:59        2010-04-09 00:29:59

S2ODS.v_etl_sysdate
EMPDATAB                                            21382
2010-04-10
      2010-04-10 00:29:59        2010-04-10 00:29:59

...
...
S2ODS.v_etl_sysdate
EMPDATAB                                            1141971
2010-07-15
      2010-07-15 01:00:00        2010-07-15 01:00:00

S2ODS.v_etl_sysdate
EMPDATAB                                            1142420
2010-07-16
      2010-07-16 01:00:00        2010-07-16 01:00:00


98 rows selected.

SQL>


A:

* 直接执行package能取到最新值。
* 执行scenario, 如果生成scenario时,选择了v_etl_sysdate做参数,则以后运行scenario该参数默认值都是历史第一个值。
* 生成scenario不选择该变量做参数,执行也可得到最新值。

===ODI 11gR1===
document: http://download.oracle.com/docs/cd/E14571_01/odi.htm
download: http://edelivery.oracle.com/EPD/Download/get_form?egroup_aru_number=11571971

===如有error/discard记录,LKM SQLLDR导入失败===
Q:

如果有error或discard记录,LKM SQLLDR导入失败

A:

sqlloader not load file in oracle when get invalid rows.: http://forums.oracle.com/forums/thread.jspa?threadID=1043579

This is a bug 8560194 with ODI LKM File to Oracle (SQLLDR) and it has not been resolved yet.
SQLLDR if successful returns 0
SQLLDR if unsuccessful returns 1
SQLLDR if successful but even 1 record erred out to .bad or .dsc file returns 2

So, for ODI anything that is not 0 is an error.

To resolve this bug, you will have to customize this KM and change the step "Invoke SQLLDR" to selectively handle each error condition.

Duplicate the KM.
Goto the step Call sqlldr. and change the technology to Jython.

Replace the existing code with the following:

import os
retVal = os.system(r'sqlldr control=<%=snpRef.getSrcTablesList("", "[WORK_SCHEMA]/[TABLE_NAME].ctl", "", "")%> log=<%=snpRef.getSrcTablesList("", "[WORK_SCHEMA]/[TABLE_NAME].log", "", "")%> userid=<%=snpRef.getInfo("DEST_USER_NAME")%>/<%=snpRef.getInfo("DEST_PASS")%>@<%=snpRef.getInfo("DEST_DSERV_NAME")%> > <%=snpRef.getSrcTablesList("", "[WORK_SCHEMA]/[TABLE_NAME].out", "", "")%>')

if retVal == 1 or retVal > 2:
  raise 'SQLLDR failed. Please check the <%=snpRef.getSrcTablesList("", "[WORK_SCHEMA]/[TABLE_NAME].log", "", "")%> for details '


Hope that helps


===显示Session运行状态有问题===
Q:

Operator日志显示某Session总是Running状态,在后台查询已无相应数据库会话

A:

该会话可能是从本机No agent发起的,当会话运行中,退出了客户端(Designer,Operator)。客户端退出,会话也随之终止,但会话状态不会更新到ODI系统表。

===过程中使用绑定变量,报错Missing parameter===
Q:

Procedure中一条语句使用到了bind variable:
begin
...
UPDATE <%=odiRef.getOption("TABLE_NAME")%>
  SET STATUS=<%=odiRef.getOption("T1_STATUS")%>
  WHERE T1_ID=<%=odiRef.getOption("T1_ID")%>;
...
end;


P1_ID赋值为":ADMIN_ODI.v_t1_ID",开头的冒号表示使用绑定变量

执行时出错:
com.sunopsis.sql.SnpsMissingParametersException: Missing parameter
  at com.sunopsis.sql.SnpsQuery.completeHostVariable(SnpsQuery.java)
  at com.sunopsis.sql.SnpsQuery.updateExecStatement(SnpsQuery.java)
...


日志显示,最后生成的语句是:
begin
...
UPDATE #ADMIN_ODI.v_admin_odi_t1
  SET STATUS=2
  WHERE T1_ID=:ADMIN_ODI.v_t1_ID;
...
end;


A:

ODI把UPDATE语句最后的分号当成变量名的一部分,所以找不到变量,就报错了。

分号换行写,或前面加空格与变量名分开,即可。

===OdiOSCommand双连字符问题===
Q:

* OdiOSCommand调用命令sh -c "rsync -q --dry-run ...."
* 从Operator操作日志观看生成的命令,double hyphen及其后字符都没有了
* 将双连字符改成\u002d\u002d,生成命令没错,执行报错"命令返回:2"
* 检查出错原因,好像还是因为双连字符后被截断了,导致命令不完整:
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file


A:

OdiOutFile先将执行的命令写到一个脚本内,然后OdiOSCommand调用此脚本

===SNP_SESSION.SESS_STATUS字段代表什么含义?===
* D = Done
* W = Waiting
* E = Error
* R = Running
* M = Warning
* Q = Queued

===SQLLDR LKM如何实现只选择几列导入===
Q:

* 一个文件有A,B,C 3列,数据库表中有B,C 2列
* interface mapping只映射了B,C列, km生成的CTL文件内也只有这2列, 于是字段不匹配,sqlldr导入失败

A:

对所有没有mapping的字段,建filter, 填字段名 is not null or 字段名 is null

===Scheduler Agent和Work Repository是一一对应的吗===
Q:

odiparam.sh有个参数ODI_SECU_WORK_REP,表示agent连接哪个工作资料库

10g中,Scheduler Agent在启动时连接该工作资料库,获取scheduler定时任务

11g,情况好像有所不同,启动agent后,日志显示:
2010-08-24 20:08:38.177 NOTIFICATION ODI-1128 Agent pa_emods_dev is starting. Application Server: STANDALONE. Agent Version: 11.1.1.3.0 - 23/06/2010
. Port: 21911. JMX Port: 22911
2010-08-24 20:09:01.667 NOTIFICATION ODI-1136 Starting Schedulers on Agent pa_ods_dev
2010-08-24 20:09:01.853 NOTIFICATION ODI-1111 Agent pa_emods_dev started. Agent version: 11.1.1.3.0 - 23/06/2010. Port: 21911. JMX Port: 22911.
2010-08-24 20:09:01.907 NOTIFICATION ODI-1137 Scheduler started for work repository REPWPROD on Agent pa_ods_dev
2010-08-24 20:09:02.012 NOTIFICATION ODI-1137 Scheduler started for work repository REPWDEV on Agent pa_ods_dev

貌似连接了所有工作资料库,一个agent就管理了所有scheduler任务

odiparam.sh对该变量的注释也有所变化:
# The following work repository name variable is required by startcmd (when the specified
# command needs to connects to the work repository), startscen, and restartsession scripts.
# The agent startup and agentstop programs do not need this variable.
#
#  ODI_SECU_WORK_REP
#    Name of the Work Repository to connect. This Work Repository must
#    be attached to the master repository.


A:

测试了下,好像是这样
* 10g scheduler agent从odiparam.sh指定的work repository取出context和logical agent等于当前physical agent的任务
* 11g agent从所有的work repositories取出context和logical agent等于当前physical agent的任务

7.2.2 Agent Startup and Shutdown Cycle: http://download.oracle.com/docs/cd/E14571_01/core.1111/e10106/odi.htm#ASHIA4972
When the Oracle Data Integrator agent starts, it first reads its configuration, which includes master repository connection information. Then the agent connects to each of the work repositories attached to this master repository and removes stale sessions. Stale sessions are sessions that are incorrectly indicated in the work repository as running on this given agent. Stale sessions may result from an agent being stopped without being able to stop these sessions gracefully. As the agent restarts, it identifies the stale sessions and moves them to an error state.

From that point, the agent can retrieve and compute the schedules available for it in each work repository. Once this phase is complete, the agent waits for incoming sessions requests to start their processing, and is also able to start sessions based on its schedules.


===如何使用子查询===
Using subqueries in Oracle Data Integrator (ODI) interfaces for complex data integration requirements: http://www.business-intelligence-quotient.com/?p=621
Subselect, derived tables, and subqueries in ODI 11G: http://www.business-intelligence-quotient.com/?p=1045

===生成场景报错An object will be in an unidentified state===
Q:

https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=FAQ&id=471564.1#aref17
2. "An object will be in an unidentified state...." Message Is Randomly Displayed
The following message is displayed randomly:
"An object will be in an unidentified state (it is in the state Not found in the database and Update is currently being performed on it) " for example, when refreshing an Oracle Data Integrator Variable, running a Scenario...

Such a problem has been attributed to the ODI Log related tablespaces being full.

Workarounds are the following:

Increase the size of the appropriate tablespaces containing the ODI Work Repositories.
Purge the Log tables in ODI Log (Operator).


A:

* 删除日志

* 关了重新打开,有时也能好

===MySQL建temporary indexes的问题===
Q:

LKM建临时索引使用如下语句:
Create <%=odiRef.getTemporaryIndex ("INDEX_TYPE_CLAUSE") %> Index <%=odiRef.getObjectName(odiRef.getTemporaryIndex ("IDX_NAME"),"W") %> on <%=odiRef.getTemporaryIndex ("COLL_NAME")%>
<%=odiRef.getTemporaryIndexColList( "(", " [CX_COL_NAME] ", ", ", ")" )%>


生成的SQL语句是:
create ... index aaa.ix$_bbbb on .....;

索引名之前带上了数据库名

MySQL不支持这样写,应去掉数据库名:aaa.

所以将KM写为
Create <%=odiRef.getTemporaryIndex ("INDEX_TYPE_CLAUSE") %> Index ", "W").substring(odiRef.getCatalogName("W").length()+1)?> on <%=odiRef.getTemporaryIndex ("COLL_NAME")%>
<%=odiRef.getTemporaryIndexColList( "(", " [CX_COL_NAME] ", ", ", ")" )%>


A:

good

===OdiSqlUnload 报错内存不够===
Q:

使用OdiSqlUnload导出数据,大约28万条记录,报OutOfMemoryError
java.lang.OutOfMemoryError: Java heap space
  at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:1585)
  at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1409)
  at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2886)
  at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:476)
  at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2581)
  at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1757)
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2171)
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
  at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
  at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275)
  at com.sunopsis.sql.SnpsQuery.executeQuery(SnpsQuery.java:602)
  at com.sunopsis.dwg.tools.SqlUnload.actionExecute(SqlUnload.java:327)
  at com.sunopsis.dwg.function.SnpsFunctionBase.execute(SnpsFunctionBase.java:273)
  at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execIntegratedFunction(SnpSessTaskSql.java:3185)
  at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execIntegratedFunction(SnpSessTaskSql.java:1414)
  at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java:2785)
  at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2515)
  at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:534)
  at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:449)
  at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1954)
  at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1818)
  at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$2.doAction(StartScenRequestProcessor.java:559)
  at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:224)
  at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor.doProcessStartScenTask(StartScenRequestProcessor.java:481)
  at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$StartScenTask.doExecute(StartScenRequestProcessor.java:1040)
  at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:114)
  at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:82)
  at java.lang.Thread.run(Thread.java:619)


A:

增加odi agent java虚拟机内存

"java heap OutOfMemory" Error When Loading A Large Amount Of Data From Mysql With ODI ID 737309.1: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=PROBLEM&id=737309.1
This issue is due to a MySQL JDBC Driver issue.

When selecting a large amount of data, the MySQL JDBC Driver loads the entire ResultSet returned by the select to the JVM's memory.

This seems to be the case for any version of MySQL JDBC Driver.


* http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-implementation-notes.html
ResultSet

By default, ResultSets are completely retrieved and stored in memory. In most cases this is the most efficient way to operate, and due to the design of the MySQL network protocol is easier to implement. If you are working with ResultSets that have a large number of rows or large values, and can not allocate heap space in your JVM for the memory required, you can tell the driver to stream the results back one row at a time.

To enable this functionality, you need to create a Statement instance in the following manner:

stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
        java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);

The combination of a forward-only, read-only result set, with a fetch size of Integer.MIN_VALUE serves as a signal to the driver to stream result sets row-by-row. After this any result sets created with the statement will be retrieved row-by-row.


* 经试验,odiunload 参数fetchsize改小,比如改成10,能成功


===索引===
Q:

建索引

A:

create index w_dev.i_SNP_SESSION_psn on w_dev.SNP_SESSION(PARENT_SESS_NO) online;
create index w_prod.i_SNP_SESSION_psn on w_prod.SNP_SESSION(PARENT_SESS_NO) online;
...

create index w_dev.i_SNP_OBJ_STATE_IO on w_dev.SNP_OBJ_STATE(I_INSTANCE,I_OBJECT) online;
create index w_prod.i_SNP_OBJ_STATE_IO on w_prod.SNP_OBJ_STATE(I_INSTANCE,I_OBJECT) online;
...

create index w_prod.i_SNP_SESSION_an_ss on w_prod.SNP_SESSION(AGENT_NAME,SESS_STATUS) online;
create index w_dev.i_SNP_SESSION_an_ss on w_dev.SNP_SESSION(AGENT_NAME,SESS_STATUS) online;



===导入报错 ORA-00001: AK_SNP_GRP_STATE===
Q:

导入一个项目时报错:
java.sql.SQLException: ORA-00001: unique constraint (xxxx.AK_SNP_GRP_STATE) was happend
...


改用utf-8格式导出导入,导入报错
... integrity constraint (xxxxx.FK_TXT) violated - Parent Key are not found.
...


A:

因有人以中文系统创建了项目,项目中带有中文字符,如Markers是中文名称,如:优先级、进度、笑脸

将中文标识改为英文后,导出导入成功


===ODI Sendmail tool 发中文显示乱码===
Q:

用ODI sendmail tool发中文邮件,显示为乱码

A:

标题和内容编码不对,默认用了操作系统的语言设置

方法1:ODI Agent环境变量LANG设置GBK,LANG=zh_CN.gbk,然后重启agent

方法2:自己编写jython程序,支持编码,参考Unprintable And UTF-8 Characters When Sending Emails With The ODI  SendMail Tool ?: https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=PROBLEM&id=423953.1。未能实现

===ODI Agent不断重启===
Q:

按问题[#ODI Sendmail tool 发中文显示乱码]所述,设置LANG=zh_CN.gbk后,odi agent反复重启

A:

经检查,是/etc/init.d/odiagentctl condstart重启了进程

LANG改成zh_CN后,ping日志内容变成中文,脚本无法识别中文,因此误判,导致重启

只要将
grep -q -- "Invalid parameter:-SECURITY_DRIVER"

改成
grep -q -- ":-SECURITY_DRIVER"

即可








--fin--

Tuesday, March 24, 2009

prevent users using exp or imp 禁止用户使用导出和导入

how to prevent users using exp or imp

提问: 何如禁止用户使用exp或imp
回答: 可以, 但禁止了也不能保证数据安全


1.
参考文档
$ORACLE_HOME/rdbms/admin/catexp.sql

Default Privileges Assigned To PUBLIC In 10.2.0.4 Database

只要从PUBLIC回收一些视图的权限, 便可以禁止用户使用exp或imp


2.
exp加trace=y, 跟踪一下
exp a/a file=a.dmp rows=n tables=\(no_such_table\) log=a.exp.log trace=y
[oracle@DEV-RPT-2 ~]$ exp a/a file=a.dmp rows=n tables=\(no_such_table\) log=a.exp.log trace=y

Export: Release 10.2.0.4.0 - Production on Tue Mar 24 05:51:18 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options
Export done in AL32UTF8 character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported

About to export specified tables via Conventional Path ...
EXP-00011: A.NO_SUCH_TABLE does not exist
Export terminated successfully with warnings.
[oracle@DEV-RPT-2 ~]$

查看跟踪文件, 查看exp查询的EXU,IMP视图等
sed -n '
/EXU/Is/.*[^a-zA-Z0-9_$]\(.*EXU[a-zA-Z0-9_$]*\).*/\1/Ip
/IMP/Is/.*[^a-zA-Z0-9_$]\(.*IMP[a-zA-Z0-9_$]*\).*/\1/Ip
' $(ls -t $ORACLE_BASE/admin/$ORACLE_SID/udump/*.trc|head -1)
[oracle@DEV-RPT-2 ~]$ sed -n '
> /EXU/Is/.*[^a-zA-Z0-9_$]\(.*EXU[a-zA-Z0-9_$]*\).*/\1/Ip
> /IMP/Is/.*[^a-zA-Z0-9_$]\(.*IMP[a-zA-Z0-9_$]*\).*/\1/Ip
> ' $(ls -t $ORACLE_BASE/admin/$ORACLE_SID/udump/*.trc|head -1)
EXU8OPT
EXU8USRU
EXU8FUL
EXU8VER
EXU81JAVT
EXU9XDBUID
EXU81CSC
EXU9GSAS
EXU9NLS
EXU10ADEFPSWITCHES
EXU10R2DEFPSWITCHES
EXU8NXPU
EXU10TABS
EXU8NXPU
[oracle@DEV-RPT-2 ~]$



3. 跟踪imp
imp a/a file=a.dmp show=y log=a.imp.log trace=y
[oracle@DEV-RPT-2 ~]$ imp a/a file=a.dmp show=y log=a.imp.log trace=y

Import: Release 10.2.0.4.0 - Production on Tue Mar 24 05:53:33 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options

Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and AL16UTF16 NCHAR character set
. importing A's objects into A
Import terminated successfully without warnings.
[oracle@DEV-RPT-2 ~]$

查看跟踪文件
sed -n '
/EXU/Is/.*[^a-zA-Z0-9_$]\(.*EXU[a-zA-Z0-9_$]*\).*/\1/Ip
/IMP/Is/.*[^a-zA-Z0-9_$]\(.*IMP[a-zA-Z0-9_$]*\).*/\1/Ip
' $(ls -t $ORACLE_BASE/admin/$ORACLE_SID/udump/*.trc|head -1)
[oracle@DEV-RPT-2 ~]$ sed -n '
> /EXU/Is/.*[^a-zA-Z0-9_$]\(.*EXU[a-zA-Z0-9_$]*\).*/\1/Ip
> /IMP/Is/.*[^a-zA-Z0-9_$]\(.*IMP[a-zA-Z0-9_$]*\).*/\1/Ip
> ' $(ls -t $ORACLE_BASE/admin/$ORACLE_SID/udump/*.trc|head -1)
imp
exu8opt
IMP9USR
EXU8FUL
EXU9NLS
IMP9COMPAT
SET_IMP_TIMEZONE
SET_IMPORT_MODE
SET_IMP_EVENTS
[oracle@DEV-RPT-2 ~]$


4. 根据前面文档和跟踪得出的结果, 取消exp,imp权限

禁止exp
revoke select on sys.exu8usru from public;
[oracle@DEV-RPT-2 ~]$ exp a/a file=a.dmp rows=n tables=\(no_such_table\)

Export: Release 10.2.0.4.0 - Production on Tue Mar 24 07:57:10 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


EXP-00008: ORACLE error 942 encountered
ORA-00942: table or view does not exist
EXP-00024: Export views not installed, please notify your DBA
EXP-00000: Export terminated unsuccessfully
[oracle@DEV-RPT-2 ~]$
[oracle@DEV-RPT-2 ~]$ imp a/a file=a.dmp show=y

Import: Release 10.2.0.4.0 - Production on Tue Mar 24 07:57:41 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options

Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and AL16UTF16 NCHAR character set
. importing A's objects into A
Import terminated successfully without warnings.
[oracle@DEV-RPT-2 ~]$
grant select on sys.exu8usru to public;

禁止imp
revoke select on sys.imp9usr from public;
[oracle@DEV-RPT-2 ~]$ exp a/a file=a.dmp rows=n tables=\(no_such_table\)

Export: Release 10.2.0.4.0 - Production on Tue Mar 24 07:58:27 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options
Export done in AL32UTF8 character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported

About to export specified tables via Conventional Path ...
EXP-00011: A.NO_SUCH_TABLE does not exist
Export terminated successfully with warnings.
[oracle@DEV-RPT-2 ~]$
[oracle@DEV-RPT-2 ~]$ imp a/a file=a.dmp show=y

Import: Release 10.2.0.4.0 - Production on Tue Mar 24 07:58:35 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options

IMP-00003: ORACLE error 942 encountered
ORA-00942: table or view does not exist
IMP-00023: Import views not installed, please notify your DBA
IMP-00000: Import terminated unsuccessfully
[oracle@DEV-RPT-2 ~]$
grant select on sys.imp9usr to public;

禁止exp和imp
revoke select on sys.exu8opt from public;
[oracle@DEV-RPT-2 ~]$ exp a/a file=a.dmp rows=n tables=\(no_such_table\)

Export: Release 10.2.0.4.0 - Production on Tue Mar 24 07:59:45 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


EXP-00008: ORACLE error 942 encountered
ORA-00942: table or view does not exist
EXP-00024: Export views not installed, please notify your DBA
EXP-00000: Export terminated unsuccessfully
[oracle@DEV-RPT-2 ~]$
[oracle@DEV-RPT-2 ~]$ imp a/a file=a.dmp show=y

Import: Release 10.2.0.4.0 - Production on Tue Mar 24 07:59:51 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


IMP-00003: ORACLE error 942 encountered
ORA-00942: table or view does not exist
IMP-00023: Import views not installed, please notify your DBA
IMP-00000: Import terminated unsuccessfully
[oracle@DEV-RPT-2 ~]$
grant select on sys.exu8opt to public;


以上是10.2.0.4的测试结果, 其它版本的没试, 应该类似



外部链接:
Prevent the use of EXP and IMP for specified Oracle Users
Trace option in Export and Import
Export/Import DataPump Parameter TRACE - How to Diagnose Oracle Data Pump
Compatibility Matrix for Export And Import Between Different Oracle Versions



-fin-

Tuesday, December 16, 2008

loading and unloading data using external table - 使用外部表装载和卸载数据

---------- Forwarded message ----------
From: wen xie
Date: Tue, Dec 16, 2008 at 19:14
Subject: Fwd: loading and unloading data using external table
To: xiewenxiewen at googlemail.com




---------- Forwarded message ----------
From: XIE WEN-MFK346
Date: Tue, Dec 16, 2008 at 18:50
Subject: loading and unloading data using external table
To: wen xie




loading and unloading data using external table


10g外部表提供了将数据导出的功能

1. 建目录, 授权

conn / as sysdba
create or replace directory dp_dir as '/home/oracle/temp';
grant read,write on directory dp_dir to a;
grant read,write on directory dp_dir to b;
SQL> conn / as sysdba
Connected.
SQL> create or replace directory dp_dir as '/home/oracle/temp';

Directory created.

SQL> grant read,write on directory dp_dir to a;

Grant succeeded.

SQL> grant read,write on directory dp_dir to b;

Grant succeeded.

SQL>


2. 建测试表

conn a/a
drop table t;
create table t as select * from all_objects;
select count(*) from t;
SQL> conn a/a
Connected.
SQL> drop table t;
drop table t
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> create table t as select * from all_objects;

Table created.

SQL> select count(*) from t;

COUNT(*)
----------
9447

SQL>


3. 导出到外部表

建立外部表, 用oracle_datapump方式导出

drop table ext_t;
create table ext_t
organization external (
type oracle_datapump
default directory dp_dir
access parameters (nologfile)
location ('ext_t.dmp')
)
reject limit unlimited
as
select * from t
/
select count(*) from ext_t;
SQL> drop table ext_t;
drop table ext_t
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> create table ext_t
organization external (
type oracle_datapump
default directory dp_dir
access parameters (nologfile)
location ('ext_t.dmp')
)
reject limit unlimited
as
select * from t
/
2 3 4 5 6 7 8 9 10 11
Table created.

SQL> select count(*) from ext_t;

COUNT(*)
----------
9447

SQL>

生成了ext_t.dmp文件
!ls -lrt ~/temp/*.dmp
SQL> !ls -lrt ~/temp/*.dmp
-rw-r----- 1 oracle oinstall 872448 Dec 16 09:57 /home/oracle/temp/ext_t.dmp

SQL>


4. 取得表结构

下一步建表用


conn a/a
set long 4000 pages 9999 line 140
select dbms_metadata.get_ddl('TABLE','EXT_T') from dual;
SQL> conn a/a
Connected.
SQL> set long 4000 pages 9999 line 140
SQL> select dbms_metadata.get_ddl('TABLE',
'EXT_T') from dual;

DBMS_METADATA.GET_DDL('TABLE','EXT_T')
--------------------------------------------------------------------------------

CREATE TABLE "A"."EXT_T"
( "OWNER" VARCHAR2(30),
"OBJECT_NAME" VARCHAR2(30),
"SUBOBJECT_NAME" VARCHAR2(30),
"OBJECT_ID" NUMBER,
"DATA_OBJECT_ID" NUMBER,
"OBJECT_TYPE" VARCHAR2(19),
"CREATED" DATE,
"LAST_DDL_TIME" DATE,
"TIMESTAMP" VARCHAR2(19),
"STATUS" VARCHAR2(7),
"TEMPORARY" VARCHAR2(1),
"GENERATED" VARCHAR2(1),
"SECONDARY" VARCHAR2(1)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY "DP_DIR"
ACCESS PARAMETERS
( nologfile )
LOCATION
( 'ext_t.dmp'
)
)
REJECT LIMIT UNLIMITED



SQL>


conn b/b
desc all_objects
SQL> conn b/b
Connected.
SQL> desc all_objects
Name Null? Type
------------------------------
----------- -------- ----------------------------
OWNER NOT NULL VARCHAR2(30)
OBJECT_NAME NOT NULL VARCHAR2(30)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_ID NOT NULL NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED NOT NULL DATE
LAST_DDL_TIME NOT NULL DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)

SQL>


5. 建外部表, 导入数据

字段名和顺序要跟导出表一致


drop table ext_t1;
create table ext_t1 (
OWNER VARCHAR2(30),
OBJECT_NAME VARCHAR2(30),
SUBOBJECT_NAME VARCHAR2(30),
OBJECT_ID VARCHAR2(30),
DATA_OBJECT_ID VARCHAR2(30),
OBJECT_TYPE VARCHAR2(30),
CREATED VARCHAR2(30),
LAST_DDL_TIME VARCHAR2(30),
TIMESTAMP VARCHAR2(30),
STATUS VARCHAR2(30),
TEMPORARY VARCHAR2(30),
GENERATED VARCHAR2(30),
SECONDARY VARCHAR2(30)
)
organization external (
type oracle_datapump
default directory dp_dir
access parameters (nologfile)
location ('ext_t.dmp')
)
reject limit unlimited
/
select count(*) from ext_t1;
SQL> drop table ext_t1;
drop table ext_t1
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> create table ext_t1 (
2 OWNER VARCHAR2(30),
3 OBJECT_NAME VARCHAR2(30),
4 SUBOBJECT_NAME VARCHAR2(30),
5 OBJECT_ID VARCHAR2(30),
6 DATA_OBJECT_ID VARCHAR2(30),
7 OBJECT_TYPE VARCHAR2(30),
8 CREATED VARCHAR2(30),
9 LAST_DDL_TIME VARCHAR2(30),
10 TIMESTAMP VARCHAR2(30),
11 STATUS VARCHAR2(30),
12 TEMPORARY VARCHAR2(30),
13 GENERATED VARCHAR2(30),
14 SECONDARY VARCHAR2(30)
15 )
16 organization external (
17 type oracle_datapump
18 default directory dp_dir
19 access parameters (nologfile)
20 location ('ext_t.dmp')
21 )
22 reject limit unlimited
23 /

Table created.

SQL> select count(*) from ext_t1;

COUNT(*)
----------
9447

SQL>


6. 不能用impdp导入

报错格式不一致


conn b/b
!impdp b/b directory=dp_dir dumpfile=ext_t.dmp tables=ext_t nologfile=y remap_schema=a:b
SQL> conn b/b
Connected.
SQL> !impdp b/b directory=dp_dir dumpfile=ext_t.dmp tables=ext_t nologfile=y remap_schema=a:b

Import: Release 10.2.0.4.0 - 64bit Production on Tuesday, 16 December, 2008 10:42:22

Copyright (c) 2003, 2007, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31619: invalid dump file "/home/oracle/temp/ext_t.dmp"



SQL>

set serveroutput on size 1000000
exec system.show_dumpfile_info(p_dir=> 'dp_dir', p_file=> 'ext_t.dmp')
SQL> set serveroutput on size 1000000
SQL> exec system.show_dumpfile_info(p_
dir=> 'dp_dir', p_file=> 'ext_t.dmp')
----------------------------------------------------------------------------
Purpose..: Obtain details about export dumpfile. Version: 19-MAR-2008
Required.: RDBMS version: 10.2.0.1.0 or higher
. Export dumpfile version: 7.3.4.0.0 or higher
. Export Data Pump dumpfile version: 10.1.0.1.0 or higher
Usage....: execute show_dumfile_info('DIRECTORY', 'DUMPFILE');
Example..: exec show_dumfile_info('MY_DIR', 'expdp_s.dmp')
----------------------------------------------------------------------------
Filename.: ext_t.dmp
Directory: dp_dir
Disk Path: /home/oracle/temp
Filetype.: 1 (Export Data Pump dumpfile)
----------------------------------------------------------------------------
...File Version....: 1.1 (Oracle10g Release 2: 10.2.0.x)
...Master Present..: 1 (Yes)
...GUID............: 5E27FE1E5914DA98E040A8C0100B6117
...File Number.....: 1000001
...Characterset ID.: 873 (AL32UTF8)
...Creation Date...: Tue Dec 16 09:57:52 2008
...Flags...........: 10
...Job Name........:
...Platform........: x86_64/Linux 2.4.xx
...Language........: AL32UTF8
...Block size......: 4096
...Metadata Compres: 1 (Yes)
...Job Version.....: 10.02.00.03.00
...Max Items Code..: 15
----------------------------------------------------------------------------

PL/SQL procedure successfully completed.

SQL>





外部链接:

Unloading and Loading Data with the ORACLE_DATAPUMP Access Driver
Populating External TableGET_DUMPFILE_INFO Procedure





Xie Wen (谢文)
Network & Operations,
Multimedia Applications & Services (MDB) MOTOROLA Inc.
NO.104 mail box,
8th floor, Motorola Tower,
No. 1 Wang Jing East Road, Chao Yang District,
Beijing 100102 P. R. China
e-mail wenxie at motorola.com

Thursday, November 6, 2008

load multi-lines records using sqlldr

---------- Forwarded message ----------
From: XIE WEN-MFK346 <wenxie at motorola.com>
Date: 2008/11/6
Subject: sqlldr导入多行记录
To: xiewenxiewen at gmail.com


三种方法
1.特殊符号表示一条记录的结束
比如:记录结束用分号+换行符表示
drop table multilines_1;
create table multilines_1 (
id int,
text varchar2(1000)
);
cat >multilines-1.dat <<'EOF'
1;Last week Motorola announced that it would be shifting gears
in its smartphone business to focus on Google's Android platform.;
2;In fact, the company's co-CEO, said it would be limiting its
efforts to Android, Windows Mobile, and its own operating system,
P2K.;
EOF
cat >multilines-1.ctl <<'EOF'
LOAD DATA
INFILE "multilines-1.dat" "str ';\n'"
TRUNCATE
INTO TABLE multilines_1
FIELDS TERMINATED BY ';'
TRAILING NULLCOLS
(
id INTEGER EXTERNAL,
text CHAR
)
EOF
sqlldr a/a control=multilines-1.ctl log=multilines-1.log
select * from multilines_1;
SQL> select * from multilines_1;
ID
----------
TEXT
--------------------------------------------------------------------------------------------------------------------------------------------
1
Last week Motorola announced that it would be shifting gears
in its smartphone business to focus on Google's Android platform.
2
In fact, the company's co-CEO, said it would be limiting its
efforts to Android, Windows Mobile, and its own operating system,
P2K.

导入的记录跟原文件中一样,也有换行
2.用CONTINUEIF参数合并多行
比如,根据每行最后一个字符判断记录是否结束
drop table multilines_2;
create table multilines_2 (
id int,
text varchar2(1000)
);
cat >multilines-2.dat <<'EOF'
1;Last week Motorola announced that it would be shifting gears
in its smartphone business to focus on Google's Android platform.;
2;In fact, the company's co-CEO, said it would be limiting its
efforts to Android, Windows Mobile, and its own operating system,
P2K.;
EOF
cat >multilines-2.ctl <<'EOF'
LOAD DATA
INFILE "multilines-2.dat"
TRUNCATE
CONTINUEIF LAST <> ';'
INTO TABLE multilines_2
FIELDS TERMINATED BY ';'
TRAILING NULLCOLS
(
id INTEGER EXTERNAL,
text CHAR
)
EOF
sqlldr a/a control=multilines-2.ctl data=multilines-2.dat log=multilines-2.log
select * from multilines_2;
SQL> select * from multilines_2;
ID
----------
TEXT
--------------------------------------------------------------------------------------------------------------------------------------------
1
Last week Motorola announced that it would be shifting gears in its smartphone business to focus on Google's Android platform.
2
In fact, the company's co-CEO, said it would be limiting its efforts to Android, Windows Mobile, and its own operating system, P2K.
多行合并成一行,换行没有了
3.用CONCATENATE合并
合并一定数量的多行,作为一行记录处理
drop table multilines_3;
create table multilines_3 (
id int,
text varchar2(1000)
);
cat >multilines-3.dat <<'EOF'
1;Last week Motorola announced that it would be shifting gears
in its smartphone business to focus on Google's
Android platform.
2;In fact, the company's co-CEO, said it would be limiting its
efforts to Android, Windows Mobile, and its own operating system,
P2K.
EOF
cat >multilines-3.ctl <<'EOF'
LOAD DATA
TRUNCATE
CONCATENATE 3
INTO TABLE multilines_3
FIELDS TERMINATED BY ';'
TRAILING NULLCOLS
(
id INTEGER EXTERNAL,
text CHAR
)
EOF
sqlldr a/a control=multilines-3.ctl data=multilines-3.dat log=multilines-3.log
select * from multilines_3;
SQL> select * from multilines_3;
ID
----------
TEXT
--------------------------------------------------------------------------------------------------------------------------------------------
1
Last week Motorola announced that it would be shifting gears in its smartphone business to focus on Google's Android platform.
2
In fact, the company's co-CEO, said it would be limiting its efforts to Android, Windows Mobile, and its own operating system, P2K.
也是多行变一行,换行没了
只能合并固定行数
4. 举例
导入数据文件
3;abadferrerer^M\
^M\
fasfrerererteter^M\
dfafaerrererer^M\
^M\
Fwerertterwt
4;feretrterteteqeeree^M\
^M\
foererntrptrtntrotrtnrtpro^M\
^M\
ojfreorrtrtrtr
(^M是\r回车符,ASCII码是13,可以按Ctrl-v,Ctrl-m输入)
想要第二个字段去掉^M\,得到如下结果
abadferrerer
fasfrerererteter
dfafaerrererer
Fwerertterwt
用CONTINUEIF+translate()实现
drop table multilines_4;
create table multilines_4 (
id int,
text varchar2(1000)
);
cat >multilines-4.dat <<'EOF'
3;abadferrerer^M\
^M\
fasfrerererteter^M\
dfafaerrererer^M\
^M\
Fwerertterwt
4;feretrterteteqeeree^M\
^M\
foererntrptrtntrotrtnrtpro^M\
^M\
ojfreorrtrtrtr
EOF
sed -i 's/\^M/\r/g' multilines-4.dat
cat >multilines-4.ctl <<'EOF'
LOAD DATA
TRUNCATE
CONTINUEIF LAST = '\\'
INTO TABLE multilines_4
FIELDS TERMINATED BY ';'
TRAILING NULLCOLS
(
id INTEGER EXTERNAL,
text CHAR "translate(:text,chr(13)||'\\',chr(10))"
)
EOF
sqlldr a/a control=multilines-4.ctl data=multilines-4.dat log=multilines-4.log
select * from multilines_4;
SQL> select * from multilines_4;
ID
----------
TEXT
--------------------------------------------------------------------------------------------------------------------------------------------
3
abadferrerer
fasfrerererteter
dfafaerrererer
Fwerertterwt
4
feretrterteteqeeree
foererntrptrtntrotrtnrtpro
ojfreorrtrtrtr


Website Analytics

Followers