Oracle MERGE statement not 'sticking' using DevArt dotConnect for Oracle - 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();

Related

Oracle OJDBC MERGE Statement and Generated Keys

Does Oracle ~>12 support generated keys using a Merge statement? Some sudo code..
MERGE INTO TARGET_TABLE TRG
USING (SELECT CAST(? AS NUMBER) AS ID FROM DUAL) SRC
ON (TRG.ID = SRC.ID)
WHEN MATCHED THEN UPDATE SET....
WHEN NOT MATCHED THEN
INSERT(ID....)
VALUES(MYSEQ.NEXTVAL...)
The prepared statement is set up;
try (PreparedStatement pstmt =
connection.prepareStatement(
loadStatement(sqlName, connection, getClass()), new String[] {ID})) {
...
int inserted = pstmt.executeUpdate();
ResultSet rs = pstmt.getGeneratedKeys();
List<Long> keys = new ArrayList<>(inserted);
while (rs.next) {
rs.getLong(1);
}
return keys;
...
I have in-memory tests where the connection uses the H2 driver running the very same SQL and PreparedStatment and that returns the generated key just fine, but Oracle does not.
Reviewing the docs it would suggest it does not?
Thanks!

Oracle not using index, Entity Framework & Devart DotConnect for oracle

The table in question has ~30mio records. Using Entity Framework I write a LINQ Query like this:
dbContext.MyTable.FirstOrDefault(t => t.Col3 == "BQJCRHHNABKAKU-KBQPJGBKSA-N");
Devart DotConnect for Oracle generates this:
SELECT
Extent1.COL1,
Extent1.COL2,
Extent1.COL3
FROM MY_TABLE Extent1
WHERE (Extent1.COL3 = :p__linq__0) OR ((Extent1.COL3 IS NULL) AND (:p__linq__0 IS NULL))
FETCH FIRST 1 ROWS ONLY
The query takes about four minutes, obviously a full table scan.
However, handcrafting this SQL:
SELECT
Extent1.COL1,
Extent1.COL2,
Extent1.COL3
FROM MY_TABLE Extent1
WHERE Extent1.COL3 = :p__linq__0
FETCH FIRST 1 ROWS ONLY
returns the expected match in 200ms.
Question: Why is it so? I would expect the query optimizer to note that the right part is false if the parameter is not null, so why doesn't the first query hit the index?
Please set UseCSharpNullComparisonBehavior=false explicitly:
var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
config.QueryOptions.UseCSharpNullComparisonBehavior = false;
If this doesn't help, send us a small test project with the corresponding DDL script so that we can investigate the issue.

Query failing on Oracle 12c and 18c when changing NLS_SORT to BINARY_CI

I have the following query which correctly returns records when I execute it via code or Oracle SQL Developer.
SELECT TABLE_T.COL_P,
1234 AS COL_C,
TABLE_T.COL_D,
SUM(SOME_COLUMN) Value
FROM TABLE_T
INNER JOIN TABLE_E E ON TABLE_T.COL_P = E.COL_P
AND TABLE_T.COL_C = E.COL_C
AND TABLE_T.COL_CC = E.COL_CC
AND TABLE_T.COL_CL = E.COL_CL
INNER JOIN TABLE_C C1 ON C1.COL_P = E.COL_P
AND C1.COL_C = E.COL_C
INNER JOIN TABLE_C C2 ON C2.COL_P = C1.COL_P
AND C2.COL_CX = C1.COL_CX
AND C2.COL_CY = C1.COL_CY
AND C2.COL_CZ = C1.COL_CZ
WHERE TABLE_T.COL_P = 'Some Text'
AND C2.COL_C = 1234
AND TABLE_T.COL_CL IN
(SELECT COL_CL
FROM TABLE_CL
WHERE COL_P = 'Some Text'
AND ((COL_CLTYPE = 'VALUE_A')
OR (COL_CLTYPE = 'VALUE_B')
OR (COL_CLTYPE = 'VALUE_C')
OR (COL_CLTYPE = 'VALUE_D')) )
GROUP BY TABLE_T.COL_P,
TABLE_T.COL_D
However, it fails to return records once I execute the following session commands:
ALTER SESSION SET NLS_COMP = LINGUISTIC;
ALTER SESSION SET NLS_SORT = BINARY_CI;
This problem only occurs when I'm running against an Oracle 12c or 18c database.
It works find with/without the session commands when running against an Oracle 12C R2 or 11g database.
I've already checked the Explain Plan for 12c/18c and 12cR2 and its creating the same plan.
I found out that by adding an ORDER BY clause to the query (ORDER BY TABLE_T.COL_D, it resolves the problem.
Any ideas on what might be causing this problem?
I know the ORDER BY solution works, but I'd like to know what the underlying cause is and if there's a better solution to it.

ORA-01779 on Join Update

I'm developing a web application on vb.net with Oracle as DB and I'm having some problems to update a table by using joins.
Since I'm kind of a newbie on Oracle, I can't make my query go on...i've been reading and I knew that oracle doesn't supports Joins on UPDATE, so i searched for alternatives and I finished on this:
UPDATE (SELECT pda.id_propuesta
FROM abd_prop_det_archivos pda
INNER JOIN abd_participantes_invitados pi
ON (pda.id_solicitud = pi.id_solicitud)
AND pi.id_solicitud = :id_solicitud
AND pi.rut = :rut)
SET id_propuesta = :id_propuesta
I'm using Oracle 11g.
It appears that you want a WHERE EXISTS clause
UPDATE abd_prop_det_archivos pda
SET ID_PROPUESTA = :ID_PROPUESTA
WHERE EXISTS( SELECT 1
FROM ABD_PARTICIPANTES_INVITADOS pi
WHERE pda.id_solicitud = pi.id_solicitud)
AND pi.id_solicitud = :id_solicitud
AND PI.RUT = :RUT )

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

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.

Resources