Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserted data is not shown in Oracle db using a direct query

Tags:

sql

oracle

I was not able to find a solution for this question online, so I hope I can find help here.

I've inherited a Java web application that performs changes to an Oracle database and displays data from it. The application uses a 'pamsdb' user ID. The application inserted a new row in the one of the tables (TTECHNOLOGY). When the application later queries the db, the result set includes the new row (I can see it in print outs and in the application screens). However, when I query the database directly using sqldeveloper (using the same user id 'pamsdb'), I do not see the new row in the modified table.

A couple of notes:

1) I read here and in other locations that all INSERT operations should be followed by a COMMIT, otherwise other users cannot see the changes. The Java application does not do COMMIT, which I thought could be the source of the problem, but since I'm using the same user ID in sqldeveloper, I'm surprised I can't see the changes there.

2) I tried doing COMMIT WORK from sqldeveloper, but it didn't change my situation.

Can anyone suggest what's causing the discrepancy and how can it be resolved?

Thanks in advance!

like image 221
Tamara Aviv Avatar asked Mar 17 '16 18:03

Tamara Aviv


People also ask

Which function is used to INSERT data values in Oracle INSERT?

Example - Using VALUES keyword The simplest way to create an Oracle INSERT query to list the values using the VALUES keyword. For example: INSERT INTO suppliers (supplier_id, supplier_name) VALUES (5000, 'Apple'); This Oracle INSERT statement would result in one record being inserted into the suppliers table.

How do you INSERT data directly from Excel to Oracle Database?

In Oracle sql developer go to Tables --> select import data ---> select your excel or csv file --> it will display the column --> import the data into a table. so helpful.

How does INSERT query work?

We can add new rows of data to the existing table by using the INSERT queries in SQL. Below is the syntax used for inserting values to a table with the specific columns we want certain values to be inserted. INSERT INTO table_name (column1, column2, column3 ... columnN) VALUES (value1, value2, value3.....

What is INSERT statement in Oracle?

The INSERT statement adds one or more new rows of data to a database table. For a full description of the INSERT statement, see Oracle Database SQL Reference. Syntax.


Video Answer


1 Answers

You're using the same user, but in a different session. Once session can't see uncommitted changes made in another session, for any user - they are independent.

You have to commit from the session that did the insert - i.e. your Java code has to commit for its changes to be visible anywhere else. You can't make the Java session's changes commit from elsewhere, and committing from SQL Developer - even as the same user - only commits any changes made in that session.

You can read more about connections and sessions, and transactions, and the commit documentation summarises as:

Use the COMMIT statement to end your current transaction and make permanent all changes performed in the transaction. A transaction is a sequence of SQL statements that Oracle Database treats as a single unit. This statement also erases all savepoints in the transaction and releases transaction locks.

Until you commit a transaction:

  • You can see any changes you have made during the transaction by querying the modified tables, but other users cannot see the changes. After you commit the transaction, the changes are visible to other users' statements that execute after the commit.
  • You can roll back (undo) any changes made during the transaction with the ROLLBACK statement (see ROLLBACK).

The "other users cannot see the changes" really means other user sessions.


If the changes are being committed and are visible from a new session via your Java code (after the web application and/or its connection pool have been restarted), but are still not visible from SQL Developer; or changes made directly in SQL Developer (and committed there) are not visible to the Java session - then the changes are being made either in different databases, or in different schemas for the same database, or (less likely) are being hidden by VPD. That should be obvious from the connection settings being used by the two sessions.

From comments it seems that was the issue here, with the Java web application and SQL Developer accessing different schemas which both had the same tables.

like image 200
Alex Poole Avatar answered Nov 06 '22 23:11

Alex Poole