I have the following criteria api query before populating parametrs
where lower(generatedAlias7.personGivenName || :param6 || generatedAlias7.personSurName) like :param7)
Can anyone explain what does it mean ?
Some vendors (e.g. Oracle or PostgreSQL I think) offer the double bar || operator to concatenate strings.
Related
This is the first table:
Line_Card
0-17
0-10
1-1
0-11
1-1-17
1-1-10
1-1-13
1-1-6
1-1-21
This is the second table:
Port
0-13-37
1-1-2-40
0-8-29
1-1-4-12
1-1-2-14
0-1-30
0-17-25
1-1-17-62
1-1-1-55
The below query is supposed to read from the product of the joined tables:
SELECT Line_Card, Port
FROM Table_1
LEFT JOIN Table_2 ON
Table_1.Column= Table_2.Column
AND Table_1.Port ~~ LIKE_ESCAPE((Table_2.Line_Card || '-%'),'\')
AND Table_1.Port !~~ LIKE_ESCAPE((Table_2.Line_card || '-%-%'),'\');
However, it shows an invalid SQL character error on oracle. It would be greatly appreciated if someone could also give me the equivalent of this statement or the infinity symbol in Teradata.
I am working through someone else's code and my understanding that this is oracle and that ~ has a purpose in oracle. The thing is that I can not find any reference to the double infinity ~~ symbol.
That's because it doesn't have any meaning in Oracle. It looks like this code is from PostgreSQL, where - as this answer says:
The operator ~~ is equivalent to LIKE, and ~~* corresponds to ILIKE. There are also !~~ and !~~* operators that represent NOT LIKE and NOT ILIKE, respectively. All of these operators are PostgreSQL-specific.
Even in PostgreSQL that implies you can just replace them with the LIKE and NOT LIKE equivalents; and that would work in Oracle too:
AND Table_1.Port LIKE Table_2.Line_Card || '-%'
AND Table_1.Port NOT LIKE Table_2.Line_card || '-%-%'
It appears that the LIKE_ESCAPE() part is a bespoke function that escapes wildcard characters. Given your sample data that doesn't seem necessary here.
db<>fiddle
As per the attached image the column tlist in a table 'c' has values separated by a comma such as 'HCC19','HCC18'.
I am trying to used the column values in a query condition on redshift ..
where a.risk_factor in (c.tlist)
.. ..but its not giving the expected result possibly because its taking the value a single string as '
where a.risk_factor in( ' 'HCC19','HCC18' ') and not as required in the expression where a.risk_factor in('HCC19','HCC18')
Is there any workaround possible for this situation ?
You may try using a LIKE comparison here:
WHERE c.tlist LIKE '%''' || a.risk_factor || '''%';
The above LIKE expression compares 'HCC19','HCC18' searching for the single quoted risk factor. If the risk factor already comes with single quotes, then just use:
WHERE c.tlist LIKE '%' || a.risk_factor || '%';
I have a ton of columns I am trying to aggregate together and most of them have NULL values. I want to separate values that do appear with a ';' but I cannot find an effective way to do this in oracle. CONCAT_WS would be exactly what I need as it would not add the delimeter between NULL values, but oracle does not support this.
concat_ws(';','dx89','dx90','dx91','dx92') as diagnoses3
ORA-00904: "CONCAT_WS": invalid identifier
Using a function like this is similar but doesn't quite get me what I need as you can see the ';' on the end of the string since dx91 and dx92 are NULL values:
dx89||';'||dx90||';'||dx91||';'||dx92 as diagnoses2
I63.8;I63.9;;
Any help would be greatly appreciated!
You can use NVL2() function specific to Oracle DB together with pipe concatenation operators :
SELECT TRIM(LEADING ';'
FROM dx89||NVL2(dx90,';'||dx90,dx90)||
NVL2(dx91,';'||dx91,dx91)||
NVL2(dx92,';'||dx92,dx92)) AS "Concatenated String"
FROM t
Demo
What is the line-continuation character for HANA SQL? Considering I have a super long statement and want it to span across multiple lines instead of it being a super long one in a line.
Thanks.
For most SQL statements, you can implicitly continue on the next line. There is no "line-continuation character". Long strings can be continued on the next line by separating them in multiple strings concatenated with ||.
For example, this is perfectly valid HANA SQL:
SELECT
"RefID",
"FirstName",
"LastName"
FROM
"People"
WHERE
"FirstName" = 'Hubert Blaine'
AND
"LastName" = 'Wolfeschlegelsteinhausenbergerdorffvoralternwaren' ||
'gewissenhaftschaferswesenchafewarenwholgepflegeun' ||
'dsorgfaltigkeitbeschutzenvonangereifenduchihrraub' ||
'giriigfeindewelchevorralternzwolftausendjahresvor' ||
'andieerscheinenbanderersteerdeemmeshedrraumschiff' ||
'gebrauchlichtalsseinursprungvonkraftgestartseinla' ||
'ngefahrthinzwischensternartigraumaufdersuchenachd' ||
'iesternwelshegehabtbewohnbarplanetenkreisedrehens' ||
'ichundwohinderneurassevanverstandigmenshlichkeitt' ||
'konntevortpflanzenundsicherfreunanlebenslamdlichf' ||
'reudeundruhemitnichteinfurchtvorangreifenvonander' ||
'erintlligentgeschopfsvonhinzwischensternartigraum';
PS: That person actually exists. :)
You can hit the return key and have a statement split in multiple line for your convenience.
Like in the image below:
Even in dynamic SQL you can split the string (with the || operator) you're going to feed in the EXEC() command.
Just studying some code , and came across this line:
v_VLDT_TOKEN_VLU := v_onl_acctID || ‘|’ || p_onl_external_id || ‘|’ || p_validation_target
It's a "validation token value" , but why would you concatenate the pipe symbol? I understand this is for dynamic SQL.
Here Pipe symbol is used as a delimiter/separator between the fields:
Assume,
v_onl_acctID = 123
p_onl_external_id = abc
p_validation_target = xyz
then
v_VLDT_TOKEN_VLU := v_onl_acctID || ‘|’ || p_onl_external_id || ‘|’ || p_validation_target
will evaluate to
v_VLDT_TOKEN_VLU = 123|abc|xyz
It is just another character for delimiter purpose and can be replaced with any other delimiter too. For reference, if the | is replaced by *, say
v_VLDT_TOKEN_VLU := v_onl_acctID || ‘*’ || p_onl_external_id || ‘*’ || p_validation_target
then the expression's value would be 123*abc*xyz
Note: || is used for concatenation
Looks like the pipe symbol is being used as a delimiter between the three fields.
I have actually seen similar code, but it was used to generate a unix statement that piped (|) the output of one command to another. If I remember correctly, they had a table with all of our database hosts, and oracle data directories. They used code similar to this to shell over to the specific database host, get a directory of the datafiles and write the output to a logfile back on the parent server which they then read in to update disk usage for reporting. This was years ago so I'm sure there is a better way to do it now.
Comment = answer apparently.
v_vldt_token_vlu looks like it's built up of three fields, with a pipe between each of them...I assume the pipe is built into the token_vlu field and then being compared to the same fields concatonated together here. Pipe was probably a developers preference. No real reference to dynamic SQL here