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
Related
I am trying to get data from a single Oracle database table in Power BI Desktop. This table has around 2 million rows of data.
The following Query works just fine:
let
Source = Oracle.Database("PPM_PROD", [HierarchicalNavigation=true]),
PPM_DEV = Source{[Schema="PPM_DEV"]}[Data],
Timesheets = PPM_DEV{[Name="BI_TIMESHEET"]}[Data]
in
Timesheets
However, if I add an SQL statement as below, I run into problems:
let
Source = Oracle.Database("PPM_PROD", [HierarchicalNavigation=true, Query="SELECT * FROM PPM_DEV.BI_TIMESHEET#(lf)WHERE (ACTUAL_TIME > 0) OR (OVERTIME > 0) "]),
PPM_DEV = Source{[Schema="PPM_DEV"]}[Data],
Timesheets = PPM_DEV{[Name="BI_TIMESHEET"]}[Data]
in
Timesheets
This query will not get any data and data load/refresh will be stuck at "Evaluating" phase forever. Any suggestions will be greatly appreciated.
In this case, I'd recommend not using the SQL statement but rather filtering it in the Power Query Editor. In the most common filtering scenarios, Power Query will transform the filter steps applied into a native query similar to your SQL statement.
You can still use a SQL statement if you prefer but the steps
PPM_DEV = Source{[Schema="PPM_DEV"]}[Data],
Timesheets = PPM_DEV{[Name="BI_TIMESHEET"]}[Data]
don't make sense if you've already selected and filtered the Timesheets table. Those steps are there to navigate to the schema and table you intend to query but you've already handled that in your SQL.
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’
);
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.
I'd like to generate the following SQL with rails / arel:
SELECT * FROM GROUPS
WHERE id = 10
CONNECT BY PARENT_ID = ID
I don't want to use plain SQL except for the last statement which is oracle specific (the real query is much more complex and I don't want to perform endless string concatenations).
What I've tried so far:
Group.where(id: 10).join('CONNECT BY PARENT_ID=ID')
This does not work as it places the custom SQL before the WHERE statement (as it assumes it's a join).
So the actual question is, how to add a custom bit of SQL to a query after the WHERE statements?
Is it possible to update 2 columns in an Update statement that are in different tables? - The reason for the"scripted":
Where "Scripted" will be the "flag" so the formula does not run again on the same records if this field is filled in.
MERGE INTO arinvt_lot_docs ALD
USING
(SELECT arinvt.id,arinvt.class,fgmulti.in_date fgmulti.cuser3 FROM arinvt,fgmulti
WHERE arinvt.class LIKE 'CP%'
OR arinvt.class LIKE 'FG%'
OR arinvt.class LIKE 'IN%'
OR arinvt.class LIKE 'LA%'
OR arinvt.class LIKE 'PK%') Classes
ON (ALD.arinvt_id = classes.id
AND to_date(in_date) = '31-Dec-2015') --just picked a date to validate
WHEN MATCHED THEN
UPDATE SET non_conform_id = '21', fgmulti.cuser3 = 'SCRIPTED' --this text "Scripted" will fill in a field that will tell us in our reports if this was set by the script
I would like to join the tables using the arinvt.id field that is present in all 3 tables ARINVT_LOT_DOCS, FGMULTI & obviously ARINVT. ARINVT_LOT_DOCS & FGMULTI contain the NON_CONFROM_ID field that needs to be changed to '21'. The FGMULTI table also contains the CUSER3 field that would have "SCRIPTED" entered in it. The ARINVT table contains the Class of the inventory item which reflects in the conditions mentioned.
You cannot update two tables in one query in Oracle and other DBMS such as SQL Server but you can use transaction to achieve similar result.
This oracle community answers exactly that, if you try to join two tables, you will get this error
ORA-01776: cannot modify more than one base table through a join view
You can use transactions to update two tables in batch-like statement.
This https://stackoverflow.com/a/2044520 shows how to do it but for SQL Sever though. You need similar statement in Oracle.