I'm trying to execute the below statement on PostgreSQL 12.4. This statement was converted from Oracle 10g to PostgreSQL 12.4 using the online SQL Lines tool.
select
hid,
pname,
starting_from,
ename
from schema1.pet
where hid=COALESCE(TO_NUMBER(sys_context('temp1','hid')),0);
I'm getting the below error:
ERROR: function sys_context(unknown, unknown) does not exist
LINE 7: where hid=COALESCE(TO_NUMBER(sys_context('temp1','hid...
I'm not sure what's the equivalent of sys_context in PostgreSQL.
How can I fix this statement to PostgreSQL?
The PostgreSQL current_setting() function comes closest to the Oracle sys_context() function. PostgreSQL does not use the namespace parameter, however.
Related
I tried to query data in TDengine with the following sql clause:
SELECT * from TABLE where COLUMN < FUNCTION();
and I got illegal condition expression error.
Does anyone know if using function in where condition is illegal usage in SQL convention or I need to resort to other syntax?
Using function in where condition is illegal. Maybe it will be supported later.
I am converting some SQL statements now that we're running against MariaDB instead of SQL Anywhere. In one of the queries, I'm getting an error on this line:
select convert(char, c.dob, 1) as "DOB"
Specifically, this is the error that is produced:
Error Code: 1064. You have an error in your SQL syntax; check the
manual that corresponds to your MariaDB server version for the right
syntax to use near 'c.dob, 1) as "DOB",
My understanding is that this "convert" is trying to produce a value of type "char" from the "dob" value, which is currently of type date.
What would the issue be in this case? Does it have to do with the way MariaDB handles dates differently?
CONVERT() has only 2 arguments:
https://mariadb.com/kb/en/library/convert/
And the datatype is second.
Furthermore, if c.dob is any type of date or time, then you do not need any conversion function. It will automatically produce a string in that context.
I have a script that used to run just fine from Teradata SQL Assistant. I am unable to get the exact same script to run from SQL Workbench/J. I have isolated the problem to one specific line. Here's the query:
SELECT
variable1 as name1,
variable2 as name2,
CONCAT(TRIM(variable3), ':', trim(variable4)) as name3
variable4 as name4,
FROM
table1
WHERE
variable4 between '2017-01-01' AND '2017-01-31';
The problem is the CONCAT line. If I comment that line out, code runs fine. If I leave that line in, I get the unhelpful message:
[Teradata Database] [TeraJDBC 16.10.00.07] [Error 3706] [SQLState 42000]
Syntax error: expected something between '(' and the 'TRIM' keyword. [SQL State=42000,
DB Errorcode=3706]
1 statement failed.
I say unhelpful, because that makes it sound like a syntax error, but this isn't a syntax error as far as Teradata is concerned. The exact same code ran fine on Windows Teradata SQL Assistant. But since OSX Teradata SQL Assistant is a dumpster fire, I have to try and run the script in SQL Workbench J.
Help, please?
There's no concat function in Teradata SQL, it's an ODBC function (sometimes) automatically translated by the ODBC driver to valid syntax. But SQL Workbench uses JDBC, which doesn't support this function.
Simply switch to Standard SQL ||:
TRIM(variable3) || ':' || trim(variable4)
Trying to execute the statement
select *
from RU_VARIANCE_HISTORY
but I'm getting the error
DB2 SQL Error: SQLCODE=-901, SQLSTATE=58004,
SQLERRMC=Invalid collation ID, DRIVER=4.21.29
Tried searching but unable to find the solution.
This can happen if DB2 thinks the statement is really too long or too short. Try adding a semicolon to the end of your statement - this worked for me with the same error.
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.