Consistent Missing Right Parenthesis Error - sql

I'm trying to right a query that checks if the value is a number and I keep getting a
ORA-00907: missing right parenthesis
error no matter what I do.
Even these queries return the error:
SELECT CAST(123456 AS NUMBER(1,0) DEFAULT -1 ON CONVERSION ERROR)
FROM ANY_TABLE_NAME
SELECT VALIDATE_CONVERSION('99' AS NUMBER)
FROM ANY_TABLE_NAME
Anything I can do to solve this?
I'm using Oracle SQL Developer version 20.2.1.175

VALIDATE_CONVERSION was not introduced until Oracle 12.2.
CAST also did not get the error handling extension until Oracle 12.2.
Therefore, if you are using Oracle 12.1 or earlier then those functions will not be valid.
For example:
They fail in Oracle 11g db<>fiddle
The work in Oracle 18g db<>fiddle
Note: this is the Oracle database version and not the version of SQL Developer, which is just a front-end user interface for accessing the database.

ORA-00907: missing right parenthesis
This error belongs to generic error messages, indicating one or more syntax errors.
How to debug ?
it means we have omitted a right bracket.
(to verify, you can use an editor which allows a "match bracket" control)
it means the compiler received an "out of context" keyword.
it means a misspelled word (i.e a missing comma, a space instead of an underscore,etc )
Your sinthax seems to be right.
You're (probably) facing an "out of context" keyword.

Related

Validate PL/SQL without permanent changes in database

Is it possible to validate a PL/SQL code without permanent changes.
I know one can commit and then rollback, but I'm looking if there's another solution.
If I write a procedure and I want to know it will compile correctly for example.
I'm using Oracle SQL Developer and didn't see any option to do this.
You can compile your procedure and check if it's valid (doesn't return compilation error).
But in this case Oracle does just Syntactic and Semantic analysis.
Syntactic analysis – Oracle verifies that keywords, object names, operators, delimiters, and so on are placed correctly in your SQL statement. So such queries like select * foRm dual will fail during this validation. For example, we can get here such errors like:
ORA-00900: invalid SQL statement
ORA-00923: FROM keyword not found where expected
ORA-00924: missing BY keyword
ORA-00933: SQL command not properly ended
…
Semantic analysis – it verifies that references to host variables and database objects are valid(including their grants) and that host-variable datatypes are correct. For example, select * from nonexisting_table will fail this validation.
Ie, you will not get errors like ORA-00979 not a group by expression on these steps, since Oracle them later, during optimization phase.
More about this:
http://orasql.org/2017/05/01/sql-validation-during-plsql-compilation/
A different answer is to try the editions feature which has been around for awhile now

Postgres solving a syntax error caused by a dash (-)

I am trying to query from a database called physionet-data.mimiciii_clinical.diagnoses_icd
PostgresSQL returns the following error message:
quan.sql:273: ERROR: syntax error at or near "`"
LINE 132: from `physionet-data.mimiciii_clinical.diagnoses_icd` icd
I think it is caused by the dash. If I change the `for ' the same error comes up
quan.sql:273: ERROR: syntax error at or near
"'physionet-data.mimiciii_clinical.diagnoses_icd'"
Any clue on how to fix that?
You would need to quote that schema name, using double-quotes:
select ...
from "physionet-data".mimiciii_clinical.diagnoses_icd
Note that quoting an identifier makes it case-sensitive. You would need to ensure that the character case the schema was created with matches the one you are using here.
Using identifiers that require quoting is not a good idea in general; as you are fiding out, this requires quoting them every where you use it later on. If that's not too late, I would recommend changing the schema name to a name that does not require quoting.

SELECT $b shows no intellisense as error, but throws error. what's the reason behind this scenario?

i tried to explore SQL.while doing so, got below error-
SELECT $b
Error- Invalid pseudocolumn "$b".
What is this error? Why SSMS's Intellisense cannot handle it as error if it's error. If I write query as 'Select #', then Intellisense shows red mark under # symbol. if i do the same for $b, it is looking like no error,but after execution, throws error.
IntelliSense is a client side thing, columns are a server side thing. IntelliSense won't necessarily know that a particular pseudocolumn doesn't exist (like $IDENTITY does exist, but only for tables that have an IDENTITY type column) but when you run the query the server will tell you it didn't exist. IntelliSense isn't a device that constantly queries the server to make sure what you're writing isn't garbage - you can see this if you use another SSMS window to add a column to a table then reference it from the first window - i tellisene doesn't know its there unless you refresh it (Ctrl+Alt+R I think) so it will draw a red line under the new column even though the query will run fine when you submit it to the server

How would I fix these "ORA-00933: SQL command not properly ended" "ORA-00923: FROM keyword not found where expected" errors?

This Statement:
SELECT id, units, cost FROM inventory_list WHERE cost <= 20;
Gives me:
ORA-00923: FROM keyword not found where expected
While this statement:
SELECT * FROM items WHERE ilt_id = 'il010230126' OR ilt_id = 'il010230128';
Gives me:
ORA-00933: SQL command not properly ended
Not sure about this and may be version dependent (below link is for oracle 10g... but you can see on this site
https://docs.oracle.com/cd/B19306_01/em.102/b40103/app_oracle_reserved_words.htm
That cost is an oracle reserved keyword, so it is not wise to use it as a column name.
If you have no control of the table I think you may be able to surround it in double quotes eg select "COST" to avoid oracle picking it up as a reserved word.
By default Oracle creates fields in uppercase so the field name will need to be in uppercase unless when the table was created it was forced into different case by surrounding it in Quotes.
Check that you don't have invisible characters in your file and that you're using the right encoding. I sometimes accidentally introduce them because I have a non english keyboard map and accidentally hit the wrong key combination.
Just type again one of your SQL statements and test them.

missing SELECT keyword error from INSERT statement

Alright, I've got this command:
INSERT INTO PHOTOS_HEADER (TC_CLOCK, DC_SCANDATE, TC_PO, DC_DATE, NC_PACKAGES)
VALUES (:TC_CLOCK, TO_DATE(:DC_SCANDATE, :DATE_FORMAT), :TC_PO, TO_DATE(:DC_DATE, :DATE_FORMAT), :NC_PACKAGES)
RETURNING NC_AUTOID into :OUTPUT
I'm running it in .NET through an OracleCommand object, and it runs find on our local 11g server. When this same code runs on a client site, we get this error:
ORA-00928: missing SELECT keyword
Could it be the returning statement? Could it be to_date? I'm working on finding out what version of the Oracle server the client is using, but any suggestions in the mean time?
Edit: Client is running Oracle 11, same as us. Removed the returning into clause, but still receiving the same error.
I was asked in a comment what to do if you need to work with a version of Oracle without returning. I think that's different enough from the spirit of an answer about whether returning exists to place in its own answer.
One approach is to use the nextval function from a sequence and get the ID before the insert.
select sequence.nextval into :id from dual;
Then perform the insert.
See http://www.dba-oracle.com/t_oracle_nextval_function.htm for more examples.
It is very likely their version of oracle does not support the returning clause. to_date in values has worked since I started playing with Oracle around Oracle 7 in 1998.
According to http://www.dba-oracle.com/plsql/t_plsql_dml.htm the returning clause was added in Oracle 9I release 2.