getting error while executing same query in Oracle - 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’
);

Related

SQL command not properly ended on insert query

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'
???

Oracle- Update multiple tables with same column name

Hi there I am new to oracle I am looking for a good way to convert my MySQL query into Oracle SQL
here is the SQL from my MySQL:
update billing, kb_detail
set tanggal_penagihan = :tanggal_penagihan
is_change = :is_change
where billing.no_billing_sap = :no_billing_sap
and billing.no_billing_sap = kb_detail.no_billing_sap
while I was reading the answers most ppl give, I found out that I need to use merge into syntax or make a loop and assign the column name one by one, is there any better way?
I mean like a simple way that MySQL update syntax
The only way to update two tables in Oracle is to run two UPDATE statements:
update billing
set tanggal_penagihan = :tanggal_penagihan
where no_billing_sap = :no_billing_sap;
update kb_detail
is_change = :is_change
where no_billing_sap = :no_billing_sap;
If you wrap that in a transaction there won't be a difference to what you did in MySQL

using an update query inside a select SQL injection (oracle)

I got an SQL injection point which allows me to insert anything after a Select keyword , such as :
Select ID FROM %INJECTION POINT%
is there anyway to complete this query to make an update for a table ? without using a ";" ?
It's not possible to do this in oracle , unless you use an existing user function to do so

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

Resources