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 AM
Hi,
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
Similar Messages
-
Return the column names for which the row values are not null.
Hi i m a new guy to db admin, and i need a sql script which should return column names of the particular table. and the returned column should have value (fyi - if the column has null value column name should not come in the sql o/p).
Exmple:
table name - A
s.no name mark status fee
1 aa 45 p null
2 bb 30 null paid
3 cc 35 p paid
fyi -1) if i give the table name(A) and s.no (2) the o/p should be -- name,mark.
2) if i give the tablename(A) and s.no (1) the o/p should be --- name,mark,status.
Thanks
Krishna.
Edited by: user13294228 on Jun 14, 2010 10:54 PMBTW,
The previous solution is for all values of the column, if you want a specific row, you can add it in where clause.
I mean in your example, it you look like:
SET serveroutput on;
DECLARE
l_cnt NUMBER;
l_str VARCHAR2 (255) := '';
l_table_name VARCHAR2 (255) := 'YOUR_TABLE_NAME';
l_col_cond VARCHAR2 (255) := 'S_NO';
l_val NUMBER := 1;
CURSOR c_col
IS
SELECT column_name
FROM user_tab_columns
WHERE table_name = l_table_name;
BEGIN
FOR i IN c_col
LOOP
EXECUTE IMMEDIATE 'SELECT COUNT ('
|| i.column_name
|| ') FROM '
|| l_table_name
|| ' WHERE '
|| l_col_cond
|| ' = '
|| l_val
INTO l_cnt;
l_str := l_str || CASE
WHEN l_cnt = 0
THEN ''
ELSE i.column_name
END || ',';
END LOOP;
l_str := SUBSTR (l_str, 1, LENGTH (l_str) - 1);
DBMS_OUTPUT.put_line (l_str);
END;Saad,
Edited by: S.Nayef on Jun 15, 2010 11:54 AM -
Can the column names be changes dynamically in OBIEE presentation
Hi,
Is thr any way through which I can change the column names depending on the value of a column.
the table structure is
Plan_name Character1 Character2 Character3 ....
so here according to plan_name the meaning of each character column changes. And I want to display each type of meaning on the presentation layer.
I cannot create aliases as the number of different plan name is 1200.
Any help will be appreciated.
Regards,
Akansh AgarwalHi,
I haven't tested these options, but you might. Maybe you try to supress the header for your table with data. After that, create a second table, which will be used as the header, and insert the same number of columns as the first table.
So on the 'header' table, create a conditional style (Criteria, Column Properties, Conditional Formatting), pointing to the values on shown in the first table. (You maybe need the data to be queried in both).
If this does't work, you can try to adapt the javascript shown in this blog: DELIVER BI OBIEE 11g & 10g , ODI , OBIA: OBIEE Table make a row BOLD with JAVA
And instead of making the row bold, change the value.
Hope this helps. Sorry if it does't work.
Best regards. -
Oracle 10g - Defining the column name in Non English
Hi Experts,
I have an exisitng application which is developed on Windows using ASP Technology and uses Oracle 10g 10.1.0.2.0.
The application is supported with an instance of Data Base within which multiple tablespaces are created for different clients. The application is developed in such a way that some of the tables arecreated dynamically and the columns are named using the data entered through the UI.
This application needs to be globalized now. The problem is, the column name entered through the UI can be in any language based on the client's settings and those values in turn will be used for naming the columns in the tables.
1) Can I have the column names to be named using non english characters in Oracle 10g DB? If so,
1.1) what should I do to configure the exisiting Oracle instance to support it?
1.2) To what level is that configuration possible, is it per DB instance level (or) can it be done at Tablespace level. I would like to configure each tablespace to host tables with columns defined with different languages, say for example, tablespace 1 will have tables with Japaenese column names and tablespace 2 will have tables with German column names?
2) What should I do to make my entire DB to support unicode data i.e., to accept any language strings. Currently all strings are declared as VarChar2, should I change all VarChar2 to NVarChar2 (or) is there a way to retain the VarChar2 as is and make some database wide setting?
Please note that I do not have an option of retaining the column in English as per the Business Requirement.
Envionment:
OS - Windows 2003 32 bit
Oracle 10g 10.1.0.2.0
UI forms in ASP
TIA,
Prem1. Yes, you can.
SQL> create table ÜÝÞ( ßàá number(10));
Table created.
SQL> insert into ÜÝÞ values (10);
1 row created.1.1 and 1.2 and 2. You can choose UTF as your default character set. It allows the user of non-English characters in VARCHAR columns in your whole database. It is not per tablespace.
SQL> create table ÜÝÞ( ßàá varchar2(100));
Table created.
SQL> insert into ÜÝÞ values ('âãäçìé');
1 row created. -
I have done extensive programming with the SQL Toolkit with LabVIEW versions through 6.1. My customer now wants to upgrade to Windows 7, so I am trying to upgrade to LabVIEW 2009 (my latest purchased version) using the Database Connectivity Toolkit, and the SQL Toolkit Compatibility vis. Everything seemed to be going okay with the higher level SQL operations, but I ran into trouble with the Get Column Name.vi.
The pictures below show the problem. The original SQL Toolkit connected the Prepare SQL.vi with the Get Column Name.vi with a cluster of two references, one for connection, and one for sql. The new compatibility vis have a class conflict in the wire because the Prepare SQL.vi contains a cluster with connection, and command references, but the Get Column Name.vi expects a cluster with connection and recordset references.
How do I resolve this conflict?
Thank You.
DanI've never worked with the old version of the toolkit, so I don't know how it did things, but looking inside the SQL prep VI, it only generates a command, and the the column name VI wants a recordset. I'm not super familiar with all the internals of ADO, but my understanding is that is standard - you only have the columns after you execute the command and get the recordset back. What you can apparently do here is insert the Execute Prepared SQL VI in the middle and that will return what you need.
I'm not sure why it worked before. Maybe the execute was hidden inside the prep VI or maybe you can get the column names out of the command object before execution. In general, I would recommend considering switching to the newer VIs.
Try to take over the world! -
How to change the column names in display
Hi,
I want to change the columns names and give the display names as more User friendly..
How should I acheive this in WebI reports.
Regards,
BOBHi,
the columns names are normal text fields. Just selecdt to edit your report , go to the editor panel and select the column header you want to modify. You can enter the text you want to display
Regards,
Stratos -
Hi experts,
I have used tableview in BSP . In the output it displays the column name as per the table which i have referred. I want to change the name of the column. How Should i do that.. anyone plz explain me with an example.
Thanks in Advance
Edited by: Vijay Babu Dudla on Apr 28, 2009 12:59 AMHi ,
If you want to change the column name, you can put your code following:
<htmlb:tableViewColumn columnName = " "
*title = " put the cloumn name here"*
</htmlb:tableViewColumn>
Please try.
Any doubt let me know.
Regards,
Chris Gu
Edited by: Gu Chris on Apr 28, 2009 5:26 AM
Edited by: Gu Chris on Apr 28, 2009 5:26 AM
Edited by: Gu Chris on Apr 28, 2009 5:27 AM -
Displaying the column names in a spreadsheet
Hello All,
I am downloading data from SAP into a spreadsheet using the FM MS_EXCEL_OLE_STANDARD_DAT. The data is coming fine.
But I need to display the column names too in the spreadsheet. Could anyone please tell me how to do that.
Thanks in advance.
Regards
IndrajitHi Pawan,
I am using the following piece of code.
TYPES: BEGIN OF ty_fieldname,
text(20) TYPE c,
END OF ty_fieldname.
DATA: gs_fieldname TYPE ty_fieldname.
gt_fieldname TYPE STANDARD TABLE OF ty_fieldname.
gs_fieldname-text = 'Material'.
APPEND gs_fieldname TO gt_fieldname.
gs_fieldname-text = 'Ad Size'.
APPEND gs_fieldname TO gt_fieldname.
gs_fieldname-text = 'Classification Group'.
APPEND gs_fieldname TO gt_fieldname.
gs_fieldname-text = 'Old Ceiling'.
APPEND gs_fieldname TO gt_fieldname.
gs_fieldname-text = 'Message Type'.
APPEND gs_fieldname TO gt_fieldname.
gs_fieldname-text = 'Message'.
APPEND gs_fieldname TO gt_fieldname.
CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
EXPORTING
file_name = p_file
data_sheet_name = text-014
TABLES
data_tab = gt_rate
fieldnames = gt_fieldname
EXCEPTIONS
file_not_exist = 1
filename_expected = 2
communication_error = 3
ole_object_method_error = 4
ole_object_property_error = 5
invalid_pivot_fields = 6
download_problem = 7
OTHERS = 8.
I am getting a short dump on this which says -
"Only flat, character-type data objects are supported at the argument
position "dest" for the statement
"WRITE src TO dest".
In this case, the operand "dest" has the non-character-type or deep type
"P". The current program is flagged as a Unicode program. In the Unicode
context, type X fields are seen as non-character-type, as are
structures that contain non-character-type components."
Indrajit -
Can I change the Column Name without losing data and change the sequence
Dear Experts,
I want to change the column name without changing the sequence and dont want lose the data.Oracle Version : ?
Example Based on 10g.
SQL> conn scott/tiger
Connected.
SQL> create table col1 as select * from all_objects where rownum <= 100;
Table created.
SQL> alter table col1 add constraints col1_pk_objid primary key(object_id);
Table altered.
SQL> desc col1
Name Null? Type
OWNER VARCHAR2(30)
OBJECT_NAME VARCHAR2(30)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_ID NOT NULL NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED DATE
LAST_DDL_TIME DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
SQL> alter table col1 rename column object_id to object_no;
Table altered.
SQL> desc col1;
Name Null? Type
OWNER VARCHAR2(30)
OBJECT_NAME VARCHAR2(30)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_NO NOT NULL NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED DATE
LAST_DDL_TIME DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
SQL> column column_name format a30
1 select column_name,constraint_name
2 from user_cons_columns
3 where table_name = 'COL1'
4* and owner = 'SCOTT'
COLUMN_NAME CONSTRAINT_NAME
OBJECT_NO COL1_PK_OBJID
SQL>
also go through
http://www.dizwell.com/prod/node/65
Message was edited by:
user52 -
Unable to reorder/change column names on interactive single row view
I have created an interactive report and grouped my columns to display nicely in a single row view report. However, once I initially add the columns to a group, I am unable to reorder them. I can move them up and down the list, but the changes don't save. Also, I have gone through column by column and unchecked the box that says Use Same Text for Single Row View and expanded the column name. However, the single row view still displays what is in the master report. I've tried closing out my browser completely and reopening, but I am still not seeing my changes. Any suggestions?
I also just stumbled about the "Use Same Text for Single Row View" option actually doing nothing - in Single Row View I still get the label text from "Column Heading", no matter what I enter in "Single Row View Label".
I had to adjust a column width using a span tag in the heading (as this seems to be the only way to do that - any other suggestions I found adding style information to the region header had no effect), and now that tag is displayed in the Single Row View label.
I can live with that for now, but it's not really nice.
Is this a known bug? Didn't find anything else in the forum regarding this problem so far.
Holger -
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,
GopiI 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. -
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;
} -
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 create some columns dynamically in the report designer depending upon the input selection
Post Author: ekta
CA Forum: Crystal Reports
how to create some columns dynamically in the report designer depending upon the input selection
how export this dynamic report in (pdf , xls,doc and rtf format)
report format is as below:
Element Codes
1
16
14
11
19
10
2
3
Employee nos.
Employee Name
Normal
RDO
WC
Breveavement
LWOP
Sick
Carers leave
AL
O/T 1.5
O/T 2.0
Total Hours
000004
PHAN , Hanh Huynh
68.40
7.60
76.00
000010
I , Jungue
68.40
7.60
2.00
5.00
76.00
000022
GARFINKEL , Hersch
66.30
7.60
2.10
76.00
In the above report first column and the last columns are fixed and the other columns are dynamic depending upon the input selection:
if input selection is Normal and RDO then only 2 columns w'd be created and the other 2 fixed columns.
Can anybody help me how do I design such report....
ThanksHi Developer life,
According to your description that you want to dynamically increase and decrease the numbers of the columns in the table, right?
As Jason A Long mentioned that we can use the matrix to do this and put the year field in the column group, amount fields(Numric values) in the details, add an filter to filter the data base on this column group, but if
the data in the DB not suitable to add to the matrix directly, you can use the unpivot function to turn the column name of year to a single row and then you can add it in the column group.
If there are too many columns in the column group, it will fit the page size automatically and display the extra columns in the next page.
Similar threads with details steps for your reference:
https://social.technet.microsoft.com/Forums/en-US/339965a1-8cca-41d8-83ef-c2548050799a/ssrs-dataset-column-metadata-dynamic-update?forum=sqlreportings
If your still have any problem, please try to provide us more details information, such as the data structure in the DB and the table structure you are currently designing.
Any question, please feel free to let me know.
Best Regards
Vicky Liu -
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.
Maybe you are looking for
-
How do I sync multiple iphones with one computer? My husband and I have separate itunes accounts, as well as different contacts and apps.
-
Computer sees monitor-but monitor does not see computer.
I have a MacBookPro with the older 29 pin DVI out. I own an 8.4" HD monitor for video production and want to use it for editing. I am trying to get my Marshall V-R84DP-HD monitor to see the computer and it does not recognize it. I have Mac OS X Versi
-
User migration vom SAP DB to LDAP: Problem when userId not equal to logonId
Hello I have to write a migration tool which migrates the users stored in the SAP DB to LDAP. Thereby the logon ID of the users in the SAP DB is not equal to the user ID. The migration works fine and in SAP Identity Management (IDM) everything is ok.
-
Adobe reader, error 15 reading a pdf.
Hi, i'm an italian user, recently my adobe reader makes a mistake while i read a pdf, so i can't read any document. This error is always present. I tried to uninstall adobe reader, done a system clean, reboot and then i tried to install another way a
-
Bought PSE13 but my computer runs OS X 10.7.5. Can I swap for PSE12?
I bought an downloaded Photoshop Elements 13 this morning without looking at the system requirements. I am running Mac OS X Lion 10.7.5. So basically i need to get a refund or swap to the elements package which will run on my machine. Does anyone