【问题标题】:Trim numbers at beginning and at the end在开头和结尾修剪数字
【发布时间】:2019-03-13 11:08:46
【问题描述】:

我的身份证号格式如下

70800123467

我需要的 ID 要求我从开头删除 708,从末尾删除 67,留下 001234。

【问题讨论】:

  • 使用哪种编程语言?开始总是 708,或者你想删除前 3 位数字。还有更多...请改进您的问题。
  • 给定用户名,我们可以猜到 SQL,但我们仍然需要知道它是哪个 RDBMS,所以请用编程语言或sql 以及您正在使用的数据库标记您的问题。

标签: sql string oracle trim


【解决方案1】:

您可以将 SUBSTR 用于 Oracle 数据库:

SUBSTR('70800123467', 4, 8) -- remove first 3 chars from a string with length of 11
SUBSTR('70800123467', -3, 8) -- remove last 2 chars from a string with length of 11

所以,正确地嵌套这两个:

SUBSTR(SUBSTR('70800123467', 4, 8), -3, 6)

会如你所愿返回001234。

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 2011-03-01
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    相关资源
    最近更新 更多