Oracle 10.2表现得很奇怪.或者是我

Cha*_*adD 1 sql oracle distributed-transactions oracle10g ora-01722

请查看以下查询.SQL没有它看起来那么糟糕.基本上,我们有一个事实表和一些简单的连接到一些维度表.然后我们有一个派生表的连接,给定别名ACCOUNTS-DIM-DEP

  SELECT dw_mgr.fa_trans_fct.period,
         dw_mgr.fa_trans_fct.asset_cost_company_code,
         dw_mgr.fa_trans_fct.asset_cost_center_id,
         dw_mgr.fa_trans_fct.depreciation_account_id,
         accounts_dim_dep.description, 
         dw_mgr.projects_dim.project_num,
         dw_mgr.projects_dim.project_name,
         ROUND (dw_mgr.fa_trans_fct.activity_deprn_amount_us, 2),
         organizations_cost.major_geography,
         organizations_cost.business_unit || organizations_cost.bu_desc,
         organizations_cost.industry_sector_num
              ||organizations_cost.industry_sector_desc,
         hyperion_organizations.hyperion_num,
         hyperion_organizations.hyperion_desc,
         hyperion_organizations.hyperion_reporting
    FROM dw_mgr.fa_trans_fct,
         (SELECT DISTINCT flex_value account_id, description
                     FROM rf_fnd_flex_values_det
                    WHERE flex_value_set_id = '1002363' 
                      AND summary_flag = 'N') accounts_dim_dep,
         dw_mgr.projects_dim,
         dw_mgr.organizations organizations_cost,
         dw_mgr.organizations hyperion_organizations
   WHERE 
         --Fact to Org on Company Code / Cost Center
         (dw_mgr.fa_trans_fct.asset_cost_center_id   
                                     = organizations_cost.cost_center_id)
     AND (dw_mgr.fa_trans_fct.asset_cost_company_code 
                                     = organizations_cost.company_code)
     --Fact to Projects Dim on Proj Num
     AND (dw_mgr.projects_dim.project_num = dw_mgr.fa_trans_fct.project_num)
     --Fact to Accounts_Dim_Dep on Account ID
     --convert account_ID on left to_number??????
     AND (accounts_dim_dep.account_id 
                            = dw_mgr.fa_trans_fct.depreciation_account_id) 
     --Fact Hyp Company Code Cost Center to Hyp Org
     AND (hyperion_organizations.cost_center_id 
                            = dw_mgr.fa_trans_fct.asset_cost_center_id AND
          hyperion_organizations.company_code  
                            = dw_mgr.fa_trans_fct.asset_cost_company_code)
   --Filters
     AND (
          dw_mgr.fa_trans_fct.period IN ('01-Jun-2009')
          --works
          --AND dw_mgr.fa_trans_fct.asset_cost_center_id IN ('000296') 
          --does not work               
          AND dw_mgr.fa_trans_fct.asset_cost_center_id IN ('000296','000296') 
          AND dw_mgr.fa_trans_fct.asset_cost_company_code = '0007'
         )



  ------------------------------------------------------------

  Statement Id=4203172   Type=
  Cost=2.64018716311899E-308  TimeStamp=06-10-09::17::51:43

       (1)  SELECT STATEMENT  CHOOSE 
     Est. Rows: 1  Cost: 6
       (14)  NESTED LOOPS 
     Est. Rows: 1  Cost: 6
           (11)  NESTED LOOPS 
                Est. Rows: 1  Cost: 5
               (9)  HASH JOIN 
                    Est. Rows: 1  Cost: 3
                   (3)  TABLE TABLE ACCESS BY INDEX ROWID DW_MGR.ORGANIZATIONS  [Analyzed] 
                   (3)   Blocks: 1,669 Est. Rows: 1 of 31,748  Cost: 1 
                        Tablespace: DIM_DATA
                       (2)  INDEX (UNIQUE) INDEX UNIQUE SCAN DW_MGR.ORG_PK  [Analyzed] 
                            Est. Rows: 1  Cost: 1
                   (8)  PARTITION RANGE SINGLE 
                        Est. Rows: 7  Cost: 1
                       (7)  PARTITION LIST ALL 
                            Est. Rows: 7  Cost: 1
                           (6)  TABLE TABLE ACCESS BY LOCAL INDEX ROWID DW_MGR.FA_TRANS_FCT  [Analyzed] 
                                Blocks: 1,431,026 Est. Rows: 7 of 32,900,663  Cost: 1
                               (5)  BITMAP CONVERSION TO ROWIDS
                                   (4)  INDEX (BITMAP) BITMAP INDEX SINGLE VALUE DW_MGR.FA_TRANS_AST_COMP_CC_BM_I
               (10)  REMOTE REMOTE.RF_FND_FLEX_VALUES_DET 
                    Est. Rows: 1  Cost: 2
           (13)  TABLE TABLE ACCESS BY INDEX ROWID DW_MGR.PROJECTS_DIM  [Analyzed] 
           (13)   Blocks: 12,184 Est. Rows: 1 of 163,117  Cost: 1 
                Tablespace: PROJECT_DATA
               (12)  INDEX (UNIQUE) INDEX UNIQUE SCAN DW_MGR.PROJECTS_UI  [Analyzed] 
                    Est. Rows: 1  Cost: 1
Run Code Online (Sandbox Code Playgroud)

用户抱怨说,当他们的WebI(商业智能)报告在其过滤器中包含多个COST CENTERS时,导致带有"IN"的SQL包含多个值,则返回以下错误:

   [1]: (Error): ORA-01722: invalid number ORA-02063: preceding line from [dbname]
Run Code Online (Sandbox Code Playgroud)

否则,对于单一的COST CENTER,报告工作正常.有趣的是,我注意到以下连接条件,对我而言似乎是UNRELATED,对SQL有负面影响:

accounts_dim_dep.account_id = dw_mgr.fa_trans_fct.depreciation_account_id
Run Code Online (Sandbox Code Playgroud)

这里的问题是左边的列accounts_dim_dep.account_id在db中定义为charchar,右边的col,dw_mgr.fa_trans_fct.depreciation_account_id定义为数字.

当我修改连接条件以将数字转换为varchar时...

accounts_dim_dep.account_id 
                       = to_char(dw_mgr.fa_trans_fct.depreciation_account_id)
Run Code Online (Sandbox Code Playgroud)

...无论过滤器中指定的COST CENTER数量如何,SQL都能正常工作.


我想知道一个看似不相关的列上的类型不匹配如何影响是否可以在IN列表中指定多个COST CENTERS.

APC*_*APC 5

ORA-02063错误意味着远程数据库中发生ORA-01722错误.这符合(根据解释计划)RF_FND_FLEX_VALUES_DET表是远程的事实.

该值accounts_dim_dep.account_id是a的别名flex_value,它似乎是varchar2,几乎肯定包含非数字值.当您将其与数字列进行比较时,Oracle会对其应用隐式TO_NUMBER(),如果它遇到的值不是数字,则会使用ORA-01722失败.通过转换 dw_mgr.fa_trans_fct.depreciation_account_id为字符串,您可以避免隐式转换.

那么,为什么原始查询在您只有一个成本中心时会成功,但在有多个成本中心时会失败?如果无法访问您的数据来运行某些测试,或者至少是不同版本的解释计划,则很难确定.但是您发布的解释计划显示远程操作仅从RF_FND_FLEX_VALUES_DET检索一行.我猜测当你运行具有多个成本中心的查询时,它会拉回一大堆行,其中包括一些flex_value具有非数字值的行.