【问题标题】:We need to mask data after a certain word to next 60 length(fixed) character [duplicate]我们需要将某个单词之后的数据屏蔽到下一个 60 长度(固定)字符 [重复]
【发布时间】:2022-01-21 22:54:39
【问题描述】:

我在屏蔽以下输入的记录时遇到了问题:

输入:

The Domain Value is 32456 is getting from Spain to Madrid for String value differently . and this is the data for all kind of variable.

输出:

The ************************************************************ring value differently . and this is the data for all kind of variable.

基本上在上面输入的“域值”是固定字,所以我们需要屏蔽从域值开始到下一个 60 长度(固定)的数据。

我正在尝试下面的查询,但它没有屏蔽到下一个 60 长度

SELECT 
  CASE 
    WHEN start_pos1 > 0 THEN SUBSTR( col, 1, start_pos1 - 1) 
        || RPAD('*', end_pos1 - start_pos1, '*') 
        || SUBSTR(col, end_pos1) 
    ELSE col 
  END AS col_new 
FROM ( 
  SELECT
    col, 
    REGEXP_INSTR( col, 'Domain Value([. # -]*\s{60}+)+', 1, 1, 0, NULL) AS start_pos1, 
    REGEXP_INSTR( col, 'Domain Value([. # -]*\s{60}+)+', 1, 1, 1, NULL) AS end_pos1,
  FROM Table 
)

【问题讨论】:

  • 您似乎问了三个非常相似的问题,但没有说明为什么为这些问题提供的答案对您不起作用。也许您需要花一些时间真正详细地阐明您的要求,然后看看您是否可以调整您已经给出的任何建议?
  • 也许您应该考虑研究数据编辑选项,看看它是否符合您的需求

标签: sql oracle


【解决方案1】:

看起来像是一些子字符串的问题:

SQL> with test (col) as
  2    (select 'The Domain Value is 32456 is getting from Spain to Madrid for String varies differently . and this is the data for all kind of variable.' from dual)
  3  select substr(col, 1, instr(col, 'Domain Value') - 1) ||
  4         lpad('*', 60, '*') ||
  5         substr(col, instr(col, 'Domain Value') + 60) result
  6  from test  ;

RESULT
--------------------------------------------------------------------------------
The ************************************************************ring varies diff
erently . and this is the data for all kind of variable.


SQL>

【讨论】:

    【解决方案2】:

    如果文本“域值”可能在文本中出现多次,则使用 regexp_replace 即可。

    with demo (col) as
         ( select 'The Domain Value is 32456 is getting from Spain to Madrid for String varies differently . and this is the data for all kind of variable.' from dual
           union all
           select 'The Domain Value is a secret.' from dual 
         )
    select regexp_replace(col, 'Domain Value.{1,48}', rpad('*',60,'*')) as redacted
    from   demo;
    

    DBFiddle

    【讨论】:

      猜你喜欢
      • 2022-01-09
      • 2022-01-20
      • 2021-03-05
      • 2015-06-25
      • 1970-01-01
      • 2010-12-13
      • 1970-01-01
      • 1970-01-01
      • 2015-05-08
      相关资源
      最近更新 更多