Oracle E-Business-Suite中的表(联系数据)

时间:2019-01-04 14:41:50

标签: sql oracle oracle11g

我正在使用连接到Oracle数据库(11g)的SQL DEVELOPER

看看这个: Explanation_tables

这就是我想要做的(我将添加另一张图片)

Image_1

这是我的查询

SELECT
    hp.party_name                              
  , hca.account_number
  , hca.cust_account_id                        
 -- , hcsu.LOCATION customer_site_name
  , hcas.cust_acct_site_id                     
  , hcp.phone_number
  , hcp.email_address
  , CASE WHEN LENGTH(hcp.phone_number) > 25 then null else hcp.phone_number END
  , hl.address1
  , hl.address2
  , hl.address3
  , hl.address4
  , hl.city
  , hl.province
  , hl.postal_code
  , hcas.status                                
  , DECODE( hcas.attribute5, 'PUP', 'Y', 'N' ) 
  , hca.status                                 
FROM apps.hz_cust_accounts hca
INNER JOIN apps.hz_cust_acct_sites_all hcas ON hca.cust_account_id = hcas.cust_account_id
INNER JOIN apps.hz_party_sites hps ON hcas.party_site_id = hps.party_site_id
INNER JOIN apps.hz_locations hl ON hps.location_id = hl.location_id
INNER JOIN apps.hz_parties hp ON hps.party_id = hp.party_id
LEFT JOIN (
        SELECT
            owner_table_id
          , max(case when contact_point_type = 'PHONE' then phone_number end) phone_number
          , max(case when contact_point_type = 'EMAIL' then email_address end) email_address
        FROM hz_contact_points
        WHERE status = 'A'
        AND primary_flag = 'Y'
        AND owner_table_name = 'HZ_PARTY_SITES'
        AND contact_point_type IN ('EMAIL','PHONE')
        GROUP BY 
            owner_table_id
    ) hcp ON hcas.party_site_id = hcp.owner_table_id 
WHERE hcas.status = 'A'
AND hps.status = 'A'
AND hca.status = 'A'
AND hca.account_number = '008776'
;

每次执行查询时,我都会得到:

Image_2

这不是我想要的。

我一直在尝试解决此问题,更改此条件:

hcp ON hcas.party_site_id = hcp.owner_table_id

但是我不知道,我认为主要问题是这种状况,

你能帮我吗?我不知道该怎么办。

更新:

IMAGE4

这是为客户创建联系电子邮件的方式,看看:

  l_contact_point_rec.contact_point_type     := 'EMAIL';--p_contact_rec.contact_point_type;


  IF p_contact_rec.orig_system_address_ref  IS NULL THEN

     l_contact_point_rec.owner_table_name       := 'HZ_PARTIES';
     l_contact_point_rec.owner_table_id         := l_party_id; --l_contact_party_id;
  ELSE

     l_contact_point_rec.owner_table_name       := 'HZ_PARTY_SITES';
     l_contact_point_rec.owner_table_id         := l_party_site_id;
  END IF;

  l_contact_point_rec.primary_flag           := 'Y';
  l_contact_point_rec.contact_point_purpose  := 'PORTAL';
  --This should exists in HZ_CREATED_BY_MODULES Lookup
  l_contact_point_rec.created_by_module      := 'TCA_V2_API';
  l_contact_point_rec.application_id         := '222';


  l_email_rec.email_format                   := 'MAILHTML';
  l_email_rec.email_address                  := p_contact_rec.email_address;

  hz_contact_point_v2pub.create_contact_point (
                                               p_init_msg_list     =>  'T'                ,
                                               p_contact_point_rec =>  l_contact_point_rec,
                                               p_edi_rec           =>  l_edi_rec          ,
                                               p_email_rec         =>  l_email_rec        ,
                                               p_phone_rec         =>  l_phone_rec        ,
                                               p_telex_rec         =>  l_telex_rec        ,
                                               p_web_rec           =>  l_web_rec          ,
                                               x_contact_point_id  =>  l_contact_point_id ,
                                               x_return_status     =>  l_return_status    ,
                                               x_msg_count         =>  l_msg_count        ,
                                               x_msg_data          =>  l_msg_data
                                              );


  debug_msg (l_calling_sequence||'***************************');
  debug_msg (l_calling_sequence||' Output hz_contact_point_v2pub.create_contact_point EMAIL....');
  debug_msg (l_calling_sequence||'l_return_status: '||l_return_status);
  debug_msg (l_calling_sequence||'l_msg_count: '||l_msg_count);
  debug_msg (l_calling_sequence||'l_msg_data: '||l_msg_data);
  IF l_return_status != 'S' THEN
    FOR I IN 1..l_msg_count
    LOOP
      debug_msg (l_calling_sequence||'. '||SubStr(FND_MSG_PUB.Get(p_encoded => FND_API.G_FALSE ), 1, 255));
      l_msg_data := l_msg_data ||('. '||SUBSTR( FND_MSG_PUB.Get(
                                                                p_encoded => FND_API.G_FALSE )
                                                                ,1, 255
                                                               )
                                              );

    END LOOP;
    RAISE e_error;
  END IF;

新图像:

JUY

NEW IMAGE#2:

HYT

LINK:

https://www.mediafire.com/file/8xncjoj8l8gdy7d/results.xlsx/file

1 个答案:

答案 0 :(得分:0)

如果p_contact_rec.orig_system_address_ref是NULL则

 l_contact_point_rec.owner_table_name       := 'HZ_PARTIES';

所以,我认为您必须在owner_table_name ='HZ_PARTY'之后查找hz_contact_points。 而且,如果我看一下关系架构,hp可以直接链接到hca。 你可以试试这个吗?

SELECT
    hp.party_name                              
  , hca.account_number
  , hca.cust_account_id                        
 -- , hcsu.LOCATION customer_site_name
  , hcas.cust_acct_site_id                     
  , hcp.phone_number
  , hcp.email_address
  , CASE WHEN LENGTH(hcp.phone_number) > 25 then null else hcp.phone_number END
  , hl.address1
  , hl.address2
  , hl.address3
  , hl.address4
  , hl.city
  , hl.province
  , hl.postal_code
  , hcas.status                                
  , DECODE( hcas.attribute5, 'PUP', 'Y', 'N' ) 
  , hca.status                                 
FROM apps.hz_cust_accounts hca
INNER JOIN apps.hz_parties hp ON hca.party_id = hp.party_id
INNER JOIN apps.hz_cust_acct_sites_all hcas ON hca.cust_account_id = hcas.cust_account_id
INNER JOIN apps.hz_party_sites hps ON hcas.party_site_id = hps.party_site_id
INNER JOIN apps.hz_locations hl ON hps.location_id = hl.location_id
--INNER JOIN apps.hz_parties hp ON hps.party_id = hp.party_id
LEFT JOIN (
        SELECT
            owner_table_id
          , max(case when contact_point_type = 'PHONE' then phone_number end) phone_number
          , max(case when contact_point_type = 'EMAIL' then email_address end) email_address
        FROM hz_contact_points
        WHERE status = 'A'
        AND primary_flag = 'Y'
        AND owner_table_name = 'HZ_PARTY'
        AND contact_point_type IN ('EMAIL','PHONE')
        GROUP BY 
            owner_table_id
    ) hcp ON hcas.party_site_id = hcp.owner_table_id 
WHERE hcas.status = 'A'
AND hps.status = 'A'
AND hca.status = 'A'
AND hca.account_number = '008776'