ORA-00907 Missing right parenthesis Postgresql to Oracle - oracle

I am moving from Postgres to Oracle and I am getting the ORA-00907 error for the following statement:
UPDATE investigations SET
team=(SELECT team FROM assigned WHERE parent_id=investigations.id LIMIT 1);
Please help with my Oracle syntax.
Thanks in advance!

As far as I know oracle doesn't have LIMIT clause. Take a look at this topic

you can try using rownum
SELECT team FROM assigned WHERE parent_id=investigations.id and rownum =1

Related

Connect by level in Postgres on a sequence

I need to convert a query from Oracle to Postgres which uses connect by level on a sequence in Oracle.
I know that connect by level is not available in Postgres. I couldn't find an alternate for this using recursive cte.
In Oracle if I run this query.
create sequence ID_SEQ;
select ID_SEQ.nextval from DUAL connect by level <= 3;
I will get the following result
1
2
3
I need the same in Postgres. Please share some solutions if anyone has any idea.
Thanks in advance
Gokul.
The direct translation of that query is to use generate_series() and nextval()
select nextval('id_seq')
from generate_series(1,3);
This will advance the sequence three times.
If however the goal is to set a specific value for an existing sequence (which requires such a hack in Oracle), just use setval():
select setval('id_seq', 3);

delphi: ROW-00025: Invalid RowSetHandle when executing a query on an oracle db

I've created a small 64-Bit application and I want to execute a simple query
select field1, field2 from table where field1 = 'xyz' order by 1
on an oracle db.
I am using:
Windows 10
Oracle Database 11g Client (x64)
Delphi 10.1.2 Berlin
TADOQuery with the connection string:
Provider=OraOLEDB.Oracle;Password=XYZ;User ID=XYZ;DataSource=XYZ;Persist Security Info=True
When executing the query I get the error:
ROW-00025: Invalid RowSetHandle
I have never seen any error like this before.
Do you have any ideas? If you need more information, let me know in the comments below.
Thanks for your suggestions and comments. Meanwhile we found a solution...
We need to set the CursorLocation from the ADOQuery from clUseServer to clUseClient. With this change our query works. I guess our oracle server has some issues.
can you try in this way,
select field1, field2 from table where field1 = 'xyz' and rownum=1;

No records when using SELECT query on DBLINK in Oracle

I'm trying to move data in between two oracle databases say SOURCE_A and DEST_B. I have created a dblink (LINK_A) using TOAD on DEST_B to SOURCE_A to copy data from the tables. Dblink creation was fine, but when I used a select statement like below, I see no data except column names.
SELECT * FROM TABLE_A#LINK_A;
Could you please help me understand what am I doing wrong or missing here. I tried running a DESC on the TABLE_A using the link and it worked fine. Not sure why its not pulling any data from the SOURCE_A database.
Any help is greatly appreciated. Thanks.
Alright, with many trial and errors, I managed to get a solution that works for me in this SO question.
I used the technique provided by - Jeremy Scoggins and it worked like charm. I was able to move data using toad and its perfect. Thanks to all of you for your time and support.
Appreciate it.

Why Oracle 10g doesn't complain about column ambiguity?

I'm using Oracle 10g (XE 10.2.0.1.0), and find a behavior that I don't understand:
select *
from employees manager
join employees worker on MANAGER.EMPLOYEE_ID = WORKER.MANAGER_ID
join departments on DEPARTMENTS.manager_id = 108
where
department_id = 100
;
The problem is I think Oracle should have complain about the ambiguity of department_id in the where clause, since it's a column in both the table employees and departments. The fact is in Oracle 10g, it doesn't, and the result shows that it interprets the department_id as the one in departments. However, if I comment out the second join statement (4th line above), Oracle does complain “ORA-00918: column ambiguously defined” as expected.
So, can somebody help to explain how the ambiguity is defined in Oracle 10g? Or perhaps this is a bug in 10g?
BTW: The tables are defined in the default HR schema bundled in the Oracle 10g.
Update: Just found a related post:
Why does Oracle SQL mysteriously resolve ambiguity in one joins and does not in others
I believe it is a bug in Oracle 10g that Oracle chose not to fix. When we were upgrading our applications from 10g to 11gR2, we found a couple of queries that were written "loosely" in respect of ambiguous column names but worked in Oracle 10g. They all stopped working in 11gR2. We contacted Oracle but they pretty much said that the tolerant behavior toward ambiguous column names is a correct behavior for Oracle 10g and the stringent behavior is the correct behavior for 11g.
I think it is, because departments have no alias. Therefore everything without being qualified by an <alias>. is first treated to be from departments.
So I also think when you give departments an alias you should get the ORA-00918 again. Cannot test here though...

Nhibernate Generate wrong SQL for Oracle with locking

yesterday I've been trying to make this code work inspite the fact it's just working fine with nhibernate and SQL server but when it come to oracle it generate wrong sql
UnitOfWork.Current.CreateCriteria<Bill>().Add(Restrictions.IsEmpty("ReqId"))
.SetMaxResults(BatchSize).SetLockMode(LockMode.Upgrade).List<Bill>();
the generated SQL will something like
Select * from
(Select bill_0.id,bill_0.BillNo ...... from Bill bill_0 where bill_0.reqId is Not null )
where ROWNUM < 10 for UPDATE of bill_0.ID
so i wont run because the allies bill_o is defined inside the inner sql statement so who got the solution ?
the correct sql would be something like this which i tried and worked on oracle db
Select bill_0.id,bill_0.BillNo ...... from Bill bill_0
where bill_0.reqId is Not null and ROWNUM < 10 for UPDATE of bill_0.ID
Since, as you say, NHibernate is generating invalid Oracle SQL, I suggest you file a bug with the NHibernate people. The SQL would work if the in-line view had been assigned an alias of "bill_0", or if the FOR UPDATE clause didn't use a table alias ("for UPDATE of ID"). Whether you can modify your NHibernate calls to make either of these happen I'm afraid I have no idea.

Resources