I FOUND MY MISTAKE!!! This is wrong CASE WHEN regexp_substr(artikel.abez1,'[^/]*$') AS download,
I just deleted 'Case when' and it works! Thank you everyone! :)
I have this data:
DE-Internet-LTE
AE-Internet-Ethernet-10M/30M
How can I get only the value "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".
I'm using SQL Tool 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 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 /
`
it gives error ora-00920 invalid relational operator.
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. If you really want 10M, then this should do what you want:
select regexp_substr(regexp_substr(t.abez1, '([^-/]+)/[^-/]+$'), '^[^-/]+') AS upload
from t;
Here is a 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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.