I have the following oracle statement which some days ago worked quick and fine. When I run it now it takes forever:
MERGE INTO tablef f using
(
select t.colf,t.colup
from tablet t
inner join (select max(created) as maxcreated
from tablet) mt
on t.created = mt.maxcreated) fu
on f.colf = fu.colf
WHEN MATCHED THEN
UPDATE SET f.aus = fu.colup
Or is there a way to reformulate the query to get it running again and faster?
The two tables involved have a primary key. For tablef the primary key is colf and for tablet the primary key is colf and created.
Actually I also want to run this query from an SQL server database via an oracle linked server.
And when I run this in SQL server management studio as follows:
execute ('MERGE INTO tablef f using
(
select
t.colf,t.colup
from tablet t
inner join (select max(created) as maxcreated from tablet) mt on t.created = mt.maxcreated) fu
on f.colf = fu.colf
WHEN MATCHED THEN
UPDATE SET f.aus = fu.colup') AT ORACLELINKEDSERVER*
it runs without error and says 1 row affected. However if I check the data on the oracle database the row is not updated.
Related
This is my first question on StackOverflow (but not the first question I asked to myself on Oracle SQL Developer :p)
My needs :
I first tried to do all my works exclusively on Oracle SQL Dev but it asks to much ressources to be done.
In consequences, I decided to only export all the data I need and then import all in R and do my work on it.
Finally, it takes about 2 minutes to do the job :D
My problem is :
I run about 10 different SQL script which are really simple. Please find below two of them :
select japolip_wnupo wnupo,japolip_socpo socpo,japolip_jasccdp_winag winag,japolip_wnpro wnpro,jaagenp_ainag,jaagenp_nomag
from sunapicf.japolip japolip
left join sunapicf.jaagenp jaagenp on jaagenp_winag = japolip_jasccdp_winag
;
select distinct socpr socpo,jaagenp.jaagenp_winag winag,JACRCFP.JACRCFP_wnpro wnpro,jaagenp_ainag,jaagenp_nomag
from sunapicp.JACRCFP JACRCFP
left join
(
select japrodp_wnpro,socpr
from sunapicp.japrodp japrodp
cross join xmltable('//JAPRODP' passing xmltype(japrodp.ficxml) columns SOCPR)
) japrodp on japrodp.japrodp_wnpro = JACRCFP.JACRCFP_wnpro
left join sunapicf.jaagenp jaagenp on jaagenp.jaagenp_winag = jacrcfp.jacrcfp_winit
;
Then I have to launch the Export function for every results, change the formatting and the type of file to be delivered to .dsv (just to have the right comma :D), and also change the folder directory and the name.
It is too much repetitive and can generate some mistakes.
That's why I would like to add a command line where I would specify the folder directory, the name, the formatting and what so ever.
Do you have any information about that ?
Thank you very much.
I did not try anything because I don't have any idea to try.
I tried to connect R to Oracle but I guess I have to pay for it (and the company does not want to :D).
Using SQLcl is definitely the way to go. Build a script (or set of scripts) that run all of the queries that you want to export data into CSV files. Below is an example script that will connect to the database, set formatting, generate the files then disconnect.
The script would get launched with a command like this:
sql /nolog #start_export.sql
start_export.sql example contents:
--Connect to the database
connect <username>/<password>#<TNSalias>
--Set format to CSV for results from SELECT statements
set sqlformat csv;
--Turn off the number of rows that get returned by the select
set feedback off;
--Create 1st report
spool report1.csv
select japolip_wnupo wnupo,japolip_socpo socpo,japolip_jasccdp_winag winag,japolip_wnpro wnpro,jaagenp_ainag,jaagenp_nomag
from sunapicf.japolip japolip
left join sunapicf.jaagenp jaagenp on jaagenp_winag = japolip_jasccdp_winag;
--Create 2nd report
spool report2.csv
select distinct socpr socpo,jaagenp.jaagenp_winag winag,JACRCFP.JACRCFP_wnpro wnpro,jaagenp_ainag,jaagenp_nomag
from sunapicp.JACRCFP JACRCFP
left join
(
select japrodp_wnpro,socpr
from sunapicp.japrodp japrodp
cross join xmltable('//JAPRODP' passing xmltype(japrodp.ficxml) columns SOCPR)
) japrodp on japrodp.japrodp_wnpro = JACRCFP.JACRCFP_wnpro
left join sunapicf.jaagenp jaagenp on jaagenp.jaagenp_winag = jacrcfp.jacrcfp_winit;
--Disconnect
exit
The following SQL command returns approximately 4.500 records and contains integer-, string- and blob (text) values. All indexes are set properly. Furthermore we know that the in clause is not the best but that shouldn't bother us right now. The SQL command is executed on a firebird 3.0 server:
Select
distinct O.Nr, O.Betreff, O.Text, O.Absenderadresse, O.Gelesen, O.Datum, O.Ordner, O.TextNotiz, M.ID, R.PosNr as RPosNr, R.AddressType, R.Address, R.Name, A.Nr as AttachmentNr, M.Bezeichnung as Mailordner, 0 as Archived
from Table1 O
left join Table2 R on (R.Nr = O.IDNr)
join Table3 M on (M.Nr = O.Ordner)
and (M.PersonalNr=O.PersonalNr)
left join Table4 A on (A.Nr = O.IDNr)
where (O.PersonalNr = 12)
and O.Ordner in (608,7440,7441,7444,6144,7091,5467,617,2751,710,6580,2812,609,7054,7194,7479,614,620,7030,615,3434,4883,619,6465,7613)
We executed the SQL command in an external application (from which we know that this application uses the FIBPlus components) and in our very basic sample Delphi7 application (which uses the original AnyDAC database components Version 8.0.5). If we fetch all records into a grid, we have the following performance:
External Application with FIBPlus ~ 200 – 400 milliseconds
Delphi7 with AnyDAC ~ 3.500 – 4.500 milliseconds
In our Delphi7 program we have connected a TADQuery to it's own TADTransaction.
The default settings are used for both components, except the ReadOnly property of the TADTransaction, which we changed to True
Now we wonder why the external application is approximately 10 times faster than our Delphi7 program?
Are there any properties which we can modify to speed up our Delphi 7 program?
Any help is appreciated...
I'm developing desktop application (WinForm) using vb.net and using LINQ to access the database (SQLSERVER 2016)
I have 2 instance database identical DB(same structure and data).
- SQLEXPRESS2016 (Express edition)
- SQLSERVER2016 (Developer edition)
But why I getting significant Different time execution and different schema execution plan also? The sql script generated by LINQ??
dim myResult = (from i in myDataContext.ItemMaster _
Where i.IsActive _
Order by m.ItemNumber).AsQueryable
dim count = myResult.Count()
I profiling the query generated by linq by SQL Server profiling, and myResult.Count() will generated the script (in this case the script is same between dev and standard/express):
Select Count(1) AS [value]
FROM( Select TOP (1000) NULL AS [EMPTY]
FROM ITEM_MASTER as [t0] WHERE IS_Active = 1
ORDER BY [t0].[ItemNumber]
)AS [t1]
My Question are:
1. Why in some cases the query was different between
Express/Standard edition and Developer edition? (The DB structure and data is same, just different version)
one will generated SELECT TOP (1)..., the other will SELECT TOP (2) ....
Why The execution time different is significant.
dev = 0.xx seconds
std/express = 8s econds.
it should not a big deal, since the number of rows about 10,000 something
Why the execution plan also different? std/express seems more complicated schema and some index is missing.
screenshot sql dev vs express/standard
It solved by adding NOEXPAND hint keyword.
See original answer here:
https://social.msdn.microsoft.com/Forums/en-US/b095ce80-6b19-45a5-9a31-4532fcd8af83/different-output-script-generated-by-linq-to-sql-2016-expressstandard-edition-vs-developer-edition?forum=sqlnetfx
credit to: Yuvraj Singh Bais
There is a log-time SQL which need to be performance-tuing. However I can not change the SQL, because it is generated by IDM(one application
developed by Oracle) automatically. The customer know it will be a
long time if they ask for the new edition of IDM which contain new
and fasted SQL. So I am required to boost the response time without
change the original SQL.
I give a solution of materialized view, however there are some
problems when I test for it.
The SQL is :
select * from scott.usr
where act_key in (select act_key
from scott.ACT act
START WITH act_key in ('267' )
connect by nocycle
prior act_key = parent_key)
For table ACT, there are two columns: act_key and parent_key, which is
foreign key relationship. My puzzle is , there is a input parameter 267, which is not fixed.
if I create a materialized view like the following:
sql> select act_key from scott.ACT act
connect by nocycle prior act_key = parent_key;
The query rewrite will not happen. Any input is appreciated.
Regards
santa
I have been using SQL Server 2008 for a short time now and have never used Oracle before. I am able to access an Oracle table through SQL Server with the syntax
select * from [OracleDB1]..[OracleDB1].[Zips]
(where OracleDB1 is the oracle database and Zips is the table I require)
Is it possible to join a SQL Server table with this one in a Table-valued Function? Just using a normal join as I would with SQL Server tables gives an Invalid object name error on the Oracle table.
Can this be done directly (or at all) or is it possible to do this some other way such as table variables?
example query:
select * from dbo.Table1 t INNER JOIN [OracleDB1]..[OracleDB1].[Zips] z where t.zip = z.zip
I was performing the join wrong since I missed the ON clause. I was able to get it to work by declaring a temptable and joining on that.
declare #tempTable table{
ZIP nvarchar(5),
COUNTY nvarchar(10)
}
insert #tempTable select ZIP, COUNTY, from [OracleDB1]..[OracleDB1].[ZIPS]
select * from dbo.Table1 t INNER JOIN #tempTable z on t.ZIP = v.ZIP where t.AdmissionOn >= '08-08-2011' AND t.AdmissionOn <= ''09-08-2011'
This also worked in line as I had in the original question once I added the ON clause but the table variable suits my needs better since it only has to access the Oracle table once and not each comparison.