How to get the column name and table name with value
Hi All
I have one difficult requirement
I have some column values and they have given some alias column names but i need to find the correct column name and table name from the database.
For example value is "SRI" and i dont know the table and exact column name so is there any possibilities to find the column name and table name for the given value
Thanks & Regards
Srikkanth.M
Searching all the database for a word...
Courtesy of michaels...
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
11g upwards
SQL> select table_name,
column_name,
:search_string search_string,
result
from (select column_name,
table_name,
'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
from cols
where table_name in ('EMP', 'DEPT')),
xmltable (str columns result varchar2(10) path '.')
TABLE_NAME COLUMN_NAME SEARCH_STRING RESULT
DEPT DNAME es RESEARCH
EMP ENAME es JAMES
EMP JOB es SALESMAN
EMP JOB es SALESMAN
4 rows selected.
Similar Messages
-
How to get the column names of the table into the Dashboard prompt
how to get the column names of the table into the Dashboard prompt
Thanks & Regards
Kishore PHey john,
My requirement is as follows
I have created a Rank for Total sales by Region wise i.e RANK(SUM(Dollars By Region)) in a pivot table.
My pivot table looks like this
COLUMN SELECTOR: TOTAL US , REGION , DISTRICT , MARKET
---------------------------------------------------- JAN 2009 FEB 2009 MAR 2009
RANK REGION DOLLARS DOLLARS DOLLARS DOLLARS
1 CENTRAL 10 20 30 40
2 SOUTHERN 10 30 30 70
3 EASTERN 20 20 20 60
4 WESTERN 10 20 30 40
When i select the District in column selector
Report has to display rank based on Total Sales by District. i.e
------------------------------------------------- JAN 2009 FEB 2009 MAR 2009
RANK DISTRICT DOLLARS DOLLARS DOLLARS DOLLARS
for this i need to change the fx of rank i.e RANK(SUM(Dollars By Region)) to RANK(SUM(Dollars By District)) and fx of Region i.e Markets.Region to Markets.District dynamically.
so , i need to capture column name of the value selected from the column selector and dynamically i need to update the fx 0f RANK & fx of region.
do you have any solution for this?
http://rapidshare.com/files/402337112/Presentation1.jpg.html
Thanks & Regards
Edited by: Kishore P on Jun 24, 2010 7:24 PM
Edited by: Kishore P on Jun 24, 2010 7:28 PM -
Reading csv file how to get the Column name
Hi,
I am trying to read a csv file and then save the data to Oracle.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:;Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=.;Extensions=csv,txn");
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("select * from filename.csv");
while(rs.next())
System.out.println(rs.getString("Num"));
My csv file looks like this:
"CHAM-23","COMPANY NAME","Test","12",20031213,15,16
Number,Environ,Envel,Date,Time
"1","2",3,"4",5
"6","7",8,"9",9
Now is there anyway using the above code I start processing the file from the second row that holds the names of the columns and skip the first row. And also can I get the name of the column using ResultSet something like:
if columnName.equals("Number")
Because I may have a csv file that could have more columns:
"CHAM-24","COMPANY NAME","Test","12",20031213,16,76
Number,Environ,Envel,Date,Time,Total,Count
"1","2","3","4","5",3,9
"6","7","8","9",9",,2
So I want to get the column name and then based on that column I do some other processing.
Once I read the value of each row I want to save the data to an Oracle Table. How do I connect to Oracle from my Application. As the database is on the server. Any help is really appreciated. ThanksThe only thing I could think of (and this is a cluj) would be to attempt to parse the first element of each row as a number. If it fails, you do not have a column name row. You are counting on the fact that you will never have a column name that is a number in the first position.
However, I agree that not always placing the headers in the same location is asking for trouble. If you have control over the file, format it how you want. If someone else has control over the file, find out why they are doing it that way. Maybe there is a "magic" number in the first row telling you where to jump.
Also, I would not use ODBC to simply parse a CSV file. If the file is formatted identically to Microsoft's format (headers in first row, all subsequent rows have same number of columns), then it's fine to take a shortcut and not write your own parser. But if the file is not adhering to that format, don't both using the M$ ODBC driver.
- Saish
"My karma ran over your dogma." - Anon -
Hi,
I am using OCCI to interact with DB through code, which means I am writing a vc++ file to interact with Data Base and execute the Stored Procedure which I am calling from the C++ Code. And also displaying the output of the Stored Procedures to the Front End. I am succeeded in this, but now I should be able to display the Column names of the output to Front End. Can any one help me on this.
Example:
Sno | Sname
------- |-------------
1 ABC
2 DEF
I am getting (1,ABC) and (2,DEF) as the output of the Stored Procedure but I need the Column names also to display. How to get them.
Thanks in Advance..:)Look at Re: exporting csv via pl/sql - select statement?
It has an example how to extract the column name from a cursor. You have to check, whether you can use DBMS_SQL.DESCRIBE_COLUMNS
Your procedure might need another out parameter, that returns the column names , e.g. as comma separated list or as varray. -
How to get the column name and table name from xml file
I have one XML file, I generated xsd file from that xml file but the problem is i dont know table name and column name. So my question is how can I retrieve the data from that xml file?
Here's an example using binary XML storage (instead of Object-Relational storage as described in the article).
begin
dbms_xmlschema.registerSchema(
schemaURL => 'my_schema.xsd'
, schemaDoc => xmltype(bfilename('TEST_DIR','my_schema.xsd'), nls_charset_id('AL32UTF8'))
, local => true
, genTypes => false
, genTables => true
, enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_CONTENTS
, options => dbms_xmlschema.REGISTER_BINARYXML
end;
genTables => true : means that a default schema-based XMLType table will be created during registration.
enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_CONTENTS : indicates that a repository resource conforming to the schema will be automatically stored in the default table.
If the schema is not annotated, the name of the default table is system-generated but derived from the root element name :
SQL> select table_name
2 from user_xml_tables
3 where xmlschema = 'my_schema.xsd'
4 and element_name = 'employee';
TABLE_NAME
employee1121_TAB
(warning : the name is case-sensitive)
To annotate the schema and control the naming, modify the content to :
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb">
<xs:element name="employee" xdb:defaultTable="EMPLOYEE_XML">
<xs:complexType>
Next step : create a resource, or just directly insert an XML document into the table.
Example of creating a resource :
declare
res boolean;
doc xmltype := xmltype(
'<employee>
<details>
<emp_id>1</emp_id>
<emp_name>SMITH</emp_name>
<emp_age>40</emp_age>
<emp_dept>10</emp_dept>
</details>
</employee>'
begin
res := dbms_xdb.CreateResource(
abspath => '/public/test.xml'
, data => doc
, schemaurl => 'my_schema.xsd'
, elem => 'employee'
end;
The resource has to be schema-based so that the default storage mechanism is triggered.
It could also be achieved if the document possesses an xsi:noNamespaceSchemaLocation attribute :
SQL> declare
2
3 res boolean;
4 doc xmltype := xmltype(
5 '<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xsi:noNamespaceSchemaLocation="my_schema.xsd">
7 <details>
8 <emp_id>1</emp_id>
9 <emp_name>SMITH</emp_name>
10 <emp_age>40</emp_age>
11 <emp_dept>10</emp_dept>
12 </details>
13 </employee>'
14 );
15
16 begin
17 res := dbms_xdb.CreateResource(
18 abspath => '/public/test.xml'
19 , data => doc
20 );
21 end;
22 /
PL/SQL procedure successfully completed
SQL> set long 5000
SQL> select * from "employee1121_TAB";
SYS_NC_ROWINFO$
<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceS
<details>
<emp_id>1</emp_id>
<emp_name>SMITH</emp_name>
<emp_age>40</emp_age>
<emp_dept>10</emp_dept>
</details>
</employee>
Then use XMLTABLE to shred the XML into relational format :
SQL> select x.*
2 from "employee1121_TAB" t
3 , xmltable('/employee/details'
4 passing t.object_value
5 columns emp_id integer path 'emp_id'
6 , emp_name varchar2(30) path 'emp_name'
7 ) x
8 ;
EMP_ID EMP_NAME
1 SMITH -
How to fix the column length and table length?
Hi Experts/Gurus,
I want to fix the column lenght so that if data exceeds it should be in the same colum. But the size of the table should not get changed.. I used the width property of both table and column. But its not working..
Regards,
YugeshHi Yugesh,
For column wrapping you can use the SET_WRAPPING of cl_salv_wd_header and the data.....you have got cell editor for that column right...then using the cell edtior reference you can get the specific cell tyep(like cl_salv_wd_text_view type check this)
this is object reference and you can use the set_wrapping of this class. using this you can get the wrapping functionality for the data also....
DATA: lr_column TYPE REF TO cl_salv_wd_column,
lr_column_header type ref to cl_salv_wd_header,
lr_editor type ref to cl_salv_wd_uie,
lr_textview type ref to cl_salv_wd_uie_text_view.
wd_this->alv_value->if_salv_wd_table_settings~set_fixed_table_layout( ABAP_TRUE ).
lr_column = wd_this->alv_value->if_salv_wd_column_settings~get_column( 'EDITION' ).
lr_column->set_width( '55' ).
lr_column_header = lr_column->get_header( ).
lr_column_header->set_wrapping( abap_true).
lr_editor = lr_column->get_cell_editor( ).
lr_textview ?= lr_editor.
lr_textview->set_wrapping( abap_true ).
Now for the column and it's data the wrapping is set...
Regards,
Lekha.
Edited by: Lekha on Nov 16, 2009 2:12 PM -
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 get the field name of an internal table during runtime?
How to get the field name of an internal table during runtime?
Hi Sudhir,
Declare and Use Get Cursor Field in Your Prm to get the field Name of the Intenal Table
Example Code:
<b> DATA: v_field(60). " Insert this code.
GET CURSOR FIELD v_field. " Insert this code.</b>
<b>CHECK v_field = 'ITAB-KUNNR'. " Insert this code. (or)
Write: v_field.</b>
Regards,
Ramganesan K. -
How to change the column name as bold in adf table
Hi,
How can I change the column name with bolder style and blue colour in adf Table?
I changed the color and font weight in af:column properties, but its effecting the data in that column but not with the column Header Text property.(i have given column name in header text).
can any one have any idea how to do this?
and I have taken panel tabbed layout and in that i'm displaying this table.
but this table has scroll beneath of it to show all columns.
but i want to display all columns (for this, page should have scroll at the bottom side).
how can I achieve this???Hi,
Add the following CSS Code to the custom skin css file that is to be created as per the suggestions above.
*af|column::column-header-cell{*
color:Blue;
font-weight:bold;
This would ensure that all the table column headers are blue in color and bolder font style through-out the application.
By the way, what version of JDeveloper are you using?
Thanks,
Navaneeth -
How to use the column names generated from Dynamic SQL
Hi,
I have a problem with Dynamic SQL.
I have written an SQL which will dynamically generate the Select statement with from and where clause in it.
But that select statement when executed will get me hundreds of rows and i want to insert each row separately into one more table.
For that i have used a ref cursor to open and insert the table.
In the select list the column names will also be as follows: COLUMN1, COLUMN2, COLUMN3,....COLUMNn
Please find below the sample code:
TYPE ref_csr IS REF CURSOR;
insert_csr ref_csr;
v_select VARCHAR2 (4000) := NULL;
v_table VARCHAR2 (4000) := NULL;
v_where VARCHAR2 (4000) := NULL;
v_ins_tab VARCHAR2 (4000) := NULL;
v_insert VARCHAR2 (4000) := NULL;
v_ins_query VARCHAR2 (4000) := NULL;
OPEN insert_csr FOR CASE
WHEN v_where IS NOT NULL
THEN 'SELECT '
|| v_select
|| ' FROM '
|| v_table
|| v_where
|| ';'
ELSE 'SELECT ' || v_select || ' FROM ' || v_table || ';'
END;
LOOP
v_ins_query :=
'INSERT INTO '
|| v_ins_tab
|| '('
|| v_insert
|| ') VALUES ('
|| How to fetch the column names here
|| ');';
EXECUTE IMMEDIATE v_ins_query;
END LOOP;
Please help me out with the above problem.
Edited by: kumar0828 on Feb 7, 2013 10:40 PM
Edited by: kumar0828 on Feb 7, 2013 10:42 PM>
I Built the statement as required but i need the column list because the first column value of each row should be inserted into one more table.
So i was asking how to fetch the column list in a ref cursor so that value can be inserted in one more table.
>
Then add a RETURNING INTO clause to the query to have Oracle return the first column values into a collection.
See the PL/SQL Language doc
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/returninginto_clause.htm#sthref2307 -
Get the column names of a query (in own plugin)
Hi,
I'm developing my first plugin. It is a region plugin where the plugin-user passes a sql query as the source that the plugin will turn into a formated report.
I found how to retreive the query result by using APEX_PLUGIN_UTIL.GET_DATA functions. Since it is an array, it is simple to cycle through the data rows. But how can i figure out
1) how many columns the query returns
2) whats the name of the columns is?
Thanks a lot in advance for any hint...
Cheers, HansHi Hans,
the package APEX_PLUGIN_UTIL provides everything you need. No need to do your own DBMS_SQL handling!
Have a look at the API documentation and the example of GET_DATA at http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_plugin_util.htm#BABFBIJD
The t_column_value_list record type is a two dimensional array defined as
type t_column_value_list is table of wwv_flow_global.vc_arr2 index by pls_integer;The first array contains an entry for each column.
l_column_value_list.COUNTcan be used to get the number of columns.
l_column_value_list(1).COUNTcan be used to get the number of rows. An example to iterate over all columns and rows:
for l_column in 1 .. l_column_value_list.count loop
for l_row in 1 .. l_column_value_list(l_column).count loop
sys.htp.p('column#=' || l_column || ' row=' || l_row || ' value: ' || l_column_value_list(l_column)(l_row));
end loop;
end loop;If you need the name of the columns and maybe the original data type and not everything converted to VARCHAR2 you have to use the more sophisticated GET_DATA2. See http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_plugin_util.htm#BABFJHAI
This function returns the record type t_column_value_list2 which is defined as
type t_value is record (
varchar2_value varchar2(32767),
number_value number,
date_value date,
timestamp_value timestamp,
timestamp_tz_value timestamp with time zone,
timestamp_ltz_value timestamp with local time zone,
interval_y2m_value interval year to month,
interval_d2s_value interval day to second,
blob_value blob,
bfile_value bfile,
clob_value clob );
type t_value_list is table of t_value index by pls_integer;
type t_column_values is record (
name varchar2(32767),
data_type varchar2(20), /* use c_data_type_* constants to compare */
value_list t_value_list );
type t_column_value_list2 is table of t_column_values index by pls_integer;Again, it's some kind of two dimensional array. The first dimensions are the columns. But this time you also get some details of the parsed column. For example:
for l_column in 1 .. l_column_value_list2.COUNT loop
sys.htp.p('Column Name: ' || l_column_value_list2(l_column).name || ' Data Type: ' || l_column_value_list2(l_column).data_type );
end loop;Will return you all the columns of the SQL statement. Using "name" and "data_type" you can get the column name and the data type. To access the values you can use
for l_column in 1 .. l_column_value_list2.COUNT loop
sys.htp.p('Column Name: ' || l_column_value_list2(l_column).name || ' Data Type: ' || l_column_value_list2(l_column).data_type );
for l_rows in 1 .. l_column_value_list2(l_column).value_list.COUNT loop
sys.htp.p(
'row=' || l_row || ' value: ' ||
apex_plugin_util.get_value_as_varchar2 (
p_data_type => l_column_value_list2(l_column).data_type,
p_value => l_column_value_list2(l_column).value_list(l_row) );
end loop;
end loop;I used apex_plugin_util.get_value_as_varchar2 to always get a VARCHAR2, independent of the actual data type of the column. If you need the original data type, use "number_value", ... of the t_value record type.
Hope that gives you a direction
Patrick
Regards
Patrick
My Blog: http://www.inside-oracle-apex.com
APEX Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolf -
Getting the column names dynamically
hi gurus,
i have list item populated with many table names from a schema.
i have grid in oracle forms 10g and i want to fill the grid with the data that should come at least four/more columns.
i want to fire the list change trigger when each time any one table name is selected/changed.
how can i get the column names dynamically
please give me the step by step process
for filling the grid..hi ,
by getting column names dynamically i am creating a record group
using this below query
SELECT COLUMN_NAME, DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = <table_name>
but when timestamp datatype is there then it is showing error cannot create group groupname
but the record group is running successful on varchar2,number,date dayatypes
if any alternative is there i mean to say without using record group then tell me or where is the problem -
How to get the Text name to pass in the parameter header in save_text
Hi,
I am trying to change the long text of operation for historical order by using the flat file.I am using the save_text to do this.I would like to know how to get the text name in order to pass the parameter header in save_text.
I went to the tcode iw62 to get the header information of the long text.300100000009200000001
i would like to know what this 1000000092 indicates and where is this value updated in the table so that i can link it thru the order no to get the link and pass it in the text_name.
can anyone help me out?
krishnanHi,
Your query is.
I went to the tcode iw62 to get the header information of the long text.300100000009200000001
i would like to know what this 1000000092 indicates
In above number
300 - Client
1000000092 - AUFPL - Routing number of operations in the order (You can fetch this from table HIVG)
00000001 - APLZL - General counter for order ( You can fetch this from table HIVG).
BR,
Vijay -
How to get the column index inside a dataTable
Hello,
before I get staked, there are multiple threads handling familiar topics to the one I'm questioning about but none gives an anwer. If there is one, I'm propably to less skilled to see it.
So here is my Problem: I've build a web-interface to a time-recording system. The hours worked on a certain project are displayed in a dataTable component which is generated out of a mySQL Query. Each entry (column/row) contains a inputText component to display and edit the specific value.
Editing one of these inputText elements now fires a valueChangeEvent which reads the new value and stores it in the database. For that cause I need to know the row- and column-index of the inputText component that fired the event.
Using the getClientId method from the valueChangeEvent I get some Information which makes it possible to calculate the row/column index. A typical clientID looks like "form_table:mainTable:0:_id14". "form_table" is the ID of the form the dataTable is in. "mainTable" is the id of the dataTable component. "0" is the row the component is in. And finally "_id14" stands for the id randomly given to the inputText component by JSF.
My Problem is now, that though I can calculate the column out of the[i] "_id14", this calculation is hardcoded. So everytime I add a component in before the dataTable, the calculation needs to be adjusted in the code.
The Questions:
- How to force a sensefull id indicating a column-index for the inputText components inside the columns of a dataTable?
- Nicer since no workaround: How to get the column-index inside the dataTable on a natural way? (e.g. out of the valueChangeEvent the specific inputText component fires)
After some investigation here on the board and on the net I know multiple ways to get the row index, (Things like component-binding and so on) but I can't find a answer on how to get the column-index.
Thanks to all answers and/or links to things my eyes missed while searching for one....then index 0 becomes index 1 and my program doesn't work properlyThe program works properly, just not as you expect it to.
As you've noticed the table gives you the flexibility to move columns around. So if you move column 0 to column 1, why would you expect to still use 0 as the index? The table manages the reordering of columns for you to make sure the data being displayed in each table column comes from the correct column in the data model.
You can manage this yourself using one of the following methods (I forget which one):
table.convertColumnIndexToModel(int viewColumnIndex)
table.convertColumnIndexToView(int modelColumnIndex)
Or, you can get data from the data model directly:
table.getModel().getValueAt(row, 0); -
How to get the VARIANT name in the program
Hi Guys,
Can somebody tell me how to get the VARIANT name in a program.
I have to perform some code with specific variant only. So I want to check in program which variant has been used to call the program.
Thanks,Hi,
Variants are stored in table VARI and VARID.
You can use RS_ALL_VARIANTS_4_1_REPORT to get all the variants for a report program.
please check out the link below it will be helpful to you
Re: Programs for a transaction variant
Hope this helps.
ashish
Maybe you are looking for
-
How can I extract an integer from a TextField?
I wrote my code for my multiplications tables program, and it compiles fine. However, when I go to run it, it throws some exceptions because of the line where I try to extract the integer from the TextField. This is my code. //July 2, 2011 //Multipli
-
Error in File IC Work Order Report_v3-3: Max processing time or Max records
Hello Friends, While running the Crystal report in Business Object Infoview, I am getting the below mentioned error when i am trying to go to the next page or trying to export all pages of report into PDF and any other format. I
-
Error when rendering a page having a dvt:lineGraph
I have a page containing a line graph with the following structure: <dvt:lineGraph id="trndgrp" tabularData="#{pageFlowScope.myBean.trendChartData}" dynamicResize="DYNAMIC_SIZE" imageFormat="HTML5" inlineStyle="border-width:0px;" threeDEffect="false"
-
Oracle 9i Database for Window download
The download button at top right does not work. Gives me junk. I tried by going to Oracle Technology Network > Software > Oracle9i Database then click on download for windows. That too do not work. Gives me junk. Oracle support guys please help me!!!
-
Account 640001 requires an assignment to a CO object
Hi, While i am using this GL 640001, the following error is coming " . This GL is assigned in OKB9 with Profit Center is mandatory (3) & cost center also assinged for this GL with several profit center. suppose if i assigned any cost center in KA