REGEXP gives different outputs - sql

I've used REGEXP to find text patterns, but I'm having a problem with one part of it. I'd like to classify a ticketing fare calculation line as having only 1 of the following labels:
blank (there are no Q surcharges)
QCPN (there are only instance(s) of the existing format Q20.00)
QPRO (there are only instance(s) of the new additional format Q LONSYD20.00)
QBOTH (there are examples of both QCPN and QBOTH)
Below SQL:
SELECT JOUR.JOUR_FSERNR
AS TICKET,
CASE
WHEN REGEXP_LIKE (
JOUR.JOUR_FCA1LN
|| JOUR.JOUR_FCA2LN
|| JOUR.JOUR_FCA3LN
|| JOUR.JOUR_FCA4LN,
'Q[[:space:]][[:alpha:]]{6}')
THEN
'QPRO'
WHEN REGEXP_LIKE (
JOUR.JOUR_FCA1LN
|| JOUR.JOUR_FCA2LN
|| JOUR.JOUR_FCA3LN
|| JOUR.JOUR_FCA4LN,
'Q[[:digit:]]+\.[[:digit:]]+.*END')
THEN
'QCPN'
WHEN REGEXP_LIKE (
JOUR.JOUR_FCA1LN
|| JOUR.JOUR_FCA2LN
|| JOUR.JOUR_FCA3LN
|| JOUR.JOUR_FCA4LN,
'Q[[:space:]][[:alpha:]]{6}')
AND REGEXP_LIKE (
JOUR.JOUR_FCA1LN
|| JOUR.JOUR_FCA2LN
|| JOUR.JOUR_FCA3LN
|| JOUR.JOUR_FCA4LN,
'[[ALPHA]]{3}Q[[:digit:]]+\.[[:digit:]]')
THEN
'QBOTH'
ELSE
NULL
END
AS QTYPE,
( (JOUR.JOUR_FCA1LN || JOUR.JOUR_FCA2LN) || JOUR.JOUR_FCA3LN)
|| JOUR.JOUR_FCA4LN
AS FARECALC
FROM "S00BJOUR" JOUR
WHERE JOUR.JOUR_FSERNR = '9999889652'
If you look at the above SQL and find the CASE WHEN line that outputs 'QCPN', you'll see there's an "END" text string 'Q[[:digit:]][[:graph:]]END'. I put ‘END’ in there because I only want the REGEXP to look to the left of 'END' in a fare calc line.
But it gives me some incorrect outputs as shown in the attached image Incorrect Outputs in RED:
Any help to have this corrected is much appreciated.

It feels strange, you don't put so much quantifier. Like QCPN, whathever it means shoudld be :
Q[[:digit:]]{2}\.[[:digit:]]{2}
To match your Q20.00 example at least.
EDIT :
In your "with end exemple", didnt work because you dont put any quantifier :
Q[[:digit:]][[:graph:]]END
#Match Q5.END, Q22END, Q8AEND
#Dont match Q20.00 END
But :
Q[[:digit:]]+\.[[:digit:]]+.*END
#Match "Q1.2 ZA VD END Q20.2"
#Dont match "Q5.END", "BF END Q10.25"
For the second problem, QPRO/QBOTH, the probleme is :
Q HAMAOQ20.00
Try
[[:space:]]Q[[:digit:]]+\.[[:digit:]]+.
For QCPN regex.

Related

HANA DB : How to use CONCAT syntax more than 2 fields

I'm using query in HANA Studio , It's work
CASE WHEN T0."U_XXX_SalEmp2" is not null THEN CONCAT
(T7."SlpName",CONCAT ('+',T0."U_XXX_SalEmp2")) ELSE T7."SlpName" END
AS"Sales Emp",
But I want to CONCAT more fields
**For Example :** CASE WHEN T0."U_XXX_SalEmp2" is not null THEN CONCAT (T7."SlpName",CONCAT ('+',T0."U_XXX_SalEmp2"),**CONCAT
('+',T0."U_XXX_SalEmp3"**),**CONCAT ('+',T0."U_XXX_SalEmp4"**)) ELSE
T7."SlpName" END AS"Sales Emp",
You can use the two pipe symbols || for chained concatenation.
Your example would look like this:
CASE
WHEN T0."U_ISS_SalEmp2" is not null
THEN
T7."SlpName" || '+' ||
T0."U_ISS_SalEmp2" || '+' ||
T0."U_ISS_SalEmp3" || '+' ||
T0."U_ISS_SalEmp4"
ELSE
T7."SlpName"
END AS "Sales Emp"

Oracle SQL: Using CHR() function with || concatenate and join

Query below returns error
SELECT 'mailto:'|| fscp.parameter_value || '?subject=' || wfn.subject nid_subject || chr(38)
FROM apps.wf_notifications wfn, apps.fnd_svc_comp_param_vals_v fscp
WHERE fscp.component_id = :component_id
AND component_parameter_id = :param
AND wfn.item_key = :itemkey;
Error
ORA-00923: FROM keyword not found where expected
00923.00000 - "FROM keyword not found where expected"
When I remove the '|| chr(38)' at the end of the select statement, the query runs fine.
Something related to joining tables? Because the below query also works fine:
select 'Text: '||chr(39)||wfn.notification_id||chr(39) from wf_notifications wfn;
You have this in the select:
|| wfn.subject nid_subject ||
Perhaps you intend:
SELECT 'mailto:'|| fscp.parameter_value || '?subject=' || wfn.subject || nid_subject || chr(38)
----------------------------------------------------------------------^
Alex is right. The key in the question is that it works without chr(38). So, try this:
SELECT ('mailto:'|| fscp.parameter_value || '?subject=' || wfn.subject || chr(38) ) as nid_subject
Notice the use of parentheses and as to make it clear that a column alias is being defined.

While function how do I use both & and |

I am a total noob so when I explain simple stuff, it's not because I'm retarded, it's just that I want to know if I think wrong or right.
I have 2 variables at first, x1 and y1. I put them in a while () like this
while ( y1<0 || y1>500 || x1<0 || x1>500)
I read this as "when one of these "things" are true, it will do the while function.
So for example if y1=601, y1>500 is true, the other 3 are false but it goes into the function since only 1 need to be true.
Now here's where I get problem, I want to add a third variable called z. I add it like this:
while(y1<0 || y1>500 || x1<0 || x1>500 && z>51)
What I want this to do is run the while function ONLY if z>51 is true together with at least 1 more function. Or if thats not possible, I want it to run ONLY if z>51 is true. My code is wrong because right now it just continues on forever even if z>51 is false.
If I understand correctly your question, you want:
while((y1<0 || y1>500 || x1<0 || x1>500) && z>51)
In boolean logic, and (also noted ^ or .) has a higher priority than or (also noted v or +).
Which means that:
y1<0 || y1>500 || x1<0 || x1>500 && z>51
is equivalent to
y1<0 || y1>500 || x1<0 || (x1>500 && z>51)
Therefore, you need parenthesis if that's not what you want, exactly like the parenthesis you add when you use + and * in maths.
Alternatively you could check the value of z first and keep the loop unchanged.
if (z > 51) {
while ( [...])
[...]
}
This is slightly different to Maxime's solution as it assumes that the value of z does not matter once you enter the loop. If you on the other hand want to update z and use it as condition to exit the loop then keep it in the while condition.
The 2 checks are separate.
You can't simply write y1<0 || 50051
You have to write (y1<0 || y1>50051)
50051 always evaluates to true hence I assume it would run forever
for your last request
while(z1>51 && y1 >0)

Selenium IDE - Can I select a row based on column content to verify other columns?

I am testing an application using Selenium IDE. There is a table with unstable row ordering - which means the elements I need to verify are in different rows on each test run.
I'd like to use text known to be in the first column to find the row; and then verify the other columns in the same row.
The test looks like this:
store || //form/table || tableXpath
store || 3 || initialsRow
verifyTable || ${tableXpath}.${initialsRow}.0 || Initials
verifyTable || ${tableXpath}.${initialsRow}.1 || MJ
verifyTable || ${tableXpath}.${initialsRow}.2 || MH
Instead of hard-coding the "initialsRow" value; is it not possible to find the row index dynamically?
The solution I found was to use the Selenium's storeElementIndex command. It gets the index of an HTML element relative to its parent.
See http://release.seleniumhq.org/selenium-core/1.0.1/reference.html
I changed the test as follows:
store || //form/table || tableXpath
storeElementIndex || ${tableXpath}//tr/td[text() = "Initials"]/.. || initialsRow
verifyTable || ${tableXpath}.${initialsRow}.1 || MJ
verifyTable || ${tableXpath}.${initialsRow}.2 || MH
The XPath query //form/table//tr/td[text() = "Initials"]/.. finds the 'tr' element above the 'td' element containing the text "Initials". Selenium stores the index of this 'tr' element relative to whatever its parent element is.
Well, now I found, selenium CAN calculate. Unfortunately not implicitly like ${tableXpath}.${initialsRow + 1}.1 .
So I added an additional command:
storeEval || ${ORBInitialPort} + 1 || ORBInitialPortRow
and used ORBInitialPortRow instead of ORBInitialPort as index.

How to query for a built string select

I would like to do something like
SELECT * FROM (
SELECT ('reword#' || reword) || reword_faq as reword FROM me_review_entries re
) as re
WHERE re.reword = 'reword#2#SOME_FAQ'
I tried to do
SELECT ('reword#' || reword) || reword_faq as foo FROM me_review_entries re
WHERE foo = 'reword#2#SOME_FAQ'
But I get:
ERROR: column "foo" does not exist
LINE 2: WHERE foo = 'reword#2#SOME_FAQ'
Is the first way of doing the only way ? Or could I improve that ?
I think it depends on your database, but the foo column does not exist except within the query, so you might have to do:
SELECT ('reword#' || reword) || reword_faq as foo FROM me_review_entries re
WHERE ('reword#' || reword) || reword_faq = 'reword#2#SOME_FAQ'