Need help on getting the column names of Tabletype
I have a table Mapping with the following values: This Mapping table contains the table names (in Tabname) and the column names(colname) of various tables and values(ValuesTobeFilled) for the columns.
I have to insert into the tables present in the Tabname field with the values present in the ValuesTobeFilled in the columns present in the Colname field.
Note: The Mapping table need not contain all the columns of the base table. The columns that are not present can be filled with null. And this mapping table is not fixed i.e. rows can be inserted/deleted frequently.
Sample values in mapping table:
Tabname Colname ValuesTobeFilled
sample_items Eno Corresponding Expression to get the values from XML input
sample_items Ename Corresponding Expression to get the values from XML input
XXX YYY Corresponding Expression to get the values from XML input
Before filling in the actual tables, I have to store the entire data temporarily and I have used a tabletype declared as follows:
TYPE T_sample_items IS TABLE OF sample_items%ROWTYPE INDEX BY BINARY_INTEGER;
l_sample_items T_sample_items;
Where the table sample_items have the following columns:
• Eno
• Ename
• Eaddress
• Eemail
So, the tabletype should be filled as:
Eno Ename Eaddress EEmail
1 XXX - -
I have declared a cursor to select the values from mapping table and I need to fill in the ValuesTobeFilled values to the corresponding table.
CURSOR c_xpath (c_tname mapping.TABNAME%type)
IS
select * from mapping where tabname = c_tname;
CURSOR c_tables
IS
SELECT DISTINCT TABNAME FROM mapping;
FOR crsr IN c_tables
LOOP
p_tname := CRSR.TABNAME;
FOR csr IN c_xpath(p_tname)
LOOP
IF l_xml_doc.EXISTSNODE(CSR.XPATH_EXP) = 1
THEN
l_node_value := l_xml_doc.extract(CSR.XPATH_EXP).getStringVal(); -- This is the value to be stored in the corresponding column
ELSE
l_node_value := NULL;
END IF;
IF CSR.COLUMN_NAME = ‘eno’
THEN
l_sample_items(1).eno := l_node_value;
ELSIF CSR.COLUMN_NAME = ‘ename’
THEN
l_sample_items(1).name := l_node_value;
END IF;
END LOOP;
END LOOP;
And I need to eliminate hard coding while comparing the column names (in the following piece of code) as the Mapping table values are subject to insertion/deletion:
IF CSR.COLUMN_NAME = ‘eno’
THEN
l_sample_items(1).eno := l_node_value;
ELSIF CSR.COLUMN_NAME = ‘ename’
THEN
l_sample_items(1).ename := l_node_value;
END IF;
I need to insert the values directly into the tabletype without this hardcoding. Please suggest me ways to compare the mapping table values with the field (column) names of the tabletype. If it is not possible using tabletype, please suggest any other ways of fixing the problem.
Many thanks,
Gopi
I take it this isn't going to be a serious production system at the end of the day?
Storing metadata in tables for extraction and insertion of data is just wrong in so many ways. It smells heavily of Entity Attribute Value modelling, which is the most wrong way to use a relational database and is known to have major performance implications and be liable to bugs and issues. The idea that EAV modelling allows for 'generic' databases where new data items can be added flexibly later on without having to change code is usually justified with an excuse of "it means we don't have to update all our tables when we want a new column" which is easily countered with "if you're adding a single column a good relational design wouldn't require you to add it to more than one table anyway in most cases".
Just what exactly are you trying to do and why? There has to be a better way.
Similar Messages
-
Help to get the column names from ResultSet.
Hi,
I hava a ResultSet and i want the column names into a String Array.
i wrote the code to get the column names as below,
String s = "select Dept_No,Dept_Name from tb_dept";
rs = statement.executeQuery(s); // ResultSet defined before
String[] columnNames1 = null;
ResultSetMetaData meta = rs.getMetaData ( ) ;
for (int x = 1; x <= meta.getColumnCount(); x++)
columnNames1[x] = meta.getColumnName(x).toString();
but i'm getting NullPointer exception. However if i print the column names means its printing the first column name and giving NullPointer Exception at the next step.
Can anyone help me...
Thanks,
Rashmybut rs.getRow() ll give the current roe no right?
but we can move to the last row using last() method
and get the row count right?
thank you yaar.
private int getRowCount(ResultSet resultSet){
int total = 0;
try{
resultSet.afterLast();
if(resultSet.previous()) total = resultSet.getRow();
resultSet.beforeFirst();
}catch(SQLException sqle){
javax.swing.JOptionPane.showMessageDialog(null,sqle);
return total;
} -
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 -
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 -
Need help on displaying the callers name on ip phone with cme using external directory
Hello Guys,
Need help on displaying the callers name on ip phone with cme while using external directory
Thank you,
KhajaThanks for your help,
Does it 100% work with CME. We use SIP and 2ring for external directory? Thanks you. -
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 can i get the column names in CSV file.
Hi,
After execution of infospoke i can not see the column names in that file.How can i get column of respective infoprovider?
Thanks,
Gananadha LenkaHello Gana,
Actually while exporting the data using Info Spoke, we have the possibility to modify the data that we send. This is possible using transformations.
In your Info Spoke, you have a tab called Transformations.
Here you need to create an implementation and then use BADi to populate data.
Check if you can write a start routine sort of thing here and insert a new record into the internal table by hardcoding with your field headings.
Let me know if you dont know how to create transformations.
Kris... -
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.MSearching 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. -
Help to extract the Column Name depending on the row values
Hello All,
I have a table with below format
Table Name: Employees
Emp Name Monday Tuesday Wednesday Thursday Friday Saturday
John yes NULL yes yes NULL NULL
Michael NULL yes NULL yes yes NULL
Smith NULL yes yes NULL yes yes
In the above I have explicitly mentioned NULL just for better understanding.
I am trying to send an email using HTMLDB_MAIL.SEND which will have the body as following
"John is absent on Tuesday, Friday and Saturday
Michael is absent on Monday, Wednesday and Saturday
Smith is absent on Monday and Thursday"
I am trying to do this using cursor, fetching each row and matching the value with NULL. But I am not able to display the column name.
Can somebody please help me?
Regards,
RS.
Edited by: user8966924 on Jan 24, 2013 4:35 AMHi,
just use Peter's query, collect into a nested table the output and create one CLOB variable from collection to use it as a body:
create or replace function getbodyemp
return clob
is
p_body_out clob;
type tp_tbemp is table of varchar2 (100);
v_tbemp tp_tbemp;
begin
-- collect the output into a nested table
with employees as
select 'John' Emp_Name , 'yes' Monday, null Tuesday, 'yes' Wednesday, 'yes' Thursday, null Friday, null Saturday from dual union all
select 'Michael' Emp_Name , null Monday, 'yes' Tuesday, null Wednesday, 'yes' Thursday, 'yes' Friday, null Saturday from dual union all
select 'Smith' Emp_Name , null Monday, 'yes' Tuesday, 'yes' Wednesday, null Thursday, 'yes' Friday, 'yes' Saturday from dual
select
e.emp_name || ' is absent on ' ||
replace (trim( ',' from nvl2(monday,null, 'Monday')
|| nvl2(Tuesday,null, ',Tuesday')
|| nvl2(Wednesday,null, ',Wednesday')
|| nvl2(Thursday,null, ',Thursday')
|| nvl2(Friday,null, ',Friday')
|| nvl2(Saturday,null, ',Saturday')), ',', ', ') txt
bulk collect into v_tbemp
from
employees e
where
monday is null
or tuesday is null
or wednesday is null
or thursday is null
or friday is null
or saturday is null
for i IN 1 .. v_tbemp.count
loop
p_body_out := p_body_out || v_tbemp(i) || chr(10);
end loop;
return p_body_out;
end getbodyemp;
select getbodyemp() from dual;
GETBODYEMP()
John is absent on Tuesday, Friday, Saturday
Michael is absent on Monday, Wednesday, Saturday
Smith is absent on Monday, Thursday
1 row selected.Regards.
Al -
When double clicking on alv ,want to get the column name
Hello there,
I'm displaying the value of internal table in an alv using Reuse_alv_grid_display method ,using fieldcatalog.I want to know the column name when double clicking on a particular line .If the the fieldname is 'MATNR' then i want to check that column name.
If anybody have any idea plz terply me.
Thanking you neonfor that you have to use the USER_COMMAND event.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = it_fcat
TABLES
t_outtab = itab
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
FORM USER_COMMAND using ucomm type sy-ucomm
selfield type slis_selfield.
data: fieldname(30).
case ucomm.
when '&IC1'.
case selfield-fieldname.
when 'MATNR'.
message 'clicked on Matnr' type 'I'.
when 'POSNR'.
endcase.
endcase.
ENDFORM. -
Hi ,
I have a table so many constraints on so many columns. I need to know which column has which constraint plsql dev?? like below...
table_name -------- col_name ------ constraint_name_of_that_col
xxxxxx xxxxxxx xxxxxxxxxxxxxxxx
or else please let me know how can i get the corresponding col_name for a particular constraint name???My be this can give you a help:
[code]
SELECT *
FROM ALL_CONSTRAINTS
WHERE R_CONSTRAINT_NAME IN (SELECT CONSTRAINT_NAME
FROM ALL_CONSTRAINTS
WHERE TABLE_NAME = 'TABLE_NAME'
[/code] -
I need help in getting the Enduser requirment collection in Quries..!
Hello all,
I am needed to go to the client site to get the end-user requirement on quires...!they have already sent me an xls file which has all the names/Descriptions of the reports they needed in BW module by module wise. These are not the SAP BC reports. now this something i have never worked on..(Gathering the requirement)...!and then when i come back form the site (1week)..we actually need to develop the BW modeling (from the scratch)to meet this. My client already has few other rollouts in BW like..Eg Europe/Asia ,this will help me 40% only and now this is a new rollout.
I need ur help seriously to light success in my trip...
1)What kind of information should i need to gather from end-user?(tell me in detail)
2)there are around 180reports from all the modules...!and they may be or may not meet up the SAP BC.
3)how to do the modelling based on this information?
4)when i should go for Business contant Objects (Cubes/Datasources...etc)
It will be kind enough for you all....!please share your experience with me..!I need it !
Thanks to All.....!
Have a nice day. ([email protected])Hi,
For each and every report , try to get what are the restrictions to be consider and what is the logic of programming behind in the calulation of performance
indicators.
If you are able to get any relavent R/3 report take a look on that . and analyze the logic being used in the calcuations.
Let us take report for Net sales(this is billing report):
And assume the client wants to consider (total sales - value of returns) as net sales.
So here all types of billing documents(wheher it may be sold document or return) will be extracte to BW.
But in the report we need to differentiate the these billing documents on basis of Billing type or Billing category or Etc, to find out the value of net sales.After differentiating few documents come under sold documents and few comes under returns.
So to differentiate the documents we should aware of what are the characterstics are crucial.
And the logic in assigning the value of any document , each organization follows their own logic. So ask them how they are calculating them. This is important when they are following different calculation or logic for displaying values in any R/3 reports . It is important , because they will compare R/3 reports with BW reports later.
And also try to tell them that BW is For analysis reports. It is very difficult(almost not possible) some times to built a report if they are looking pure OLTP oriented report in BW. So examine each report possibilities in BW.
And donot worry for any thing . You will do it easily. Try to do the job with all your efforts.Then you will get success in that.
with rgds,
Anil Kumar Sharma .P -
Just new to this and unable to find answers
My solution
Public Function GetTableColumnNames() As Boolean
Form1.ListBox1.Items.Clear()
_MDFFileName = String.Format("{0}.mdf", _DatabaseName)
_sqlConnectionString = String.Format("Data Source=(LocalDB)\v11.0;AttachDBFileName={1};Initial Catalog={0};Integrated Security=True;", _DatabaseName, Path.Combine(_DatabaseDirectory, _MDFFileName))
Dim cn As New SqlConnection(_sqlConnectionString)
'put the table name in brackets in case it has spaces in it
Dim SQLString As String = "SELECT * FROM [" & _TableName & "]"
Try
cn.Open()
Dim cmd As New SqlCommand(SQLString, cn)
Dim rdr As SqlDataReader =
cmd.ExecuteReader(CommandBehavior.KeyInfo)
Dim tbl As DataTable = rdr.GetSchemaTable
'This shows all of the information you can access about each column.
For Each col As DataColumn In tbl.Columns
Form1.ListBox1.Items.Add(col.ColumnName)
Debug.Print("col name = " & col.ColumnName & ", type = " & col.DataType.ToString)
Next
'Get each column.
For Each row As DataRow In tbl.Rows
Form1.ListBox1.Items.Add(row("ColumnName"))
Next
rdr.Close()
Catch
MessageBox.Show("Error opening the connection to the database.")
Finally
cn.Close()
End Try
Return _Success
End Function
Maybe you are looking for
-
Ok so I have a 2009 27" IMac. I already had a OEM copy of Win 7 partitioned and running perfectly fine for months. Recently I was sent a message from Apple about needed to bring comp in to get a possible faulty HD swaped out. I bought a Time Capsule
-
Can I use a 45 Magsafe charger for a Early 2011 i7 MBP regularly?
Hello, A few weeks ago the 60w charger that came with my MBP started to fail and ended up shutting the mac down unexpectedly and preventing it to boot. Therefore, I had to take it to a tech to reinstall OS with all the inconveniences this caused me.
-
TileList Add/Remove function problems for a flex beginner
I am starting up a new project for my university course which will allow users to drag and drop icons into their own area. I wanted to use a TileList to provide the buttons for the users to select their area i.e. when a user clicks on a button in the
-
Hi, This is a pretty general, and hopefully easy question. I'm doing development for a client that needs to connect to SAP B1 externally using Java. From what I read, and I am new to SAP development and SAP in general, the SAP B1 sdk has connectors
-
When you are defining filters in CSM, is it possible to use several IPs or ranges of IPs in the "Attackers" and "Victims" tab? Thank you