code running in oracle 11g - oracle

I am having 3 tables case_details, codehead and case_staus. I am trying to fetch the values from database. Code mentioned below is running well in oracle 10 xe, but in oracle 11g 32 bit it is showing 0 rows...the code is
select a.case_id
,a.case_description
,a.case_contract_value
,b.sub_codehead
,c.case_status_name
from case_details a
,codehead b
,case_status c
where a.case_codehead = b.code_id
and a.case_status = c.case_status_id
and joint_directorate = 85
and case_status < 2
order by case_id;
I am unable to understand that well running code is not executing in oracle 11g...please help me out..

Related

What's wrong with this UPDATE SQL JOIN syntax? [duplicate]

This question already has answers here:
Oracle SQL: Update a table with data from another table
(7 answers)
Oracle SQL update based on subquery between two tables
(4 answers)
Closed 3 years ago.
Trying to update a column in a table based on the value in another table as part of a data migration. All the columns exist in both tables in the join, but am receiving an unexpected error message when I run the following:
UPDATE CSB
SET IFS10_SCHEDULE = CS.SCHEDULE_NO
FROM IC_U_CUSTOMER_SCHED_B CSB
JOIN CUST_SCHED CS
ON CSB.CUSTOMER_NO = CS.CUSTOMER_NO
AND CS.SHIP_ADDR_NO = CSB.SHIP_ADDR_NO
AND CSB.CUSTOMER_PART_NO = CS.CUSTOMER_PART_NO
AND CSB.DOC_NO = CS.DOC_NO
AND CSB.AGREEMENT_ID = CS.AGREEMENT_ID
AND CSB.CUST_SCHEDULE_TYPE = CS.CUST_SCHEDULE_TYPE;
I receive the error:
Error at Command Line : 3 Column : 1
Error report -
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
I'm sure it's got to be a syntax issue, but can't see where. Any ideas?
EDIT - thanks, solution obtained. For learning purposes (I've done T-SQL for the last 20 years and only just learning PL-SQL), I also re-wrote the query as a MERGE INTO - but this also failed. Any obvious issues here?:
MERGE INTO IC_U_CUSTOMER_SCHED_B CSB
USING CUST_SCHED CS
ON (CSB.CUSTOMER_NO = CS.CUSTOMER_NO
AND CS.SHIP_ADDR_NO = CSB.SHIP_ADDR_NO
AND CSB.CUSTOMER_PART_NO = CS.CUSTOMER_PART_NO
AND CSB.DOC_NO = CS.DOC_NO
AND CSB.AGREEMENT_ID = CS.AGREEMENT_ID
AND CSB.CUST_SCHEDULE_TYPE = CS.CUST_SCHEDULE_TYPE)
WHEN MATCHED THEN UPDATE SET CSB.IFS10_SCHEDULE = CS.SCHEDULE_NO
WHERE CSB.IFS10_SCHEDULE != CS.SCHEDULE_NO;
Should be
UPDATE ic_u_customer_sched_b csb
SET csb.ifs10_schedule =
(SELECT cs.schedule_no
FROM cust_sched cs
WHERE csb.customer_no = cs.customer_no
AND cs.ship_addr_no = csb.ship_addr_no
AND csb.customer_part_no = cs.customer_part_no
AND csb.doc_no = cs.doc_no
AND csb.agreement_id = cs.agreement_id
AND csb.cust_schedule_type = cs.cust_schedule_type);

DB2 iSeries doesn't lock on select for update

I'm migrating a legacy application using DB2 iSeries on AS400 that has a specific behavior that I have to reproduce using .NET and DB2.Data.DB2.iSeries client for .NET.
What I'm describing works for me with DB2 non AS400 but in AS400 DB2 it worlks for the legacy application i'm replacing - but not with my application.
The behavior in the original application:
Begin Transaction
ExecuteReader () => Select col1 from table1 where col1 = 1 for update.
The row is now locked. anyone else who tries to run Select for update should fail.
Close the Reader opened in line 2.
The row is now unlocked. - anyone else who tried to run select for update should succeed.
Close transaction and live happily ever after.
In my .NET code I have two problems:
Step 2 - only checks if the row is already locked - but doesn't actually lock it. so another user can and does run select for update - WRONG BEHAVIOUR
Once that works - I need the lock to get unlocked when the reader is closed (step 4)
Here's my code:
var cb = new IBM.Data.DB2.iSeries.iDB2ConnectionStringBuilder();
cb.DataSource = "10.0.0.1";
cb.UserID = "User";
cb.Password = "Password";
using (var con = new IBM.Data.DB2.iSeries.iDB2Connection(cb.ToString()))
{
con.Open();
var t = con.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
using (var c = con.CreateCommand())
{
c.Transaction = t;
c.CommandText = "select col1 from table1 where col1=1 FOR UPDATE";
using (var r = c.ExecuteReader())
{
while (r.Read()) {
MessageBox.Show(con.JobName + "The Row Should Be Locked");
}
}
MessageBox.Show(con.JobName + "The Row Should Be unlocked");
}
}
When you run this code twice - you'll see both processes reach the "This row should be locked" which is the problem I'm describing.
The desired result would be that the first process will reach the "This row should be locked" and that the second process will fail with resource busy error.
Then when the first process reaches the second message box - "the row should be unlocked" the second process( after running again ) will reach the "This row should be locked" message.
Any help would be greatly appreciated
The documentation says:
When the UPDATE clause is used, FETCH operations referencing the cursor acquire an exclusive row lock.
This implies a cursor is being used, and the lock occurs when the fetch statement is executed. I don't see a cursor, or a fetch in your code.
Now, whether .NET handles this as a cursor, I don't know, but the DB2 UDB documentation does not have this notation.
Isolation Level allows this behavior. Reading rows that are locked.
ReadUncommitted
A dirty read is possible, meaning that no shared locks are issued and no exclusive locks are honored.
After much investigations we created a work around in the form of a stored procedure that performs the lock for us.
The stored procedure looks like this:
CREATE PROCEDURE lib.Select_For_Update (IN SQL CHARACTER (5000) )
MODIFIES SQL DATA CONCURRENT ACCESS RESOLUTION WAIT FOR OUTCOME
DYNAMIC RESULT SETS 1 OLD SAVEPOINT LEVEL COMMIT ON RETURN
NO DISALLOW DEBUG MODE SET OPTION COMMIT = *CHG BEGIN
DECLARE X CURSOR WITH RETURN TO CLIENT FOR SS ;
PREPARE SS FROM SQL ;
OPEN X ;
END
Then we call it using:
var cb = new IBM.Data.DB2.iSeries.iDB2ConnectionStringBuilder();
cb.DataSource = "10.0.0.1";
cb.UserID = "User";
cb.Password = "Password";
using (var con = new IBM.Data.DB2.iSeries.iDB2Connection(cb.ToString()))
{
con.Open();
var t = con.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
using (var c = con.CreateCommand())
{
c.Transaction = t;
c.CommandType = CommandType.StoredProcedure;
c.AddParameter("sql","select col1 from table1 where col1=1 FOR UPDATE");
c.CommandText = "lib.Select_For_Update"
using (var r = c.ExecuteReader())
{
while (r.Read()) {
MessageBox.Show(con.JobName + "The Row Should Be Locked");
}
}
MessageBox.Show(con.JobName + "The Row Should Be unlocked");
}
}
We don't like it - but it works.

Strange query behavior oracle 11g

I have a query as:
SELECT ps_node_id,name
FROM cz_ps_nodes WHERE cz_ps_nodes.ps_node_type=261
START WITH NAME = 'Bundle Rule Repository',cz_ps_nodes.devl_project_id = P_devl_project_id AND cz_ps_nodes.deleted_flag = 0
CONNECT BY PRIOR ps_node_id = parent_id.
This query works.
But if I just remove the name from the select part like:
SELECT ps_node_id
FROM cz_ps_nodes WHERE cz_ps_nodes.ps_node_type = 261
START WITH NAME = 'Bundle Rule Repository',cz_ps_nodes.devl_project_id = P_devl_project_id AND cz_ps_nodes.deleted_flag = 0
CONNECT BY PRIOR ps_node_id = parent_id.
The query just hangs but was working on oracle 10 g and the problem started when we upgraded to oracle 11g.
Could anyone explain why?
Got the issue solved by using : alter session set optimizer_features_enable='10.2.0.4' –

Connecting to Oracle Database in Haskell using HDBC

I was trying to work with Oracle Database from Haskell and have faced with such problem.
So, there is this code.
module Main where
import Database.HDBC
import Database.HDBC.ODBC
main :: IO ()
main = do
let connectionString = "Driver={Microsoft ODBC for Oracle};Server=127.0.0.1;Uid=valera;Pwd=2562525;"
let ioconn = connectODBC connectionString
conn <- ioconn
vals <- quickQuery conn "SELECT * FROM PERSONS_TEST" []
print vals
return ()
Pretty simple, huh? But that won't work. With this connection string the error is
*** Exception: SqlError {seState = "[\"HY090\"]", seNativeError = -1, seErrorMsg = "sqlGetInfo SQL_TXN_CAPABLE: [\"0: [Microsoft][ODBC driver for Oracle]\\65533...
and then 65333 repeats many times. And with this
Provider=msdaora;Data Source=127.0.0.1;User Id=valera;Password=2562525;
the error is
*** Exception: SqlError {seState = "[\"IM002\"]", seNativeError = -1, seErrorMsg = "connectODBC/sqlDriverConnect: [\"0: [Microsoft][\\65533...
and 65333 repeats again till the end
I suppose, that the problem is in connection string, but I had tried a whole bunch of them (I've used http://www.connectionstrings.com/)
I'm using Haskell Platform 2011.4.0.0, GHC 7.0.4, Oracle Database XE 11.2 on Windows 7 64-bit. Microsoft MDAC SDK installed.
\65533 and so on is the symbols of ODBC driver error message string in your locale (RU?). I find the best way so on to develop in english locale system, thus error messages in ghci console shown in english language and can be read.

SELECT FOR UPDATE not working with JDBC and Oracle

I've written a simple Java program, which opens a transaction, selects some records, does some logic and then updates them. I want the records to be locked so I used SELECT...FOR UPDATE.
The program works perfectly fine with MS SQL Server 2005, but in Oracle 10g the records are not locked!
Any idea why?
I create the connection as follow:
Connection connection = DriverManager.getConnection(URL, User, Password);
connection.setAutoCommit(false);
If I execute the SELECT..FOR UPDATE from Oracle SQL Developer client I can see that the records are locked, so I'm thinking it might be an issue with the JDBC driver rather than a database problem, but I couldn't find anything useful online.
These are the details of the JDBC driver I'm using:
Manifest-Version: 1.0
Implementation-Vendor: Oracle Corporation
Implementation-Title: ojdbc14.jar
Implementation-Version: Oracle JDBC Driver version - "10.2.0.2.0"
Implementation-Time: Tue Jan 24 08:55:21 2006
Specification-Vendor: Oracle Corporation
Sealed: true
Created-By: 1.4.2_08 (Sun Microsystems Inc.)
Specification-Title: Oracle JDBC driver classes for use with JDK14
Specification-Version: Oracle JDBC Driver version - "10.2.0.2.0"
Sorry, I cannot reproduce this behaviour. Exactly how are you running your SELECT ... FOR UPDATE queries in JDBC?
I have a table, locktest with the following data in it:
SQL> select * from locktest;
A B
---------- ----------
1 0
2 0
3 0
4 0
5 0
I also have this Java class:
import oracle.jdbc.OracleDriver;
import java.sql.*;
public class LockTest {
public static void main(String[] args) throws Exception {
DriverManager.registerDriver(new OracleDriver());
Connection c = DriverManager.getConnection(
"jdbc:oracle:thin:#localhost:1521:XE", "user", "password");
c.setAutoCommit(false);
Statement stmt = c.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rSet = stmt.executeQuery(
"SELECT a, b FROM locktest FOR UPDATE");
while (rSet.next()) {
if (rSet.getInt(1) <= 3) {
rSet.updateInt(2, 1);
}
}
System.out.println("Sleeping...");
Thread.sleep(Long.MAX_VALUE);
}
}
When I run this Java class, it makes some updates to the table and then starts sleeping. It sleeps so that it keeps the transaction open and hence retains the locks.
C:\Users\Luke\stuff>java LockTest
Sleeping...
While this is sleeping, I try to concurrently update the table in SQL*Plus:
SQL> update locktest set b = 1 where a <= 3;
At this point, SQL*Plus hangs until I kill the Java program.

Resources