我在SAP HANA上有一些表和“创建列表”来组合多个“原始表”,并且需要替换新创建表中一列的字符串。表名“ Testsubject_status”列名“ STATUS”。 我需要替换字符串的原因是为了使特定条目的措辞统一。 通过以下示例,希望可以更清楚我的意思:
表名称:Testsubject_status ---列:状态
结果应为
表名称:Testsubject_status ---列:状态
我尝试了以下操作:
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
);
创建表正在工作。 Replace_Regexpr语句仅在不与create column table语句一起运行,然后仅创建一个包含一列且每行条目为“ TEST with%”的表时起作用。
其他信息:
不确定以这种方式创建表格是否是最好的表格,但我想那是另一回事了
提前感谢您的输入!
答案 0 :(得分:0)
@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
);
这将产生一个包含以下示例数据的表
请注意,如果给定条件匹配,则STATUS列将替换为静态文本。否则状态文本将保持不变
对于其他信息,我添加了以下表达式,但我不太喜欢 也许有更好的解决方案
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"
您可以在表定义脚本中添加一个新的计算列
我假设您在表格数据中有以下状态文本: