Finding a column name from all tables
i have 85 tables in my user, i forget a column name and its table name. how to find that particular column amongst all tables i have.
hi
You can use User_tab_columns or All_tab_columns
SQL>Select Table_Name,Column_Name From user_tab_columns
where lower(table_name) like '%emp%' or
lower(column_name) like '%dept%'
Khurram Siddiqui
[email protected]
Message was edited by:
pcbyte12
Similar Messages
-
Finding the column names from a table.
I am on 10g
I would like to find out the columns of a table where there are null columns in a table.....this table contains about 300 + columns where i do not want to put where condition for all the columns
is there a way i can write a sql to find?
for a given table or the results set that i need to get, i will have same results for all the rows, so it
cant be like col1 is null on row1, but col2 is not null on row2 ...they are all identical....
example table, but it has 300 + cols
F_IND H_IND P_IND DMA_IND
N N
N N
N N
N N Thanksselect count(col1), count(col2), count(col3), ...
from your table;
The results with 0s are null throughout the table (or the table has no rows). -
How to find same field name from all tables?
Dear All,
I want to find those tables that contain a field name, say COMPANY_CODE, from all user tables. How can I do that by writing SQL?
Many thanks,
AndrewSELECT table_name
FROM user_tab_columns
WHERE column_name = 'COMPANY_CODE'Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
How to get only column names from different tables as single table columns
Hi All,
I have one requirement in which we want only column names from different tables.
for example :
I have three tables T1 ,T2, T3 having
col1 clo2 clo3 --> T1 ,
col3 col5 ,clo6 --> T2 ,
Clo6 col8 col9 --> T3
columns i want to get only all Column names from all table as single Resultset not any data from that how can i get that empty resultset
because this empty result i want to bind in datagridview(front end) as Empty resultset
Please tell me anyways to do this
Niraj SevalkarIf I understand you want an empty result set, just with metadata. SET FMTONLY do the trick:
SET FMTONLY ON
SELECT Col1, Col2, Col3, ....., Coln
FROM
T1 CROSS JOIN T2 CROSS JOIN T3
SET FMTONLY OFF
Another alternative is to include an imposible contition
SELECT Col1, Col2, Col3, ....., Coln
FROM
T1 CROSS JOIN T2 CROSS JOIN T3
WHERE 1 = 0
If you are using a SqlDataAdapter in your client application. You can use the FillSchema method. the select command may be any select statement that returns the columns you want. Under the covers FillSchema will call SET FMTONLY ON.
If you are using SqlCommand.ExecuteReader you can pass SchemaOnly to CommandBehavior argument. SET FMTONLY ON is called under the covers. Again the select command may be any select statement that returns the columns you want.
"No darás tropezón ni desatino que no te haga adelantar camino" Bernardo Balbuena -
Column names from another table
Hi All,
I have a scenario where i need to get names of a column from another table
for eg,
Table EMP
EmpNo EmpName EmpContact EmpPhone
1 xyz [email protected] 345
2 abc [email protected] 897
3 ttp [email protected] 345
The column names of this table can be configurable from some other place and its value is stored in another table like
Table Config (2 Columns)
Column_Name Value
EmpName First name
EmpContact Email
EmpPhone Mobile
Now i want to fetch the values from Emp table but with column headers that are changed and have a value in Config table.
If a column name is not there in config table then the original column name should come.
As shown below
EmpNo First name Email Mobile
1 xyz [email protected] 345
2 abc [email protected] 897
3 ttp [email protected] 345
Another eg, If EmpName is not changed and entered in second table , then i want to have the same name as the original EMP table has as shown below.
EmpNo EmpName Email Mobile
1 xyz [email protected] 345
2 abc [email protected] 897
3 ttp [email protected] 345
In other words something like this,
select empno,
EmpName as (select value from config where column_name=EmpName),
EmpContact as (select value from config where column_name=Empcontact),
EmpPhone as (select value from config where column_name=EmpPhone)
From EMP
Can some one please help me in providing a solution for this.
Edited by: 941386 on May 30, 2013 6:20 AMUnfortunately, I think this is a job for dynamic sql ...
Build your "query" first:
(note this won't work "as is", fix the syntax - but you get the idea.)
lv_str := 'select empno,
EmpName as ' || (select value from config where column_name=EmpName) || ',
EmpContact as ' || (select value from config where column_name=Empcontact) || ',
EmpPhone as ' || (select value from config where column_name=EmpPhone) || '
From EMP;';
execute immediate lv_str;Not sure if there's a better way or not.
Only other way I can think of is to leverage the way UNION [ALL] works.
So the following query:
select a, b, c from dual
union all
select d, e, f from dual
/returns data in columns "named" : "a, b, c"
Effectively renaming columns d, e, f. You just need to turn your data on edge in that first query, then throw out the rows (I don't know how to get it to work, but perhaps somebody else does?)
[edit]
another thought is create a view over top of the table, query that view, then drop the view :P
that would work nicely - avoid the dynamic SQL. shrug
[edit]
Edited by: Greg.Spall on May 30, 2013 9:37 AM -
Finding same column name from multiple database tables
I am needing to find all tables in a database that contain the same column. ie: which tables in database A have col_a in it.
Is it possible to do a sql code to qry all of this?
ThanksNo, Ignacio did not, at least, not really. ;)
The usage of ALL_TAB_COLUMNS only has info for tables which the actual user has access to.
If you need to be sure that you search each and every table, you have to use DBA_TAB_COLUMNS (or the connected user must be a super hero...).
Just wanted to point that out.
Regards,
Guido -
Same column name from different table
i have a sql query as like this : "SELECT * FROM TABLE1,TABLE2". i use oracle. both TABLE1 and TABLE2 have the same column named 'COLUMN1'. while i get rows how i know the value of COLUMN1 from which table (TABLE1 or TABLE2).
sample code snippet is above. do u help me!
while (rs.next())
value1 = rs.getString("COLUMN1");
// is value1's value from table1 or table2. how do i know this?
// i try value1 = rs.getString("TABLE1.COLUMN1"); but it doesn't work :(
....I case you don't know what an alias is, it would look something like this:
SELECT a.COLUMN1 as FirstColumn1, b.COLUMN1 as SecondColumn1 FROM FirstTable a, SecondTable b
Notice that in the FROM clause we've appended a short name for each table. You're not limited to one character, but I try to keep it simple. Now we can refer to the tables as a and b.
Because I did that I have to refer to any ambiguous columns (although it's good practice to refer to ALL columns) using the table name prefix and a period. This tells the driver which "COLUMN1" I want. Then we include as AS clause which allows us to tell the driver what we want that column name to be when it's returned to us. This is specially usefule when I have two columns in two separate tables with the same name (as you have here) or if I'm calculating data (i.e. (a.QTY * b.PRICE) as UnitPrice) that doesn't have a column name, so here I can give it one.
It's a little weird at first since you use the alias names in the select before you actually define them in the FROM clause, but you'll get use to it.
Now you retrieve FirstColumn1 and SecondColumn1 from your ResultSet, not Column1.
HTH. -
Dynamic Column Names from one table and its corresponding values from another table
I have 2 tables. First tables gives the specification if a column is required or not. we have the 2nd table with the same column name where we provide the actual values.
I want to select all the required columns from the 1st table and retrieve the values for those from the 2nd table. Both this i want to achieve in a single select statement.This wil require a dynamic Query with a Pivot
DECLARE @ColsPivot as VARCHAR(MAX);
DECLARE @Query AS VARCHAR(MAX);
1. Retreive the ID for all required field
SET @ColsPivot = (SELECT STUFF((SELECT ',' + quotename(CAST([RequirementID] as varchar(3))) FROM [dbo].[Requirement] WHERE required=1 FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)') ,1,1,''));
This will give you : [1],[2],[3],[8],[9],[14] for exemple.
2. Build your Query
SET @Query ='SELECT ClientID,'+@ColsPivot+''
FROM (
SELECT [ClientID],[RequirementID],[Value]
FROM dbo.RequirementValue
WHERE ClientID=@CliendID --Optional SP parameter
)src
PIVOT(
MAX(Value)
for [RequirementID] in ('+@ColsPivot+')
) p';
3. Exec(@Query); -
How to find out Column names from JDBC?
Hello,
How to get Oracle's Table Meta Data without firing a "SELECT" statement and using ResultSet meta data ?
Thanks,
-rajThis works for most jdbc drivers:
Connection con = ???;
DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs = dbmd.getColumns( null, null, "TABLENAME", null );Read the API: http://java.sun.com/j2se/1.4.1/docs/api/java/sql/DatabaseMetaData.html#getColumns(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String) -
JTable not seeing Column names from Abstract table model
Here is the code for the getColumnNames method
It is getting called and it is send the correct data However the Headings do not match the data.
public String getColumnName(int col){
String s_retval;
switch (m_iMode){
case PhoneTableModel.NORMALVIEW:
default:
s_retval= m_sHeadingsDefault[col];
break;
System.err.println("TableNames "+s_retval);
return s_retval;
}Why do you show the part of the code that works?!
Show how you create and display your table!
What is displayed in the headings then?
Which JDK on which platform? -
How to know primary key column name form a table name in sql query
Suppose I only know the table name. How to get its primary key column name from the table name?
ThanksViews don't have primary keys though their underlying tables might. You'd need to pick apart the view to determine where it's columns are coming from.
You can select the text of the view in question from user_views. -
How to find the column name and table name with a value
Hi All
How to find the column name and table name with "Value".
For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
Any help is highly appricatable
Thanks & Regards
Srikkanth.M2 solutions by Michaels (the latter is 11g upwards only)...
michaels> var val varchar2(5)
michaels> exec :val := 'as'
PL/SQL procedure successfully completed.
michaels> select distinct substr (:val, 1, 11) "Searchword",
substr (table_name, 1, 14) "Table",
substr (t.column_value.getstringval (), 1, 50) "Column/Value"
from cols,
table
(xmlsequence
(dbms_xmlgen.getxmltype ('select ' || column_name
|| ' from ' || table_name
|| ' where upper('
|| column_name
|| ') like upper(''%' || :val
|| '%'')'
).extract ('ROWSET/ROW/*')
) t
-- where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
order by "Table"or
SQL> select table_name,
column_name,
:search_string search_string,
result
from cols,
xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
columns result varchar2(10) path '.'
where table_name in ('EMP', 'DEPT')
TABLE_NAME COLUMN_NAME SEARCH_STRING RESULT
DEPT DNAME ES RESEARCH
DEPT DNAME ES SALES
EMP ENAME ES JONES
EMP ENAME ES JAMES
EMP JOB ES SALESMAN
EMP JOB ES SALESMAN
EMP JOB ES SALESMAN
EMP JOB ES PRESIDENT
EMP JOB ES SALESMAN
9 rows selected. -
How to find a column name in tables
Hello Guys,
I need to find a column name "company_id"
in all the tables in my schema. How can i dont this?
Is there any view that search for coulmns in a table. Please help.
Regards, ImranQuestions about the dictionary are best answered by querying DICT.
In this case
select * from dict where table_name like '%COL%'
Alternatively you can look in the Oracle reference manual for your version.
The information is online, there is little need to ask around here.
Sybrand Bakker
Senior Oracle DBA -
How to read the column name of a table from sap system using C#?
Hi!!
I am using SAP .NET connector and creating a windows application.
Now I wanna read the column name when a table name is given....
Connection is done, but I don't know the code to read the column names alone...
Can anyone help me with the code??fine!!
So if i give the table name, which the RFC_READ_TABLE function module have, will it run properly? or i wanna change all the codes in order to support RFC_READ_TABLE function module?
Because from the beginning I was using BAPI_CUSTOMER_GETLIST function, but my client requirement is to use ERP function module RFC_READ_TABLE, he didn't give any table name also..
This is my code: What I have to change in this???
ECCDestinationConfig ECCDestination = new ECCDestinationConfig();
RfcDestinationManager.RegisterDestinationConfiguration(ECCDestination);
RfcDestination rfcDest = null;
rfcDest = RfcDestinationManager.GetDestination(a);
RfcRepository repo = rfcDest.Repository;
IRfcFunction customerList = repo.CreateFunction("BAPI_CUSTOMER_GETLIST");
IRfcTable addressData = customerList.GetTable("AddressTable"));
int j = addressData.Metadata.LineType.FieldCount;
for (int i = 0; i < j; i++)
RfcElementMetadata metadata = addressData.GetElementMetadata(i);
listallcolumn.Items.Add(metadata.Name);
Message was edited by: Jeswin Rebil -
Update SAME column name in two tables from ONE query
Dear All Seniors
Please tell me is it possible to update a same column name in two tables.
I have two tables in same schema
(1)table name
pem.igp_parent
column name
igp_no.
igp_type
(2)table name
pem.igp_child
column name
igp_no.
igp_type
i want to update igp_no column in one query please tell me how it would be possible.
thanks
yassenYou want to update the data from what to what? Where is the new data coming from?
If you are trying to put the same data in two different tables, that strongly implies that you have a normalization problem that needs to be addressed.
Why do you want a single query rather than updating each table in turn? Can you join the two target tables to produce a key-preserved view?
Justin
Maybe you are looking for
-
Macbook Pro 13, i5 2011 awkwardly beeps and freezes.
I've had my Macbook Pro 13 inch i5 Sandy Bridge since it came out in March. I always noticed a bit of lag while having a few aps up. When I'd make songs on garageband it would randomly turn silver and bring up a box saying something like "Hold Down t
-
I wrote a cls that extends JTree....I have defined the root node in this class. Public class a extends JTree{ /// global variable nd constructor public void JTReader() DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); m_mod
-
Hi folks, Wonder if you can help. When I sent a clip from the timeline in fcp to shake, I opened it up successfully and applied a constant speed change in shake. The problem is that it seemed to then lose the in and out point of the clip and apply it
-
Create Relation Type ContactPartner with own Relationtype
Hi everybody, i copied the relationtype BUR001 (Contact Partner) into the Type ZUR001. Now when I create a new Contact Partner with a new bol-Object lv_fac = lv_core->get_entity_factory( 'BuilContactPerson' ). lr_builcontactperson = lv_fac->create(
-
Hi, I created a servlet & then ran it , it worked fine. After that I modified it so that it should display a different message on browser but its displaying the previous staff. Strangely even if I delete the servlet & then try to access it using a UR