提取数据如果

发布于 2025-02-06 02:41:17 字数 386 浏览 5 评论 0原文

我是SQL的新手,并接受了培训,使我能够在3月使用SSR,但我们也有Oracle DB。

我需要提取可以在称为家庭电话,工作电话或手机的列中保存的电话号码,但我只想在数字启动07但也限制为11位时提取。这里的问题是数字可以在所有或任何3列中。

如果数字以07以外的其他内容开头,或者数据具有文本,我想用空白替换。

我已经考虑使用

“”选择家庭电话, 工作电话, 移动号

DB的 在哪里家庭手机,例如“ 07”% 和像'07'%的手机一样 移动不像“ 07'%”''

,但这大大减少了预期的数据集。

我已经看了替换和regexp-replact,但在一分钟内不能完全抓住我的头。任何帮助都非常感谢,我认为如果不是11位手机号码,则要导出所有数据,只有空白。

I am new to SQL and had training to enable me to use SSRS in March but we also have an oracle DB.

I need to extract phone numbers which can be held in columns called home phone, work phone or mobile phone but I want to only extract if the number starts 07 but also limit to 11 digits. The issue here is the number could be in all or any 3 of the columns.

If the number starts with anything other than 07 or if the data has text, I want to replace this with a blank.

I have looked at using

'''Select home phone,
Work phone,
Mobile no

From DB
Where home phone like '07'%
And work phone like '07'%
And mobile no like '07'%'''

But this massively reduces the data set as expected.

I have looked at replace and regexp-replace but can't quite get my head around this bit at the minute. Any help much appreciated, I think want to export all of the data just have a blank if it's not an 11 digit mobile number.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

却一份温柔 2025-02-13 02:41:17

您应该放置或放在查询中。由于您提到您只想导出数据,因此我认为查询是将电话号码格式化如下:

SELECT
  CASE
    WHEN SUBSTR(HOME_PHONE, 1, 2) = '07' --START WITH '07'
        AND LENGTH(HOME_PHONE) = 11      --11 DIGITS
        AND LENGTH(TRIM(TRANSLATE('HOME_PHONE', ' +-.0123456789', ' '))) IS NULL --CONTAIN ONLY NUMBER
      THEN HOME_PHONE
    ELSE '' --RETURN BLANK IF CONDITION NOT MATCHED
  END AS HOME_PHONE
FROM DATA_TBL

您可以将其应用于SELECT work_phone和Mobile_phone。

如果这不是您想要的,请提供示例数据和所需的输出,以便我更容易复制。

You should put OR instead of AND in your query. Since you mentioned you want to export data only so I think the query is to format the phone number as below:

SELECT
  CASE
    WHEN SUBSTR(HOME_PHONE, 1, 2) = '07' --START WITH '07'
        AND LENGTH(HOME_PHONE) = 11      --11 DIGITS
        AND LENGTH(TRIM(TRANSLATE('HOME_PHONE', ' +-.0123456789', ' '))) IS NULL --CONTAIN ONLY NUMBER
      THEN HOME_PHONE
    ELSE '' --RETURN BLANK IF CONDITION NOT MATCHED
  END AS HOME_PHONE
FROM DATA_TBL

You can apply the same to select WORK_PHONE and MOBILE_PHONE.

If this is not what you are looking for, please give sample data and desired output so it would be easier for me to replicate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文