In Oracle, how do you search a tables' column-names? - sql

I have a large table with over 50 columns. And I would like to search those columns for a particular word. How do I do this in Oracle ?
thanks

You can use the following:
select COLUMN_NAME from ALL_TAB_COLUMNS
where TABLE_NAME='your_table_name' and COLUMN_NAME like '%whatever_word_required%';
Explanation: ALL_TAB_COLUMNS describes the columns of the tables, views, and clusters accessible to the current user. So from all the tables, since you want to search in a particular table so give your table-name in the query and specify the criteria for columns using the LIKE.
Say if your table name is "Table1" and column-name you are trying to search is "Employee", so the query becomes:
select COLUMN_NAME from ALL_TAB_COLUMNS
where TABLE_NAME='Table1' and COLUMN_NAME like '%Employee%';
For reference see the Oracle Docs

Related

how to find column names which has particular value in snowflake for a particular schema. The schema may have more than 300 tables

Basically search for all the columns which has a specific value in multiples tables in a schema
In Snowflake, there is a 'COLUMNS' view which has this information. You can use the following commands:
use <Database_Name>;
select
column_name
from
information_schema.columns
where
table_schema='<schema_name>'
and column_name like '%value%'

Is there a way to get all column names in a table for IBM Netezza? [duplicate]

Is there a query I can write to search all the column names for a particular database in Netezza?
Within the same database you can use the following query:
select *
from _v_odbc_columns1
where column_name like '%columnname%'
or a less Netezza specific query
select *
from information_schema.columns
where column_name like '%columnname%'
The important catalog views in netezza system are listed below
_V_USER: the user view gives information about the users in the netezza system.
_V_TABLE: the table view contains the list of tables created in the netezza performance system.
_V_RELATION_COLUMN: the relation column system catalog view contains the columns available in a table.
_V_TABLE_INDEX: this system catalog contains the information about the
indexes created on table. netezza does not support creating indexes on a table as of now.
_V_OBJECTS: lists the different objects like tables, view, functions etc. available in the netezza.
Example:
SELECT *
FROM _V_RELATION_COLUMN
WHERE
ATTNAME like '%GEO%' --SPECIFY COLUMN NAME
AND type = 'TABLE'
You would access something similar to an information_schema.
Column Name, %COW%', would use % as a wildcard...gathering any column that has 'COW' in the name
SELECT *
FROM _V_SYS_COLUMNS
WHERE
COLUMN_NAME like '%COW%'
AND TABLE_SCHEMA = 'DEV'
ORDER BY TABLE_NAME
;

How to get few column names among all columns in the one table with query in sql server 2008

select COLUMN_NAME
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='Submenu';
The above query gave all column names in Submenu table but I want only three column names of Submenu table.
Is there any way to get column names?
I assumed this is SQL Server, so the below queries might not work on other RDBMS's).
If your question is how to find only the column names you need (presuming you know in advance which ones those are), you would have to do something like this:
SELECT
COLUMN_NAME
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME='Submenu'
AND COLUMN_NAME IN ('Column1', 'Column2', 'Column3')
At this moment, you basically are requesting a list of any column within your table, without any restrictions whatsoever.
Alternatively, if you're looking only for the first three column names, this would work:
SELECT TOP 3
COLUMN_NAME
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME='Submenu'
ORDER BY
ORDERINAL_POSITION
In the latter case, you will have to determine how you want to sort the column names though (either by using something like ORDER BY COLUMN_NAME, in case you want them listed alphabetically, or ORDER BY ORDERINAL_POSITION in case you're trying to get them in the order they appear in the table).
If this is not what you meant, please elaborate on what you are trying to achieve.
SELECT TOP 3 COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Submenu';
As easy as that!

Select columns containing string

Is it possible to retrieve all data in columns containing a particular string? I do not have any control over the data structure and I rather shorten my code than to type everything if possible. As far as I know statements as LIKE and CONTAIN are only used to retrieve particular rows instead of columns. Lets say I have a table with column names: time, run1, run2, run3, ....., run 34, I would like to use something like:
SELECT columns FROM [Tablename] WHERE columns CONTAIN 'run';
Is this possible?
Thanks!
Use like.
In Oracle, you could do
SELECT column_name
from all_tab_columns
where table_name = 'YOUR_TABLE'
and lower(column_name) like 'run%'
In SQL Server, you could do
SELECT column_name
from information_schema.columns
where table_name = 'YOUR_TABLE_NAME'
and lower(column_name) like 'run%'

How do I list all the column names in Netezza?

Is there a query I can write to search all the column names for a particular database in Netezza?
Within the same database you can use the following query:
select *
from _v_odbc_columns1
where column_name like '%columnname%'
or a less Netezza specific query
select *
from information_schema.columns
where column_name like '%columnname%'
The important catalog views in netezza system are listed below
_V_USER: the user view gives information about the users in the netezza system.
_V_TABLE: the table view contains the list of tables created in the netezza performance system.
_V_RELATION_COLUMN: the relation column system catalog view contains the columns available in a table.
_V_TABLE_INDEX: this system catalog contains the information about the
indexes created on table. netezza does not support creating indexes on a table as of now.
_V_OBJECTS: lists the different objects like tables, view, functions etc. available in the netezza.
Example:
SELECT *
FROM _V_RELATION_COLUMN
WHERE
ATTNAME like '%GEO%' --SPECIFY COLUMN NAME
AND type = 'TABLE'
You would access something similar to an information_schema.
Column Name, %COW%', would use % as a wildcard...gathering any column that has 'COW' in the name
SELECT *
FROM _V_SYS_COLUMNS
WHERE
COLUMN_NAME like '%COW%'
AND TABLE_SCHEMA = 'DEV'
ORDER BY TABLE_NAME
;