how to fetch the column name in related table in Toad? - oracle

how to fetch the column name in related table in Toad? For example,
Table Name: User;
Column name: Usr_code
Select * from User where u
after where condition, related column should be coming in drop down? send the shortcut?

Do you mean you want to know what are the columns of table User?
From Oracle metadata:
select * from all_tab_columns where table_name ='USER';
From Toad UI: You should use an alias, then shortcut for autocompletion is CTRL+space if I remember correctly. So start with the below and use kbd shortcut after you entered the last dot .:
Depending on the TOAD configuration, it can also be CTRL+.
Select * from User u where u.<ctrl>+<space>
or
Select * from User u where u.<ctrl>+<.>

To fetch the columns names from a table, I use the following:
SELECT * FROM [table name] WHERE ROWNUM < 1;

Related

Oracle.ManagedDataAccess.Client ORA-00903 invalid table name

I'm using the sqldeveloper and have one database connection with the following connection string:
MES#//localhost:1521/xepdb1
MES is the schema owner and a select statement like this shows me what I want to see:
select count(*) from site
I'm also using Visual Studio and I'm trying to connect to the database by using the Oracle.ManagedDataAccess.Client
I'm using exactly the same connection string.
The connect to the database works fine. But I'm always getting the 00903 error.
Any idea what the problem can be ?
Many thanks in advance
I've tried also something like this:
select count(*) from mes.site
If you have used quoted identifiers to create the table then you will need to use quoted identifiers (and use the same case) whenever you access the table.
For example:
CREATE TABLE MES."site" (something NUMBER);
Then you would need to use:
SELECT count(*) FROM MES."site";
or
SELECT count(*) FROM mes."site";
or
SELECT count(*) FROM mEs."site";
The MES schema name is unquoted so you can use any case (and Oracle will implicitly convert it to upper-case to look it up in the data dictionary); however, "site" is a quoted identifier and Oracle will respect the case-sensitivity of the identifier and you MUST use the correct case and the surrounding quotes.
You can see the exact case you need to use in the result of the query:
SELECT owner, table_name FROM all_tables WHERE UPPER(table_name) = 'SITE';
If the data dictionary shows that the table name is upper-case then you can use an unquoted identifier (assuming that all the other naming rules have been respected and the table name is not a reserved/keyword) otherwise you will need to use a quoted identifier.
Normally you would get the ORA-00942: table or view does not exist exception but you can get ORA-00903: invalid table name when you use a keyword for a table name:
CREATE TABLE "NUMBER" (x) AS
SELECT 1 FROM DUAL;
Then:
SELECT COUNT(*) FROM NUMBER;
Give the exception:
ORA-00903: invalid table name
And:
SELECT COUNT(*) FROM "NUMBER";
Works.
However, MES and SITE are not keywords that should trigger that.
fiddle

Selecting oracle column header

I've been browsing and to no avail, I can't find any information on how to select/show only the column header. My objective is to select only column header . I've uploaded a picture for better illustration on my objective. In the picture shown, I'm trying to only select and display the one ive highlighted in the red box.
Oracle table:
The only information I found from the net is selecting an individual column, and with that. It will display the data as well which is not my objective. my main objective is to only select column headings.
In Oracle APEX SQL Workshop you can describe a table with this command:
desc table_name
If you're using a query, you can click on the "Describe" tab below the query and above the result grid.
I had a similar requirement, so in page designer I plugged in a "Where Clause = Sysdate-1"
you can use select and null to pick columns and use alias to name them
select null AS column_name,null AS column_name
from TABLE_NAME

sqldeveloper query other users

I have a database that has say 100 other_users.
I am logged in as the database owner and I want to query a specific table in all the other users schemas.
So let's say each schema has a table called propertyvalue.
I want to find out which schemas have this value set to TRUE.
Is there a way I can run a select statement against all the other users schemas without specifically pointing to an individual schema.
Something like:
select * from otherusers.propertyvalue where value = 'TRUE', which doesn't work as I have tried that.
Thanks.
You can write a statement that will write select statements to do this
SELECT 'SELECT '||owner||'.'||table_name||'.'||column_name ||
' FROM '||owner||'.'||table_name||';'
FROM All_Tab_Cols atc
WHERE atc.column_name = 'PROPERTYVALUE';
Run this statement as a user with select privilege on the table and then run the selects that are the output.
However tables with multiple rows will return all rows. Are you expecting that there is only one row in each table?
You could also write an anonymous block that will open a cursor with the same statement and output the results to a file/table/output.

Automatically inserting column names for table in TOAD for Oracle

I am looking for a way to automatically insert column names in TOAD for Oracle to make it easier for writing queries.
Ideally, I would like to type something like the following:
select * from myTable;
Then, when I right-click on *, I would have the option to insert all known column names for that table.
Is it possible in Toad?
Press F4 on that the selected table name, and in the schema browser, select the Columns tab, then select all columns. Then drag the selection, do not copy&paste, back into the editor, and you have your comma separated column names.
select column_name || ','
from all_tab_columns
where table_name = 'SOME_TABLE'
and owner = 'SOME_OWNER'
order by column_id;
The right click on output of field names in data grid and select Export Data (to clipboard as tab delimited, don't include quoting or column headers).
Now copy/paste where u need it. Nice thing is that you can:
Use this SQL in any IDE, not just Toad
Modify output if needed, as I do in triggers to add ':old' or ':new' prefixes to each field for example, or change order.
It is also possible to generate the statement from the schema browser-> columns tab
Select the columns you want, then right click and select the 'generate statement' menu item,then select the command you want to generate (Select/Insert/Delete).
The script then gets copied to clipboard, for you to paste at your leisure.

Oracle--Error(Refereence to object_id)

SELECT object_id from dbname.tablename
This query has to be executed against oracle 11g.I get errors when i execute this.
I do a migration from sybase to oracle and in oracle this query fails.
What could be the problem. Please suggest a solution
"What could be the problem."
All sorts of things. Since you failed to state what errors you're getting, we can only guess, e.g.:
Table not found
No SELECT privilege on table
dbname not a valid schema
object_id not a column in the table
Not connected to a running oracle instance
Trying to run the statement in an environment that doesn't understand SQL
etc, etc, ...
If all you want is to check that the table exists, you could do this:
SELECT 1 FROM dba_tables WHERE owner = 'DBNAME' AND table_name = 'TABLENAME';
If you want to check that you can query the table, you could do this:
SELECT 1 FROM schemaname.tablename WHERE 1=0;
If you want to check if the table has any rows, you could do this:
SELECT 1 FROM schemaname.tablename WHERE ROWNUM <= 1;
What you will do with the result. If you only want a unique id for a row, yo can user SELECT ROWID FROM dbname.tablename!

Resources