SQL command not properly ended on insert query - oracle

I just want to alter my datas in my table this query seems good but oracle says ORA-00933: SQL command not properly ended im new in oracle from mysql.
Here's my code:
INSERT INTO AWACSRECIPEBYWSTYPE(BFGID) VALUES(23) WHERE WSTYPE = 'CLIPBOND';

You can't put a WHERE clause on an INSERT statement in Oracle. And after looking at the MySQL documentation I don't see where you can use a WHERE clause like this in MySQL either.
Did you mean to use an UPDATE statement?
UPDATE AWACSRECIPEBYWSTYPE
SET BFGID = 23
WHERE WSTYPE = 'CLIPBOND'
???

Related

getting error while executing same query in Oracle

This query working as expected in postgres but same query we need to write in Oracle could you please suggest how to write query in Oracle
delete from need_entl_status_history
using need_entitlement
where need_entitlement.need_entitlement_uuid=need_entl_status_history.need_entitlement_uuid
and need_entitlement.user_guid='b8e06968-2839-4fc1-a987-5ea81678d9ge’;
That would be something like this; I used table aliases as they improve readability.
delete from need_entl_status_history h
where h.need_entitlement_uuid in (select e.need_entitlement_uuid
from need_entitlement e
where e.user_guid = 'b8e06968-2839-4fc1-a987-5ea81678d9ge’
);

Oracle ORA-00933: SQL command not properly ended

I try to use golang and query data from Oracle. My SQL query is:
SELECT * FROM TABLE1 OFFSET 10 ROWS;
But it gives an error:
EXTRA *errors.withStack=dpiStmt_execute: ORA-00933: SQL command not properly ended
My SQL query works fine when I query in SQL*Plus, but errors when I use golang.
I'd try running the query without the terminating semicolon, as Alex Poole pointed out. A lot of Oracle client libraries (i.e. cx_Oracle in python, ADO.NET Oracle Libraries) do complain if you try to execute a query ending with the semicolon (which is perfectly legal in SQL/Plus)
If the offset is not specified, it is assumed that it is 0 (zero). So, remove that clause (as it does nothing in your case), i.e.
select * from table1
and use that query in golang.
I am pretty sure that just your closing semicolon is to much. The semicolon is a character to separate several SQL statements or to close a pl/sql block. So when you write it at the end of a SQL statement the parser doesn't know how to handle it, cause he only awaits a single SQL statement.

How to execute select query on oracle database using pi spark?

I have written a program using pyspark to connect to oracle database and fetch data. Below command works fine and returns the contents of the table:
sqlContext.read.format("jdbc")
.option("url","jdbc:oracle:thin:user/password#dbserver:port/dbname")
.option("dbtable","SCHEMA.TABLE")
.option("driver","oracle.jdbc.driver.OracleDriver")
.load().show()
Now I do not want to load the entire table data. I want to load selected records. Can I specify select query as part of this command? If yes how?
Note: I can use dataframe and execute select query on the top of it but I do not want to do it. Please help!!
You can use subquery in dbtable option
.option("dbtable", "(SELECT * FROM tableName) AS tmp where x = 1")
Here is similar question, but about MySQL
In general, the optimizer SHOULD be able to push down any relevant select and where elements so if you now do df.select("a","b","c").where("d<10") then in general this should be pushed down to oracle. You can check it by doing df.explain(true) on the final dataframe.

ORA-00907 when quering from my Java application but works fine in SQL Developer

My query that I put into a prepared statement is:
select *
from ( select seq, audit_ts, message_type
from log2
where 1 = 1
and message_type in ('SOURCE', 'DEST')
order by seq desc )
where ROWNUM <= ?
When I run the query in my application, I get:
java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis
EDIT: Here is the java executing the query. I am trying to return a set of search results, so the prefix contains the SELECT statement and then I can have any number of suffixes (in this excerpt "AUDIT_LOG_SEARCH2") which are the parameterized WHERE clauses based on the user search:
StringBuffer query = new StringBuffer(300);
query.append(dbAdapter.getQuery("AUDIT_LOG_ENTRY_PREFIX"));
query.append(dbAdapter.getQuery("AUDIT_LOG_SEARCH2"));
// Insert parameters to complete the sql prepared statement
PreparedStatement ps = _dbConn.prepareStatement(query.toString());
ResultSet rs = ps.executeQuery();
But the query runs fine when I run it separately in SQL Developer. The query was originally created for Postgres, then updated for Oracle. Any tips?
You need to set the variables into the preparedStatement before executing.
PreparedStatement ps = _dbConn.prepareStatement(query.toString());
ps.setInt(1, 10);
Please post what query.toString() gives you if that doesn't work. Not query, but query.toString()
What are you doing in your:
// Insert parameters to complete the sql prepared statement
Are you using correctly the methods ps.setString... or whatever? Or are you just replacing the question marks? the second might be corrupting your query.
Based on #AlexPoole and #EdGibbs comments, I decided to add a bunch more debug statements. It turns out the method was being recursively called with a different sql "suffix" later on in the program if certain conditions were met. The suffix was not updated with the necessary parenthesis for the new ROWNUM wrapping the statement. So although the ORA-00907 can be thrown for many different formatting problems, it was in fact a right parenthesis that was causing me problems :P
The prefix and suffix seems like a weird pattern in this code base for creating sql queries. I'm thinking of getting rid of this and refactoring so queries don't have to be built like that. Any advice??
So for anyone else who runs into this Oracle error, I would suggest logging the sql statement you are generating and play around with it in SQL Developer. If it works in there, but not in your application, your code is probably doing something funky :P

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