WHY ORA-00905: missing keyword issue occurs during create table or view in Oracle - oracle10g

This issue occurs due to the table name or view name is not valid as per the permissible text.
For example create table with table name 'EMPLOYEE-DETAIL' is not valid due to it contains hyphen '-'; so use underscore '_' instead of hyphen. Like EMPLOYEE_DETAIL.

This issue occurs due to the table name or view name is not valid as per the permissible text. For example create table with table name 'EMPLOYEE-DETAIL' is not valid due to it contains hyphen '-'; so use underscore '_' instead of hyphen. Like EMPLOYEE_DETAIL.

Related

Basic DELETE commands in PostgreSQL detecting value as column name [duplicate]

This question already has answers here:
delete "column does not exist"
(1 answer)
SQL domain ERROR: column does not exist, setting default
(3 answers)
Closed last year.
I'm trying to delete a row at PostgreSQL using pgAdmin4.
Here is my command:
DELETE FROM commissions_user
WHERE first_name = "Steven";
For some reason, the error states that
ERROR: column "Steven" does not exist
LINE 2: WHERE first_name = "Steven";
^
SQL state: 42703
Character: 50
It's weird, why is "Steven" detected as a column name, shouldn't the column name be first_name?
Use single quotes instead
DELETE FROM commissions_user
WHERE first_name = 'Steven';
Double quotes can be used table and column, and single quotes can be used for strings.
ex.
DELETE FROM "commissions_user"
WHERE "first_name" = 'Steven';
https://www.postgresql.org/docs/current/sql-syntax-lexical.html
Double quote:
A convention often used is to write key words in upper case and names
in lower case, e.g.:
UPDATE my_table SET a = 5;
There is a second kind of identifier: the delimited identifier or
quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes ("). A delimited identifier
is always an identifier, never a key word. So "select" could be used
to refer to a column or table named “select”, whereas an unquoted
select would be taken as a key word and would therefore provoke a
parse error when used where a table or column name is expected. The
example can be written with quoted identifiers like this:
UPDATE "my_table" SET "a" = 5;
Single Quote:
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS
A string constant in SQL is an arbitrary sequence of characters
bounded by single quotes ('), for example 'This is a string'. To
include a single-quote character within a string constant, write two
adjacent single quotes, e.g., 'Dianne''s horse'. Note that this is not
the same as a double-quote character (")

How to refer to a Camel SQL component named parameter where the parameter name is in mixed case and contains spaces?

I am loading a CSV file into a Postgresql database using the Camel SQL component.
The original CSV file header names (Columns) are mixed case with spaces e.g. "Cost Price"
The SQL component refers to an SQL insert statement in a properties file,
e.g.
insert into upload_data(year,month,cost)values(:#year,:#month,:#Cost Price)
I get this error:
Caused by: [org.springframework.jdbc.BadSqlGrammarException - PreparedStatementCallback; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near ":" at position...
-the position refers to the : before #Cost Price
If I change the parameter name to cost_price and modify the CSV file the file is uploaded correctly without error.
I have tried surrounding the parameter with " ' \" and {} in the insert statement
Is it possible to use mixed case with spaces in named parameters using escapes or something or do I need to intervene and modify the CSV header?
The SQL component does not support this, in fact its a real bad design to use spaces in header names. So after you read the CSV file, you can change the header name before calling the SQL component.

pg_get_serial_sequence in postgres fails and returns misleading error

This is not obviuos to me.
When I do:
SELECT MAX("SequenceNumber") FROM "TrackingEvent";
It returns perfectly fine with the correct result
When I do:
SELECT nextval(pg_get_serial_sequence("TrackingEvent", "SequenceNumber")) AS NextId
It returns an error which says
column "TrackingEvent" does not exist.
Not only is it wrong but the first argument of the function pg_get_serial_sequence takes a table name and not a column name, so the error is aslo misleading.
Anyways, can someone explain to me why I get an error on the pg_get_serial_sequence function ?
pg_get_serial_sequence() expects a string as its argument, not an identifier. String constants are written with single quotes in SQL, "TrackingEvent" is an identifier, 'TrackingEvent' is a string constant.
But because the function converts the string constant to an identifier, you need to include the double quotes as part of the string constant. This however only applies to the table name, not the column name, as explained in the manual
Because the first parameter is potentially a schema and table, it is not treated as a double-quoted identifier, meaning it is lower cased by default, while the second parameter, being just a column name, is treated as double-quoted and has its case preserved.
So you need to use:
SELECT nextval(pg_get_serial_sequence('"TrackingEvent"', 'SequenceNumber'))
This is another good example why using quoted identifiers is a bad idea. You should rename "TrackingEvent" to tracking_event and "SequenceNumber" to sequence_number

Why table name in double quotes with trailing typo is valid syntax

I entered the following query into my Postgres terminal, with an accidental l after the trailing double quote and before the semi-colon. I expected a syntax error, but instead I got query results:
select * from "myTable"l;
And in fact, I can put anything I want after the trailing double quote and I still don't get a syntax error:
select * from "myTable"asdkjh;
I checked what I thought would be the relevant docs for how double quoted strings should be formatted, but it didn't mention this.
So, why does this work?
The l or asdkjh is taken as a table alias.
The keyword AS to introduce an alias is optional, so you instead of from foo as x can also write from foo x.
from foox however would indeed be an error as that would be taken as a complete table name. As you have used a quoted identifier, it is clear where the identifier ends and the next identifier starts - thus no whitespace is required between the identifier and the alias.
So, from "myTable"asdkjh is identical to from "myTable" as asdkjh
However, from "myTable""some_alias" would be an error as it is taken as a single identifier - to include a double quote in a quoted identifier, you write two quotes, so "myTable""some_alias" references a table named myTable"some_alias

How to update a record with literal percent literal (%) in PostgreSQL without saving it as "\%"

I need to update a record, which contains literal percent signs, using PostgreSQL in Railo. The query looks like
<cfquery>
update foo set bar = 'string with % in it %'
</cfQuery>
It throws error as ColdFusion normally interprets it as a wildcard character. I can escape it using the following query.
<cfquery>
update foo set bar = 'string with escaped \% in it \%'
</cfQuery>
However, the record now contains "\%" in the database and will be displayed on the page as "\%".
I found a documentation with an example of escaping percent sign in a SELECT. But it does not work for me: syntax error at or near "ESCAPE".
SELECT emp_discount
FROM Benefits
WHERE emp_discount LIKE '10\%'
ESCAPE '\';
Is there a better to achieve the same goal? The underlining database is PostgreSQL. Thanks!
Queryparameters escape special characters. Yet another reason to use them.