简体   繁体   English

SQL-SAP HANA-列表中的REPLACE_REGEXPR

[英]SQL - SAP HANA - REPLACE_REGEXPR in Column table

I have some tables on SAP HANA and „create column table“ to combine multiple „raw tables“ and need to replace strings from one column in the newly created table. 我在SAP HANA上有一些表和“创建列表”来组合多个“原始表”,并且需要替换新创建表中一列的字符串。 Tablename “Testsubject_status” Column name “STATUS”. 表名“ Testsubject_status”列名“ STATUS”。 The reason why I need to replace the strings, is to get a harmonized wording on specific entries. 我需要替换字符串的原因是为了使特定条目的措辞统一。 With the following example, it is hopefully more clear what I mean: 通过以下示例,希望可以更清楚地理解我的意思:

Table name: Testsubject_status --- Column: Status 表名称:Testsubject_status ---列:状态

  • Test me 考验我
  • Test him 测试他
  • Test with the ID 1237 is done ID 1237的测试已完成
  • Test her 测试她
  • Test with the ID 928162 is done ID 928162的测试完成
  • Test with the ID 991 is done ID 991的测试已完成

The result should be 结果应该是

Table name: Testsubject_status --- Column: Status 表名称:Testsubject_status ---列:状态

  • Test me 考验我
  • Test him 测试他
  • Test is done 测试完成
  • Test her 测试她
  • Test is done 测试完成
  • Test is done 测试完成

I tried the following: 我尝试了以下方法:

CREATE COLUMN TABLE SCHEMATTT.Testsubject_status AS (
    Select
        Table1.Person AS “Person”,
        Table1.Vers AS “Vers”,
        Table2.Flnr AS “Flnr”,
        Table3.Status AS “Status”
FROM 
    SCHEMATTT.Table1, SCHEMATTT.Table2, SCHEMATTT.Table3 
WHERE SCHEMATTT.Table1.Person = SCHEMATTT.Table2.Person
AND SCHEMATTT.Table2.Flnr = SCHEMATTT.Table3.Flnr


SELECT
REPLACE_REGEXPR (‘with the id \d{1,}’ IN ‘TEST with %’ WITH ‘’) “replace_regexpr”
FROM SCHEMATTT.Testsubject_status
);

Creating the table is working. 创建表正在工作。 The Replace_Regexpr statement is only working if I do not run it together with the create column table statement and then only creates a table with one column and the entries 'TEST with %' in every row. Replace_Regexpr语句仅在我不与create column table语句一起运行时才起作用,然后仅创建一个包含一列的表,并且每行中都有条目“ TEST with%”。

Additional info: 附加信息:

  • There is not only the “Test is done” string that needs to be harmonized, but a few others as well. 不仅需要协调“测试完成”字符串,而且还有一些其他字符串需要协调。 So I need to use the replace statement more than once in this specific column “Status” 因此,我需要在此特定列“状态”中多次使用replace语句
  • The "Test is done" Statement is not 1:1 with another Statement in the table, so the other statements can't be used in any way to do this :-) “测试完成”语句与表中的另一条语句不是1:1的关系,因此不能以任何方式使用其他语句:-)

Not sure if creating the table in this way is the best one, but I guess that's another story  不确定以这种方式创建表格是否是最好的表格,但我想那是另一回事了。

Thank you in advance for your input! 预先感谢您的输入!

This Picture is for clarification in the comments: 该图片用于在注释中进行说明: 状态条目和所需的修改

@Mike, could you please try following SQLScript command @Mike,能否请您尝试执行以下SQLScript命令

CREATE COLUMN TABLE Testsubject_status2 AS (
Select
    Table1.Person AS "Person",
    Table1.Vers AS "Vers",
    Table2.Flnr AS "Flnr",
    Table3.Status AS "Status",
    REPLACE_REGEXPR ('test with the id [[:digit:]]* is done' FLAG 'i' IN Table3.STATUS WITH 'Test is done') "replace_regexpr"
FROM 
   Table1, Table2, Table3 
WHERE Table1.Person = Table2.Person
AND Table2.Flnr = Table3.Flnr
);

This will produce a table with following sample data 这将产生一个包含以下示例数据的表

在此处输入图片说明

Note that the STATUS column is replaced with a static text if there is a match for the given condition. 请注意,如果给定条件匹配,则STATUS列将替换为静态文本。 Else the STATUS text is kept as it is 否则,STATUS文本将保持原样

For the additional info, I added following expressions but I did not like it much Maybe there are better solutions 对于其他信息,我添加了以下表达式,但我不太喜欢,也许有更好的解决方案

REPLACE_REGEXPR (
    '(test with the id|Deployment for the ID) [[:digit:]]* is (done|completed)' 
    FLAG 'i' 
    IN Table3.STATUS 
    WITH 
        case 
            when Table3.STATUS LIKE_REGEXPR('test') Flag 'i' then 'test is done' 
            when Table3.STATUS LIKE_REGEXPR('deploy') Flag 'i' then 'deployment is done' 
            else Table3.STATUS
        end 
)  as "replace_regexpr_ext"

You can add this add a new calculated column in your table definitions script 您可以在表定义脚本中添加此添加新的计算列

I assume you have following status text in your table data: 我假设您在表数据中具有以下状态文本:

  • Deployment for the ID 234 is completed ID 234的部署已完成
  • Deploy development 部署开发

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM