Oracle error - "Pending": invalid identifier - oracle

i'm creating a query with typeorm with oracle.
I'm using this in a select, because the status can be null.
'NVL(Details.status, "Pending") AS "PostulationDetail_status"'
I have used this before but using 0, because i was working with numbers. I decided to test with strings and i got surprised. i get this error on console
[Nest] 620 - 18-11-2021 12:20:29 ERROR [ExceptionsHandler] ORA-00904: "Pending": invalid identifier
QueryFailedError: ORA-00904: "Pending": invalid identifier
I don't know how to write the query so it is valid. Does anyone had an experience like this ?

You want to use single quotes around string literals and either no quotes (the preferable, case-insensitive option) or double quotes (case-sensitive) around identifiers:
NVL(Details.status, 'Pending') AS "PostulationDetail_status"
If you use double quotes:
NVL(Details.status, "Pending") AS "PostulationDetail_status"
Then you are saying to return the DETAILS.STATUS value (this identifier is case-insensitive) or, if that is NULL then, use the value of the Pending column (this identifier is case-sensitive) and alias the value as PostulationDetail_status (again, case-sensitive).

Related

Mule APIKit validation error "Underlying error while parsing YAML syntax" on APIKIT:BAD_REQUEST

I have a query parameter defined in RAML as of type Integer and have used APIKit to generate flows and validation implementation. When I enter the invalid value 1]3 for this field, I get the following validation error, as expected:
"Invalid value '1]3' for query parameter offset. Invalid type String, expected Integer"
However, if I enter the single character ] I do not get a validation error, but it looks like this causes a fault in YAML parsing as the character is interpreted as YAML and not text to be validated.
"Invalid value ']' for query parameter offset. Underlying error while parsing YAML syntax: 'while parsing a block node
in 'reader', line 1, column 1:
]
^
expected the node content, but found ']'
To me both inputs should return the first error shown. This behaviour is also triggered by input of other YAML special characters such as : , ' and ,, where they are the only character entered in the query parameter.
So my question is, how can I get these error cases to return consistent format error messages - that is, of the first example, without mapping both to a custom Mule error? Passing the error text on to consumers as-is makes for an inconsistent user experience. Or perhaps this is not the intention, and these errors should always be mapped to a custom error?
Mule runtime version 4.3.0
APIKit version 1.4.1

Unexpected token ':' in Nifi Expression Language

I just got an error about an unexpected token while using the NiFi expression language.
'prod' validated against ${hostname:contains("prod")} is invalid because
Unexpected token ':' at line 1, column 10. Query: ${hostname:contains(prod)}
In this case the problem occurs in the RouteOnAttribute processor.
My question: What is/are the typical causes of this error?
Of course it is good to check the actual expression, however in this case I did not find any problems with the expression.
The problem comes from hostname
As documented here:
There also exist some functions that expect to have no subject. These functions are invoked simply by calling the function at the beginning of the Expression, such as ${hostname()}
After this it was quickly fixed by calling my attribute host_name instead.

Disable double underscore behaviour for Sequel

How disable double underscore behaviour for Sequel?
I work with legacy data base schema where I have a lot of columns with "__" in name.
db[:abc].insert({vector_a__c: "356"})
Sequel::DatabaseError: PG::UndefinedColumn: ERROR: column "vector_a" of relation "abc" does not exist
LINE 1: INSERT INTO "abc" ("vector_a"."c") VALUES ('356') RETURNING ...
In general you want to wrap it in an identifier:
db[:abc].insert(Sequel.identifier(:vector_a__c) => "356")
Using a string as an identifier only works in very few cases for backwards compatibility, where it is unambiguous (i.e. where an SQL string would not be valid).
Double underscore behavior disabling when you transfer columns names as string but not as symbol.
For example:
db[:abc].insert({"vector_a__c" => "356"})

SQLAlchemy: Force column alias quoting

I want SQLAlchemy to generate the following SQL code:
SELECT t171 AS "3Harm" FROM production
I've been playing around with something similar to this SQLAlchemy ORM snippet:
session.query(Production.t171.label('3harm'))
The problem here is that this doesn't properly quote "3harm" in the generated SQL. Instead of "3harm" this generates the unquoted 3harm, which is invalid because it starts with a numerical character and therefore raises the following Oracle exception:
ORA-00923: FROM keyword not found where expected
I can get this to work by capitalizing any character in the alias name:
session.query(Production.t171.label('3Harm'))
But I would still prefer to use all lowercase column names since the rest of my program is standardized for all lowercase. Any idea how to force quote the lowercase version?
Found the solution while looking for something else.
Any column can be forced to use quotes with column.quote = True.
So for the original example:
column = Production.t171.label('3harm')
column.quote = True
session.query(column)
Success!
The SQL you want to generate isn't valid; rather than this:
SELECT t171 AS '3Harm' FROM production
... you need the identifier to be enclosed in double quotes, not single quotes:
SELECT t171 AS "3Harm" FROM production
So it looks like you should be able to do this:
session.query(Production.t171.label('"3harm"'))
or maybe:
session.query(Production.t171.label("3harm"))
But I don't use SQLAlchemy and I don't have any way to check if either is valid; you might need to escape the double quotes in the first one, for instance, though from this perhaps the second is more likely to work... and I don't understand why 3Harm would work unquoted.

ASCII for SYS_CONNECT_BY_PATH ORACLE sql

Is there any way to use ascii code for value separator in SYS_CONNECT_BY_PATH.
For example in SYS_CONNECT_BY_PATH(columnname,'!'),
I want to use the ASCII value of !(33) instead of actual symbol. Also, can i use the ascii value of ENTER (13) as value separator?
Thank you.
You can use the chr function to replace a character with it's numeric equivalent.
SYS_CONNECT_BY_PATH(column name, chr(33))
Or to use a line feed, which should also be fine:
SYS_CONNECT_BY_PATH(column name, chr(13))
It's not strictly ASCII as it depends on your character set, but it will probably work for you. You can see the numeric values using the reverse ascii function, which also isn't really quite ASCII, but again close enough especially if you're always using the same character set. So ascii('!') would give you 33.
As you've discovered, giving anything except a fixed string literal gives:
SQL Error: ORA-30003: illegal parameter in SYS_CONNECT_BY_PATH
function
30003. 00000 - "illegal parameter in SYS_CONNECT_BY_PATH function"
*Cause:
*Action: use a non-empty constant string as the second argument,
then retry the operation.
This is why I usually test things before posting, but this seemed so simple... You can get around that with replace:
REPLACE(SYS_CONNECT_BY_PATH(column name, '/'), '/', chr(33))
Borrowing an example from the manual:
SELECT LPAD(' ', 2*level-1)
||replace(SYS_CONNECT_BY_PATH(last_name, '/'),'/',chr(33)) "Path"
FROM employees
START WITH last_name = 'Kochhar'
CONNECT BY PRIOR employee_id = manager_id;
Path
--------------------------------------------------
!Kochhar
!Kochhar!Greenberg
!Kochhar!Greenberg!Faviet
!Kochhar!Greenberg!Chen
!Kochhar!Greenberg!Sciarra
!Kochhar!Greenberg!Urman
!Kochhar!Greenberg!Popp
!Kochhar!Whalen
!Kochhar!Mavris
!Kochhar!Baer
!Kochhar!Higgins
!Kochhar!Higgins!Gietz
All the credit goes to Sanjeev Chauhan. Update 7/25/2017: This turned out to be a SQL Developer 4.2.0 and 17.2.0 bug. In SQLPlus and SQL Developer 3.2.2 the statement works fine.
Fix: set secureliterals off;
The source is https://community.oracle.com/thread/4065282
I had changed the version from 4.2.0 to 4.1.1.19 and my piece of code worked. Also be aware that I couldn't find "secureliterals" in version 4.2.0

Resources