EF4 Oracle Identity Insert - oracle

Does anyone know if its possible to call an oracle's sequence.NextVal from ef4 without using StoredProcedure? I have an Oracle db from a client which I cannot modify, so stroedproc are not an option for me. I use ef4 ctp5.
Thank!

For example, you can execute an SQL command:
OracleParameter param = new OracleParameter("p", OracleDbType.Integer, System.Data.ParameterDirection.Output);
oContext.Database.SqlCommand("begin SELECT sequence_name.nextval into :p FROM dual; end;", param);
int i = (int)param.Value;
I have tested this code using dotConnect for Oracle 6.0.86, it works.

I'm not familiar with ef4 but can you execute regular queries like this?
SELECT sequence_name.nextval
FROM dual;

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

passing the desc command to oracle using openquery

I am working on sql server 2005 with a linked server set up to Oracle. I can't get at the underlying account for the link. I need run the
desc <table>
command from SSIS to Oracle. I do have access to openquery. Is there a way to do this? I am guessing no but a question is easy :).
I do know that
select * from OPENQUERY(<server>,'desc <schema>.<table>') ;
doesn't work. The DBAs have been less than helpful with that, which is sad because all I need is the schema so that I can write the actual query that I need. I am open to any suggestions that might get me that answer. Thanks!
Michael.
DESC is a SQLPlus command, not an Oracle command. Try this query instead:
SELECT
Column_Name,
Data_Type,
Data_Length,
Data_Precision,
Nullable
FROM All_Tab_Columns
WHERE Owner = '<schema>' AND Table_Name = '<table>'
ORDER BY Column_ID
Make sure that <schema> and <table> are in uppercase.

Filtering date in oracle using ADO.NET

I´m changing the connection of my system from ADO to ADO.NET, and the same query does no longer works:
SELECT * FROM MY_TABLE WHERE MY_DATE_FIELD = '2011-01-20'
in ADO.NET I raise an ora-01861 error.
There is a way to change the format that ADO.NET uses ?
Thanks.
SELECT * FROM MY_TABLE WHERE MY_DATE_FIELD = TO_DATE('2011-01-20', 'yyyy-MM-DD')
should do it, you might as well use a parameterized query

Nhibernate Generate wrong SQL for Oracle with locking

yesterday I've been trying to make this code work inspite the fact it's just working fine with nhibernate and SQL server but when it come to oracle it generate wrong sql
UnitOfWork.Current.CreateCriteria<Bill>().Add(Restrictions.IsEmpty("ReqId"))
.SetMaxResults(BatchSize).SetLockMode(LockMode.Upgrade).List<Bill>();
the generated SQL will something like
Select * from
(Select bill_0.id,bill_0.BillNo ...... from Bill bill_0 where bill_0.reqId is Not null )
where ROWNUM < 10 for UPDATE of bill_0.ID
so i wont run because the allies bill_o is defined inside the inner sql statement so who got the solution ?
the correct sql would be something like this which i tried and worked on oracle db
Select bill_0.id,bill_0.BillNo ...... from Bill bill_0
where bill_0.reqId is Not null and ROWNUM < 10 for UPDATE of bill_0.ID
Since, as you say, NHibernate is generating invalid Oracle SQL, I suggest you file a bug with the NHibernate people. The SQL would work if the in-line view had been assigned an alias of "bill_0", or if the FOR UPDATE clause didn't use a table alias ("for UPDATE of ID"). Whether you can modify your NHibernate calls to make either of these happen I'm afraid I have no idea.

Oracle: LONG RAW to?

I am writing a program in java where I need to create a copy of a table (without data). for that I am using the following query
CREATE TABLE NEW_TABLE AS
SELECT * FROM OLD_TABLE
I have come across a table where one of the columns has the data type LONG RAW which is depricated.
I tried using the query below but it did not work. (ORA-01003: no statement parsed
)
CREATE TABLE NEW_TABLE AS
SELECT ID, COL1, COL2, TO_LOB(COL3) FROM OLD_TABLE
Can someone tell me a simple query for this. It should be able to store the values from the previous table. I am using oracle 10g
Thanks in advance.
EDIT:
Sorry it was my mistake, the above query worked fine but I was calling executeQuery instead of executeUpdate
Perhaps this discussion would help.
Sorry it was my mistake, the above query worked fine but I was calling executeQuery instead of executeUpdate which was throwing an SQLException

Resources