简体   繁体   English

正则表达式

[英]Regular Expression

I FOUND MY MISTAKE!!!我发现了我的错误!!! This is wrong CASE WHEN regexp_substr(artikel.abez1,'[^/]*$') AS download,这是错误的CASE WHEN regexp_substr(artikel.abez1,'[^/]*$') AS download,

I just deleted 'Case when' and it works!我刚刚删除了“Case when”,它起作用了! Thank you everyone!谢谢大家! :) :)

I have this data:我有这个数据:

  1. DE-Internet-LTE

  2. AE-Internet-Ethernet-10M/30M

How can I get only the value "10M"?我怎样才能只得到值“10M”? and if there's none, I want it to return to null.如果没有,我希望它返回空值。

I used this query:我使用了这个查询:

regexp_substr(artikel.abez1,'[^-/]*$') AS upload

On the second row, it gives the result "10M" but on the first row it return to "LTE" instead of "null".在第二行,它给出结果“10M”,但在第一行,它返回“LTE”而不是“null”。

I'm using SQL Tool 1.8 b38.我正在使用 SQL 工具 1.8 b38。

UPDATE: My full query: `更新:我的完整查询:`

SELECT DISTINCT artikel.artnr1, L1.lfnr1 AS lfnr, L1.name1 AS lf_name, artikel.abez1, regexp_substr(artikel.abez1,'(. ?){1}(. ?)-', 1, 1, '', 2) AS land, regexp_substr(artikel.abez1,'(. ?-){1}(. ?)-', 1, 1, '', 2) AS Technologie, CASE WHEN regexp_substr(artikel.abez1,'(. ?-){2}(. ?)-', 1, 1, '', 2) IS NULL THEN regexp_substr(artikel.abez1,'[^-] $') ELSE regexp_substr(artikel.abez1,'(. ?-){2}(. ?)-', 1, 1, '', 2) END AS Topologie, regexp_substr(regexp_substr(artikel.abez1, '([^-/]+)/[^-/]+$'), '^[^-/]+') AS upload, CASE WHEN regexp_substr(artikel.abez1,'[^/] $') AS download, bestanfragepos.preis / bestanfrage.bwkurs, 'Anfrage' AS Art, To_Char(bestanfrage.lfdanfrage), bestanfrage.anfragedatum, CASE WHEN InStr(angaufgut.reserve1, '.') > 1 THEN Months_Between( bestanfrage.anfragedatum, To_Date(angaufgut.reserve1)) ELSE To_Number(angaufgut.reserve1) end AS Laufzeit FROM artikel inner join modell ON modell.lfdnr = artikel.lfdmodnr left join bestanfragepos ON artikel.lfdnr = bestanfragepos.lf SELECT DISTINCT artikel.artnr1, L1.lfnr1 AS lfnr, L1.name1 AS lf_name, artikel.abez1, regexp_substr(artikel.abez1,'(. ?){1}(. ?)-', 1, 1, '', 2) AS 地, regexp_substr(artikel.abez1,'(. ?-){1}(. ?)-', 1, 1, '', 2) AS Technologie, CASE WHEN regexp_substr(artikel.abez1,'(. ?-){2}(. ?)-', 1, 1, '', 2) IS NULL THEN regexp_substr(artikel.abez1,'[^-] $') ELSE regexp_substr(artikel.abez1,'(. ? -){2}(. ?)-', 1, 1, '', 2) END AS Topologie, regexp_substr(regexp_substr(artikel.abez1, '([^-/]+)/[^-/]+$ '), '^[^-/]+') AS 上传, CASE WHEN regexp_substr(artikel.abez1,'[^/] $') AS 下载, bestanfragepos.preis / bestanfrage.bwkurs, 'Anfrage' AS Art, To_Char (bestanfrage.lfdanfrage), bestanfrage.anfragedatum, CASE WHEN InStr(angaufgut.reserve1, '.') > 1 THEN Months_Between( bestanfrage.anfragedatum, To_Date(angaufgut.reserve1)) ELSE To_Number(angaufgut) from artlikefreserve1内连接模型 ON modell.lfdnr = artikel.lfdmodnr left join bestanfragepos ON artikel.lfdnr = bestanfragepos.lf dartnr left join bestanfrage ON bestanfragepos.lfdanfrage = bestanfrage.lfdanfrage left join lieferant L1 ON L1.liefnr = bestanfrage.lfdliefnr left JOIN angaufgut ON bestanfragepos.lfdangaufgutnr = angaufgut.lfdnr WHERE Lower(modcode) LIKE 'ac%' AND Lower(abez1) NOT LIKE 'cust%' and artikel.mandant = 1 AND bestanfragepos.preis != 0 ORDER BY abez1 / dartnr 左加入 bestanfrage ON bestanfragepos.lfdanfrage = bestanfrage.lfdanfrage left 加入lieferant L1 ON L1.liefnr = bestanfrage.lfdliefnr left JOIN angaufgut ON bestanfragepos.lfdangaufgutnr = angaufgut.lfmodnr WHERE 下 (L1.liefnr = bestanfrage.lfdliefnr)不喜欢 'cust%' 和 artikel.mandant = 1 AND bestanfragepos.preis != 0 ORDER BY abez1 /

` `

it gives error ora-00920 invalid relational operator.它给出了错误 ora-00920 无效的关系运算符。

It only worked on a single data when I used this:当我使用它时,它仅适用于单个数据:

SELECT regexp_substr(regexp_substr(artikelbez, '([^-/]+)/[^-/]+$'), '^[^-/]+') FROM nag_reporting_leitungspreise WHERE art = 'Vertrag' AND REF = 3791

Your code returns 30M.您的代码返回 30M。 If you really want 10M, then this should do what you want:如果你真的想要 10M,那么这应该做你想做的:

select regexp_substr(regexp_substr(t.abez1, '([^-/]+)/[^-/]+$'), '^[^-/]+') AS upload
from t;

Here is a db<>fiddle. 是一个 db<>fiddle。

with t(str) as (
select * from table(ku$_vcnt(
'DE-Internet-LTE',
'AE-Internet-Ethernet-10M/30M',
'AE-Internet-Ethernet-20m/40m',
'AE-Internet-Ethernet-300M/500M',
'AE-Internet-Ethernet-4000k/600k',
'AE-Internet-Ethernet-200M'
))
)
select 
  str, 
  regexp_substr(str, '(\d+(k|m))(/\d+(k|m))?',1,1,'i',1) upload,
  regexp_substr(str, '/(\d+(k|m))',1,1,'i',1) download
from t;

Results:结果:

STR                                 UPLOAD  DOWNLOAD
----------------------------------- ------- --------
DE-Internet-LTE
AE-Internet-Ethernet-10M/30M        10M     30M
AE-Internet-Ethernet-20m/40m        20m     40m
AE-Internet-Ethernet-300M/500M      300M    500M
AE-Internet-Ethernet-4000k/600k     4000k   600k
AE-Internet-Ethernet-200M           200M

Just have a look at the below solution:看看下面的解决方案:

with t(str) as 
(
    select  column_value 
    from    table(sys.odcivarchar2list(
            'DE-Internet-LTE',
            'AE-Internet-Ethernet-10M/30M',
            'AE-Internet-Ethernet-20m/40m',
            'AE-Internet-Ethernet-300M/500M',
            'AE-Internet-Ethernet-4000k/600k',
            'AE-Internet-Ethernet-200M'
            ))
)
select  str, 
        regexp_substr(str, '-(\d+.*?)(/|$)',1,1,null,1) as upload,
        regexp_substr(str, '/(\d+.*?)$',1,1,null,1) as download,
        regexp_substr(regexp_substr(str, '([^-/]+)/[^-/]+$'), '^[^-/]+') as Gordan_Linoff_upload
from    t;

Output:输出:

在此处输入图片说明

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

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