表中的最大长度值

时间:2019-01-01 15:39:58

标签: sql oracle

我有一张桌子,我想知道“ phone_number”和email_address字段上存在的最大长度值是什么。

我想知道是否存在任何输入的值大于允许的值。

这是我的查询

    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
  , 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 = ''
;

2 个答案:

答案 0 :(得分:1)

如果要在表的给定字段中找到具有最大字段长度的行,请尝试以下查询。

com/pe/queries/

答案 1 :(得分:0)

一个字段的最大长度:

SELECT MAX(LENGTH(email_address)), MAX(LENGTH(phone_number)) FROM hz_contact_points

不需要分组依据,因为您正在汇总整个集合。请注意,这告诉您已知的最长数据(例如,它将返回72),但仅告诉您其他信息。然后,您将不得不再次查询以找到这种长度的行:

SELECT * 
FROM hz_contact_points 
WHERE LENGTH(email_address) = 72

例如,按电子邮件长度降序排列的前10行可能更容易:

SELECT * FROM (
  SELECT * 
  FROM hz_contact_points 
  ORDER BY LENGTH(email_address) DESC
) a
WHERE rownum <= 10

(如果您使用的是oracle12c +,则可以取消外部查询并编写FETCH FIRST 10 ROWS ONLY

具有多个电子邮件地址的行:

SELECT * 
FROM hz_contact_points 
WHERE email_address LIKE '%@%@%'