can not see table in tree view of sql developer - oracle

I can not see table in tree view of sql developer
but I can execute select statement for that table.
I logged in with 'carspgm' user and I executed below query then i can see the data but when I expand the carsdb table tree I can not see this below table.
I want to find out why I can not see and I want to find what all trigger are there on this table
select * from carsdb.COMAPNY_STATE
Please Help

Try selecting the "Other USers" treenode, and you should see "CARSDB" schema under which you will see objects owned by that user/schema.

check with the following
select * from user_tables where table_name='COMAPNY_STATE';
--the above query will return the data of table
desc COMAPNY_STATE;
--the above statement will describes the tables with columns and their data typed
If the first statement was executed then return a row then table was created.
If second statement was executed and table was exist.

Related

Oracle : table always "exist" after drop table

I'm using Oracle and I have a strange thing.
I dropped a table using :
drop table t_my_table, and committed.
But when I launch select * from t_my_table, it shows the data, as if the table is not dropped.
I tried disconnecting and reconnecting, it stills shows the data when I select.
And when I once again try with :
drop table t_my_table, it tells me that this table does not exist.
But if I run select again, the data is always there.
How is this possible ?
Thank you.
You mean this case?
create view t_my_table as
select 'I''m here' as txt from dual;
drop table t_my_table;
ORA-00942: table or view does not exist
But
select * from t_my_table;
TXT
--------
I'm here
solution of the most probably cause
select OBJECT_TYPE from user_objects where object_name = 'T_MY_TABLE';
OBJECT_TYPE
-------------------
VIEW
You defined a view (or other object type other than TABLE), that can't be dropped with DROP TABLE, but can be selected.
Simple check in USER_OBJECTS the OBJECT_TYPE. You may alternatively see also SYNONYM as proposed in other answer.
Note that it is not a MATERIALIZED VIEW as if you try to drop a Materialized View with DROP TABLE a different error message is raised:
ORA-12083: must use DROP MATERIALIZED VIEW to drop T_MY_TABLE
What does this return?
select * from all_synonyms
where synonym_name = 'T_MY_TABLE';
I suspect there is a synonym T_MY_TABLE that points to a table in a different schema.
drop table t_my_table purge;
Specify PURGE if you want to drop the table and release the space associated with it in a single step. If you specify PURGE, then the database does not place the table and its dependent objects into the recycle bin.
...
Using this clause is equivalent to first dropping the table and then purging it from the recycle bin. This clause lets you save one step in the process. It also provides enhanced security if you want to prevent sensitive material from appearing in the recycle bin.
Probably something different is happening.
Normal case would be:
SQL> create table t1 as select 1 a from dual;
Table T1 created.
SQL> drop table t1;
Table T1 dropped.
SQL> select * from t1;
Error starting at line : 22 in command -
select * from t1
Error at Command Line : 22 Column : 20
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
So what was the message after the drop table?
Is t_my_table really a table?
Try select * from all_objects where lower(object_name) = 't_my_table'

SQLDeveloper Trigger Error report - ORA-00942: table or view does not exist

I put this code into SQL Developer's Worksheet:
CREATE TRIGGER T_testDSNa
before INSERT
on testDSNa
referencing new as new
for each ROW
BEGIN
SELECT S_testDSN.nextval INTO :NEW.SYSID FROM dual;
END;
I get this:
Error report -
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Would anyone know why? This has worked for 3 previous tables until I tried to run the DDL to create a 4th. Alternatively, is there a better way to set up an autoincrementing PK?
The problem was lack of schema. Oracle Definition of a schema :
Collection of database objects, including logical structures such as
tables, views, sequences, stored procedures, synonyms, indexes,
clusters, and database links. A schema has the name of the user who
controls it.
If you want to know the objects accessible without alias. You have to look on [USER_OBJECTS]. Which describes the relational objects owned by the current user :
SELECT
OBJECT_NAME
, OBJECT_TYPE
, LAST_DDL_TIME
FROM USER_OBJECTS;
If you want to know the objects accessible to the current user :
SELECT
OWNER
, OBJECT_NAME
, OBJECT_TYPE
, LAST_DDL_TIME
FROM ALL_OBJECTS;
In your case to see your objects in the list of available tables you need:
SELECT * FROM ALL_OBJECTS WHERE OWNER = 'USER';
You can also alter the session to avoid alias :
ALTER SESSION SET current_schema = User;
For priviliges/ roles views you can look at :
SELECT * FROM USER_SYS_PRIVS;
SELECT * FROM USER_ROLE_PRIVS;
The last method but not the most secure to avoid alias. Is to log on with a user that has the same name as the schema.
Hoping that it can help
I was getting the same issue.
Solution: What I observed that my table which I created was surrounded by double quotes, which made it case sensitive.
So for each time I refer to my table, I need to surround it by double quotes.
CREATE TRIGGER T_testDSNa
before INSERT
on "testDSNa"
referencing new as new
for each ROW
BEGIN
SELECT S_testDSN.nextval INTO :NEW.SYSID FROM dual;
END;
refer this link: What exactly do quotation marks around the table name do?

Query columns names from a table from another user

Sounds pretty easy query the column names from a table, right? Indeed there is a answer to this question How can I get column names from a table in Oracle?
The main issue is that the table belongs to another user. My user is just for integration and I don't have any database privileges.
So I'm able to do some query like: SELECT * FROM anotherUser.THE_TABLE;
But something like SELECT * FROM USER_TAB_COLUMNS return no rows.
Perhaps I can create queries over all_tab_columns, Are there another faster options without procedures?
*It´s a oracle database!
SELECT *
FROM ALL_TAB_COLUMNS
WHERE OWNER='ANOTHERUSER'
AND TABLE_NAME='THE_TABLE';
Should get you there if you have privileges on the table.

Need to update an Oracle view, but the base table doesn't exist

I'm trying to make an extremely minor change to a view on an oracle database, but what's confusing me is that the base table/view for the view I want to change doesn't seem to exist.
First I did this:
select text from all_views where view_name='(view name)';
and got the view text, which of course was something like this:
SELECT
(fields)
FROM (table)
Trying to run this query on its own returns an error saying that this table or view does not exist. Searching through the lists of table names and views on the all_ tables returns nothing. Creating a new view with the same source select statement tells me I can't make it because the table or view doesn't exist. Now, this is a production database, so this should work because I can use the existing view just fine. I don't have much experience with oracle databases, so I'm probably missing something here.
I'm betting the view is in another schema. Does this return the same as your first query:
select text from all_views where view_name='(view name)' and owner = user;
If that returns no rows, then you need to find the view's owner:
select owner from all_views where view_name = '(view_name)';
And change your SQL to
select (fields) from (view_owner).(table);
You can create a view even if there doesn't exist base table by "FORCE" option("NO FORCE" is
the default) by this way:
CREATE FORCE VIEW test_view AS
SELECT c1, c2 FROM test_table; -- table, which does not exist yet.
Since we did not use the FORCE option, the view was not created.However, trying to access the
view gives an error, because the table TEST_TABLE does not exist yet.
Wow, nevermind. They weren't even asking me to do this. I missed that part in the original email.
By using "FORCE" we can also create a view by dual table(default table for oracle).
1-Example:create force view v1 as select a,b,c from dual;
Warning:view created with compilation error.
2-Example:create force view v2 as select *from dual;
Answer:view created.
Your should use force keyword..
create force view my_view as elect column1 from table_test -- table is not exists here..

What happens to an existing DB2 view, if the table is dropped?

If we have created a view on an existing DB2 table and then drop the table. What will happen to the view ?
The view becomes invalid/inoperative. Attempts to select from it will fail.
To try it:
create table TEST_TABLE (
TEST_COL INTEGER
);
INSERT INTO TEST_TABLE VALUES(1);
SELECT * FROM TEST_TABLE;
create view TEST_VIEW AS
SELECT * FROM TEST_TABLE;
SELECT * FROM TEST_VIEW;
DROP TABLE TEST_TABLE;
SELECT * FROM TEST_VIEW;
The last statement gives the error:
[IBM][CLI Driver][DB2/NT] SQL0575N View or materialized query table
"TEST_VIEW" cannot be used because it has been marked inoperative.
SQLSTATE=51024
When a view is invalidated, as shown in the above example, DB2 will allow you to recreate that view without dropping it first. This makes it possible to re-run your view DDL files (or simply dump the TEXT column of SYSCAT.VIEWS and execute that).
Nothing happened. Just don't use that view. You can recreate the table again to use the view again later.
It becomes inoperative.
Same information can be found using following query:
SELECT viewscheama,viewname,valid FROM syscat.views
.
For the perticular view , if the "Valid" column has any value apart of 'Y' , then the view will be inoperative.

Resources