Why a select query is running slower in Oracle than sql server - oracle

I am reading data from Oracle database by using ODP.Net with the follwing code
OracleConnection con = new OracleConnection(connectionString);
OracleCommand cmd = new OracleCommand( SELECT ID,RECORD(XMLType) FROM tbl_Name, con);
con.Open();
OracleDataReader _dataReader = cmd.ExecuteReader();
while (_dataReader.Read())
{
string rowId = _dataReader[0].ToString();
string xmlString = _dataReader[1].ToString();
adding this data into Queue for further processing
}
It working fine but in a minute it's reading only 10000 record. If I use SqlServer database it's reading 500000 record in minute having table with same schema.
Please help me if I am missing something to read data faster using ODP.NET
Thank you.
**
ANSWER:
**
I have tried with GetClobVal() and GetString Val() functions, now it is working fine.
select t.RECID, t.XMLRECORD.GetClobVal() from tableName t"
select x.RECID,x.XMLRECORD.getStringVal() from tableName x"
If we use these queries with oracle command it will run fast, but not as fast as sql server query.

Related

SSIS sending query with data parameter to Oracle cloud VS-2019 and MS Oracle Source

Already checked this post: SSIS and sending query with date to Oracle
And I'm using variable query per below thread
SSIS - Using parameters in Oracle Query using Attunity Oracle Datasource
Tool used: VS-2019
Data flow: MS Oracle Source (for VS-2019)
My source is Snowflake cloud. I'm successfully able to get the max date from table and store in Object type variable (named:- #var_Snowflake_Table_maxDate). Then I use a script task to convert the value to string type.
Code for script task is:
public void Main()
{
OleDbDataAdapter A = new OleDbDataAdapter(); //using System.Data.OleDb; ADDED above in NAMESPACES
System.Data.DataTable dt = new System.Data.DataTable();
A.Fill(dt, Dts.Variables["User::var_Snowflake_Table_maxDate"].Value);
foreach (DataRow row in dt.Rows)
{
object[] array = row.ItemArray;
Dts.Variables["User::var_CreateDate"].Value = array[0].ToString();
}
Dts.TaskResult = (int)ScriptResults.Success;
}
This sets my param of #var_CreateDate String type correctly. I tried this on local machine and was able to pass the value to a native instance of sql-server(yes NOT oracle). Just to test my parameters from script task works.
Finally: I'm using VS-2019's MS Oracle Source to pass the value into Oracle cloud server. Sample query's I have tried
"select * from Table where rownum <= 5 and NVL(CREATE_DATE,UPDATE_DATE) = " +"'05-09-2020'"
::::evals to::::
select * from relate.awd_acct_activity where rownum <= 5 and NVL(CREATE_DATE,UPDATE_DATE) = '2020-05-09'
and this works. But value is hard coded.
Try 2:
"select * from table where rownum <= 50 and
NVL(CREATE_DATE,UPDATE_DATE) = " +"'#[User::var_CreateDate]'"
Try 3:
"select * from table where rownum <= 50 and
NVL(CREATE_DATE,UPDATE_DATE) = to_date(" +"'#[User::var_CreateDate]'"+")"
Try 4:
"select * from table where rownum <= 50 and
NVL(CREATE_DATE,UPDATE_DATE) = to_date(" +"'#[User::var_CreateDate]'"+",'YYYY-MM-DD')"
None of try 2 through 4 eval correctly. Can I have some guidance into how to pass this parameter to Oracle cloud.
Thanks.
I'm assuming you're trying to figure out the syntax for a variable, that would hold the query text. You can try something like this:
"select * from table where rownum <= 50 and
NVL(CREATE_DATE,UPDATE_DATE) = to_date(" + "'" + #[User::var_CreateDate] + "'" + ",'YYYY-MM-DD')"

ORA-01461: can bind a LONG value only for insert into a LONG column via Access

I am trying to run the below query in Access on a Oracle database :-
UPDATE tblQuotesNew SET tblQuotesNew.Quote_Status = 'Expired'
WHERE tblQuotesNew.Quote_Status='In Progress' AND tblQuotesNew.Date_Quote_Sent<DateAdd('m',-1,Date())
The data type of Quote_Status is VARCHAR2 size 255. The data type of Date_Quote_Sent is Date.
I am connecting to the Oracle database using the code below :-
Dim mydb As DAO.Database
Dim myq As DAO.QueryDef
connectstring = "ODBC;DSN=Comsales;UID=Comsales;PWD=******;SERVER=PDBREPT"
sqltext = "UPDATE tblQuotesNew SET tblQuotesNew.Quote_Status = 'Expired' WHERE tblQuotesNew.Quote_Status='In Progress' AND tblQuotesNew.Date_Quote_Sent<DateAdd('m',-1,Date());"
myq.ReturnsRecords = False
myq.Connect = connectstring
myq.SQL = sqltext
myq.Execute
myq.Close
When I run this query I get a ORA-01461: can bind a LONG value only for insert into a LONG column error.
You're running an Access query (using Access SQL functions) as a Pass-Through query (by setting connectstring = "ODBC;...).
This won't work. Either use Oracle syntax in a Pass-Through query, or Access syntax in a "regular" Access query.
For the latter, tblQuotesNew must be a linked table, and the query connect string must be empty.

Query results in Oracle SQL Developer are different to those using .Net ODP

I have this query:
SELECT
case
when
AddressType IN (select code.codeid from code where code.codeset = AddressTypeCodeSet and code.description like 'Postal%')
then 'PostalAddress'
when
AddressType IN (select code.codeid from code where code.codeset = AddressTypeCodeSet and code.description like 'Email%')
then
'EmailAddress'
else
'OtherAddress'
end as AddressType
FROM VW_Address
WHERE AddressId=190000;
When I execute this query using SQL Developer, the result returned is OtherAddress. This is what I'm expecting. However, when I execute the same query via this code:
Dim cmd =
New Oracle.DataAccess.Client.OracleCommand(["SQL HERE]")
cmd.Parameters.Add(":p0", OracleDbType.Int32)
cmd.Parameters(0).Value = 190000
cmd.BindByName = True
Dim r = cmd.ExecuteReader()
I get a different result: EmailAddress
ODP is version 2.111.7.20, Oracle is 11g.

JDBC PreparedStatement, UNION Select and parameter passing

Ok, I know the answer is simple and I'm going to feel pretty dumb but...
Java JDK 1.7, Sybase JDBC driver
Code snipit:
String sql = "select <blah>
from <blah blah>
where date1 = ?
UNION
select <blah>
from <blah blah>
where date2 = ?";
Connection conn = ConnectionManager.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql);
logger.info("parmemeter count: " + stmt.getParameterMetaData().getParameterCount());
stmt.setDate(1, new java.sql.Date(date.getTime()));
stmt.setDate(2, new java.sql.Date(date.getTime()));
ResultSet rs = stmt.executeQuery();
while rs.next()) {
// the rest of the code
}
So why is the parmeter count only 1?
Running the program throws an error complaining: java.sql.SQLException: Invalid parameter index 2.
If I reduce the sql to either piece and reduce the setDate() to only 1 it works just fine.
The SQL with the UNION runs just fine in an interactive sql session (? filled in with a date of course)
I just ran into this problem, and this thread was very helpful. It's not the union clause that's throwing errors; it's the date that you're passing in. If you're using to_date () (unclear from your code snippet), you need to be passing a string in the query (instead of a date). Good luck!

Oracle MERGE statement not 'sticking' using DevArt dotConnect for Oracle

I'm using an Oracle MERGE statement in dotConnect for Oracle, I know that the MERGE itself is fine as runs in P-Sql and SQL Developer, yet using the dotConnect and ExecuteNoQuery the query is apparently successful (no exceptions thrown) but the table has had no updates or inserts taken place.
I can break the query into an Update and an Insert and they stick ok.
Any Ideas ?
We have answered to you at our forum: http://forums.devart.com/viewtopic.php?f=1&t=29549
As a workaround, you can try using:
1) the OCI mode;
or
2) this code:
OracleConnection conn = new OracleConnection("User Id=user;Password=pass;Server=dboracle;SID=sid;Direct=true");
conn.Open();
OracleTransaction t = conn.BeginTransaction();
OracleCommand comm = new OracleCommand(#"MERGE INTO ...");// place here your merge statement
comm.Transaction = t;
comm.Connection = conn;
comm.ExecuteNonQuery();
t.Commit();

Resources