Unable to SELECT data that is definitely there

oracle

This is truly strange. I'm connecting to an Oracle Docker container (epiclabs/docker-oracle-xe-11g) and performing the following operations:

  1. alter database default tablespace users
  2. create user foo identified by foo
  3. alter user foo quota unlimited on users
  4. create table foo.bar
  5. insert into foo.bar some data 5 times.
  6. Verify that select count(*) from foo.bar returns 5. So far so good.
  7. Open a second connection to the same database.
  8. select * from foo.bar order by baz asc

This query returns 0 rows.

Things I've ruled out:

  • The container isn't being reset, because the table foo.bar still exists. (I tried saying select * from foo.GARBAGE just to make sure it wasn't erroring out on a missing table and swallowing the error. It errored as expected. So the table is there.)
  • The second connection isn't a different user with no permissions. Verified by select USER from DUAL. Same username both times, and if it was a permissions issue I'd expect to see an error.

So… what could be the reason why I'm getting no rows returned from a table I've verified is populated with data, on a query with no WHERE clause?

Best Answer

Global temporary table was just a guess, because you had not posted the actual statement for table creation, and already said you used explicit commit. Using the information you gave us, we can only guess.

But here it is, works as expected:

[root@r5 ~]# docker pull epiclabs/docker-oracle-xe-11g
Using default tag: latest
latest: Pulling from epiclabs/docker-oracle-xe-11g
e92ed755c008: Pull complete
b9fd7cb1ff8f: Pull complete
ee690f2d57a1: Pull complete
53e3366ec435: Pull complete
51f7c9099c0d: Pull complete
1b7f09633195: Pull complete
4a8ff9746209: Pull complete
6bae0d820e30: Pull complete
Digest: sha256:

404173b90d09d0619c854dd469c76c3e7256c88a7aac5d47e05f934ec7afae06
Status: Downloaded newer image for epiclabs/docker-oracle-xe-11g:latest
docker.io/epiclabs/docker-oracle-xe-11g:latest
[root@r5 ~]# mkdir /storage/wdred_3tb_raid/mydata
[root@r5 ~]# docker run -d -v /storage/wdred_3tb_raid/mydata:/u01/app/oracle -p 1521:1521 epiclabs/docker-oracle-xe-11g
29f5bcbd1ccbf88d59111d653830098e6a965c602d07adfad5b331c7be8a4b95
[root@r5 ~]#

Test from other machine:

[oracle@o81 ~]$ sqlplus system/oracle@\"r5/xe\"

SQL*Plus: Release 19.0.0.0.0 - Production on Mon May 24 20:31:08 2021
Version 19.11.0.0.0

Copyright (c) 1982, 2020, Oracle.  All rights reserved.

ERROR:
ORA-28002: the password will expire within 7 days

Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> create user foo identified by foo default tablespace users quota unlimited on users;

User created.

SQL> grant create table to foo;

Grant succeeded.

SQL> create table foo.bar(c1 number);

Table created.

SQL> insert into foo.bar select rownum from dual connect by level <= 5;

5 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from foo.bar;

  COUNT(*)
----------
         5

SQL> connect system/oracle@r5/xe
ERROR:
ORA-28002: the password will expire within 7 days


Connected.
SQL> select count(*) from foo.bar;

  COUNT(*)
----------
         5

SQL>