简体   繁体   English

SQL-SAP HANA-控制台内容太长-将一些代码传递给过程?

[英]SQL - SAP HANA - Console Content to long - Pass some code to a procedure?

I have an SQL Script in my SAP HANA SQL Console with ~1700 rows. 我的SAP HANA SQL控制台中有一个约1700行的SQL脚本。 I have so many rows, as I need to change alot of entries in one column which is imported from one "raw table". 我有很多行,因为我需要更改从一个“原始表”导入的一列中的很多条目。 More detailed description about this "change row entries" problem The repetitive WHEN THEN Code looks like: ` 关于此“更改行条目”问题更详细描述重复的WHEN THEN代码如下:

Create Column Table xxx
Select Distinct 
   aaa AS "aaa",
   bbb AS "bbb",
   ccc AS "ccc",
   CASE 
      WHEN importedColumn like 'xx123x' THEN REPLACE_REGEXPR ('xx123x' FLAG 'i' IN importedColumn WITH 'xxx')
      WHEN importedColumn like 'yy345y' THEN REPLACE_REGEXPR ('yy345y' FLAG 'i' IN importedColumn WITH 'yyy') 
      WHEN importedColumn like 'zzz345z' THEN REPLACE_REGEXPR ('zzz345z'FLAG 'i' IN importedColumn WITH 'zzzz') 
      etc.
      etc. 
      ELSE xxx 
   END AS replace_regexpr 
FROM...
WHERE...

This (generally) works fine. (通常)可以正常工作。 The problem is, I have so many different WHEN THEN Statements (Always checking the entries of this one column and maybe change them) that I cannot execute the Code anymore -> SQL console Content is too large. 问题是,我有太多不同的WHEN THEN语句(总是检查这一列的条目并可能更改它们),以致我无法执行代码了-> SQL console内容太大。 Can I extract this case Statement somehow and store it in an procedure or something like this? 我可以以某种方式提取此case语句并将其存储在过程或类似的东西中吗? I really have no clue how I can handle this, so I am happy for every advise! 我真的不知道该如何处理,因此我很乐意为您提供建议!

  • Note: The column entries that need to be changed do not have any common pattern, so I cannot group them or something like this. 注意:需要更改的列条目没有任何通用模式,因此我无法对它们进行分组或类似的操作。 This means that I need that many WHEN THEN Statements. 这意味着我需要很多WHEN THEN语句。

From this and the linked question I take it that you have a single REGEX rule that should be applied to the input data if and only if a certain pattern is found (compared via LIKE operator). 从这个问题和链接的问题中,我认为您只有一个REGEX规则,当且仅当找到特定模式时才应将其应用于输入数据(通过LIKE运算符进行比较)。

I would put all matching pattern and replacement rules into a separate table, making maintenance, debugging and the SELECT statement a lot easier: 我会将所有匹配的模式和替换规则放在单独的表中,从而使维护,调试和SELECT语句更加容易:

create column table xxx (id int primary key
                       , "impColumn" nvarchar(4000)
);

create column table rules (id int primary key
                         , matcher nvarchar(4000)
                         , regex nvarchar(4000));       

insert into rules values (1, 'xx123x', 'xxx');
insert into rules values (2, 'yy345y', 'yyy');
insert into rules values (3, 'zzz345z', 'zzz');


insert into xxx values (1, 'xx123x');
insert into xxx values (2, 'yy345y');
insert into xxx values (3, 'zzz345z');

insert into xxx values (4, 'xx123xyy345y');
insert into xxx values (5, 'xx1zzz345zzzz345z23x');
insert into xxx values (6, 'xx123xyy345yzzz345z');

select
    x.*,
    r.*,
    REPLACE_REGEXPR (r.matcher
                    FLAG 'i' 
                    IN x."impColumn"  
                    WITH r.regex) as output
from 
    xxx x
    left outer join
    rules r
    on x."impColumn" like   r.matcher  ;

You could change the join condition to on x."impColumn" like '%'|| 您可以将连接条件更改为x。“ impColumn”,例如'%'||。 r.matcher ||'%' r.matcher ||'%'

to apply all matching rules to the input rows, but be aware that this produces one output row per applied rule, which is probably not what you want. 将所有匹配的规则应用于输入行,但是请注意,这会为每个应用的规则生成一个输出行,这可能不是您想要的。

The output without the placeholder looks like this: 没有占位符的输出如下所示:

在此处输入图片说明

Which is pretty much the same what your example SQL produces. 您的示例SQL产生的结果几乎相同。

As for the problem in SAP HANA Studio, I guess that this is due to the sheer size of the script file you try to run. 至于SAP HANA Studio中的问题,我这是由于您尝试运行的脚本文件的大小所致。 By editing the JRE VM memory for HANA Studio you may be able to avoid this problem. 通过为HANA Studio编辑JRE VM内存,您可以避免此问题。

Please check the hdbstudio.ini and set the VM parameter to 请检查hdbstudio.ini并将VM参数设置为

  • -Xmx4096m
  • -Xms512m

and restart HANA Studio. 并重新启动HANA Studio。

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

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