Selecting a single column in SQL
Hi all,
I am doign a Java application at the moment and I need to select only a single column in a row of a table.
I know that I can do something like
SELECT column_name FROM table
but the fact is, I am not supposed to know the name of the column, but only its content. The row can be determined by a CUSTOMER_ID and in the row resulting from the SELECT, one of the column has "2" as content.
I would then like to know how I can build my query to only select this column, because I will then be able to retrieve the column name using the getColumnName() from the ResultSetMetadata.
I hope it was clearly said, thanks.
D.
OMG, that table isn't even in first normal form. Whoever designed the model for that application needs to get some training. If it were properly normalized, the problem would be simple, as it is you're in a mess (as I'm sure lots of code that tries to use that table is). If it were normalized, the query would look something like this ...
select status
from customer_transaction
where transaction_code = 2;Or even better, transaction code would be more meaningful and have a code table of it's own where you could refer to it with something less obscure than the number 2.
You could create a view that makes that table appear denormalized using 100 union alls but it wouldn't perform worth a damn. All I can think of is that you'll need to generate a query that looks something like this ...
select case when tan_1 = 2 then 'STATUS_TAN_1'
when tan_2 = 2 then 'STATUS_TAN_2'
when tan_3 = 2 then 'STATUS_TAN_3'
end
from tan ...Then you can build your dynamic update using that returned column name.
Similar Messages
-
Selecting rows as columns in sql table
i have sql table like
currcode currdesc mth yr rate
SGD SINGAPORE DOLLAR 01 2013 .02
SGD SINGAPORE DOLLAR 09 2013 .02 (suppose have rates only for jan and sept )
RMB CHINESE RENMINBI 01 2013 .206
RMB CHINESE RENMINBI 02 2013 .207
For each currency rates for 12 months for every year
i want to show like (user will select the year)
currcode currdesc Jan Feb Mar Apr May Jun Jul Aug
Sept oct nov Dec
SGD SINGAPORE DOLLAR .02
.02
RMB CHINESE RENMINBI .206 .207
h2007you can use either of the below
1. Using PIVOT operator
SELECT currcode,
currdesc,
Yr,
[01] AS Jan,
[02] AS Feb,
[03] AS Mar,
[11] AS Nov,
[12] AS Dec
FROM Table t
PIVOT (MAX(rate) FOR mth IN ([01],[02],[03],[04],..,[11],[12]))p
2. using classical cross tab logic
SELECT currcode,
currdesc,
yr,
MAX(CASE WHEN mth = '01' THEN rate END) AS Jan,
MAX(CASE WHEN mth = '02' THEN rate END) AS Feb,
MAX(CASE WHEN mth = '03' THEN rate END) AS Mar,
MAX(CASE WHEN mth = '11' THEN rate END) AS Nov,
MAX(CASE WHEN mth = '12' THEN rate END) AS Dec
FROM table
GROUP BY currcode,currdesc,yr
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Thank u for helping. Your 2nd solution working great. But using Pivot table giving me 2 rows,
RMB CHINESE RENMINBI
2013 NULL
NULL NULL
0.206 NULL NULL
RMB CHINESE RENMINBI
2013 NULL
NULL NULL
NULL NULL
0.207
h2007
Do you've any additional columns you've not shown in the post above?
to change NULLs to 0 use this
SELECT currcode,
currdesc,
yr,
MAX(CASE WHEN mth = '01' THEN rate ELSE 0.00 END) AS Jan,
MAX(CASE WHEN mth = '02' THEN rate ELSE 0.00 END) AS Feb,
MAX(CASE WHEN mth = '03' THEN rate ELSE 0.00 END) AS Mar,
MAX(CASE WHEN mth = '11' THEN rate ELSE 0.00 END) AS Nov,
MAX(CASE WHEN mth = '12' THEN rate ELSE 0.00 END) AS Dec
FROM table
GROUP BY currcode,currdesc,yr
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Select single column but multiple rows in JTable
Hi
I have a jTable and want to be able to select multiple rows but only in a single column.
I've set these properties which makes selection almost the way I would like it.
table1.setCellSelectionEnabled(true);
table1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);the only problem now is that the user can select multiple columns.
Is there a simple way to restrict selection to single column?
regards
abqtable.setCellSelectionEnabled(true);
table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
DefaultListSelectionModel model =
(DefaultListSelectionModel)table.getColumnModel().getSelectionModel();
model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); -
Convert Oracle SQL query to single column output
Hello All,
I need to build the query to have multiple columns in a single column with multiple rows.
select a.customer_trx_id,a.previous_customer_trx_id
from ra_customer_trx_all a
where a.customer_trx_id = :customer_trx_id
here, a.customer_trx_id and a.previous_customer_trx_id are in two columns. I need to bring them into a single column.
Say: the above output is
a.customer_trx_id a.previous_customer_trx_id
123456 87654
Need to have single column
As
123456
87654
Please do the needful.
Thanks,
AbdulHi,
Post your question in [SQL and PL/SQL|http://forums.oracle.com/forums/forum.jspa?forumID=75] forum, you would probably get a better/faster response.
Regards,
Hussein -
How many columns a sql selects
I need to find out how many columns are in a sql statement like below:
sql = "select id, decode(description,'','No decription', description), comment from my_table";
The sql string is build dynamically so I don't know it when I write the code. I need to know before I do
call rs.next(), because I need to set up the table header so I need to know how many columns the sql is selecting.
Thanks inadvance.
BotaoYou can use the interface ResultSetMetaData,below are some methods of it.
int getColumnCount()
Returns the number of columns in this ResultSet object.
String getColumnName(int column)
Get the designated column's name.
int getColumnType(int column)
Retrieves the designated column's SQL type.
for more infomation ,you can refer to JDBC Online Document. -
Hi Experts,
I need single column to be selected from a ALV table...selected in da sense to be highlighted....as it happens..by default for a row.....
I hope u understood my query...
Please help me out in this..
I know u all will surely help me...
Thks and Regards,
Runali.Hi Runali,
Get the reference to the column settings of your ALV Model. Then you can get the reference of each column by passing the column ID. There is a method set_selected_state in the column class, but that does not highlight the column as it does for a row. So what you can use is a cell design for a column that will highlight the column with a color or whatever.
lr_column = lr_column_settings->get_column( ID = id ).
lr_column->set_cell_design( preferred design ).
Hope this helps. Please award points if it solves your purpose.
Regards,
Nithya -
SQL*Loader - How to combine Flat File 3 columns and put into one single column
Receive a flat file delimited by comma. Want to combine Flat File last 3 columns and put into one single column(Table).
e.g.
Flat File
100,239,30,20,30
While inserting into table want to combine last 3 columns and insert into invoice number column.
302030It is not possible to combine the last 3 columns as those columns are seperated by commas and in the SQL Loader control file you must ve specified COMMA as an delimiter. So u better have all the columns in the table plus add one more column which holds the concatenation of the 3 columns.
Vijay -
Multiple Selection Property in Single Column Listbox
Hello All,
I have taken a Single-column list box and have enable the multiple selection property of the listbox.
In fact, i want to find out the values of the multiple rows selected in the listbox. But, i couldn't found any of the property of this listbox that can indicate the index or value of the multiple lines that are selected.
Can anybody help me to resolve this issue? What is the approach i can take to find out the multiple rows selected in the listbox?
Regards,
NishantNishant wrote:
Hello All,
I have taken a Single-column list box and have enable the multiple selection property of the listbox.
In fact, i want to find out the values of the multiple rows selected in the listbox. But, i couldn't found any of the property of this listbox that can indicate the index or value of the multiple lines that are selected.
Can anybody help me to resolve this issue? What is the approach i can take to find out the multiple rows selected in the listbox?
Regards,
Nishant
Here is an example where the value is read from a property node.
the Value becomes an array when you elect a selection mode that allows multiple selections. (and thats the reason you can't write Selection mode while the VI is running
Jeff
Attachments:
Listbox.vi 7 KB -
Using sql load insert multiple fields data into a single column in database
Hi ,
I have my log file in sun OS box something like this
=======
(07/29/2009 00:02:24.467) 367518 (07/29/2009 00:02:26.214) 949384011
(07/29/2009 00:02:26.236) 3675 (07/29/2009 00:02:28.207) 949395117
(07/29/2009 00:02:28.240) 337710 (07/29/2009 00:02:30.621) 949400864
=============
I am trying to insert the data into oracle data base as follows.
=============================
column1 : (07/29/2009 00:02:24.467)
column2 : 367518
column3 : (07/29/2009 00:02:26.214)
column4 : 949384011
===========================
Can anyone help me with the control file format?
someone suggested me the code below.
==========
LOAD DATA
INFILE 'D:\work\load.txt'
INTO TABLE sample
(col1 POSITION(02:24) char,
col2 POSITION(27:32) INTEGER EXTERNAL,
col3 POSITION(35:57) CHAR,
col4 POSITION(60:68) INTEGER EXTERNAL
===========
but this works only for the fixed length data? Please helpuser11744904 wrote:
Hi ,
I have my log file in sun OS box something like this
=======
(07/29/2009 00:02:24.467) 367518 (07/29/2009 00:02:26.214) 949384011
(07/29/2009 00:02:26.236) 3675 (07/29/2009 00:02:28.207) 949395117
(07/29/2009 00:02:28.240) 337710 (07/29/2009 00:02:30.621) 949400864
=============
I am trying to insert the data into oracle data base as follows.
=============================
column1 : (07/29/2009 00:02:24.467)
column2 : 367518
column3 : (07/29/2009 00:02:26.214)
column4 : 949384011
===========================
Can anyone help me with the control file format?
someone suggested me the code below.
==========
LOAD DATA
INFILE 'D:\work\load.txt'
INTO TABLE sample
(col1 POSITION(02:24) char,
col2 POSITION(27:32) INTEGER EXTERNAL,
col3 POSITION(35:57) CHAR,
col4 POSITION(60:68) INTEGER EXTERNAL
===========
but this works only for the fixed length data? Please helpIs the requirement to load all data in a single column or multiple columns? The thread subject and body are conflicting. -
How To Concatenate Column Values from Multiple Rows into a Single Column?
How do I create a SQL query that will concatenate column values from multiple rows into a single column?
Last First Code
Lesand Danny 1
Lesand Danny 2
Lesand Danny 3
Benedi Eric 7
Benedi Eric 14
Result should look like:
Last First Codes
Lesand Danny 1,2,3
Benedi Eric 7,14
Thanks,
David JohnsonStarting with Oracle 9i
select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
from
(select last, first, code, row_number() over(partition by last, first order by code) rn
from a)
connect by last = prior last and first = prior first and prior rn = rn -1
start with rn = 1
group by last, first
LAST FIRST CODES
Lesand Danny 1,2,3
Benedi Eric 7,14Regards
Dmytro -
How to display two or more links in a single column
Hi,
Is there a way to display two links in a single column in a sql query report . I am able to specify one but I am not able to add links to the same column . I want to take the same column id and redirect the user to different pages based on the values selected .
ThanksThere is no way to this declaratively that I know of. Some alternatives...
1. Put the conditional branching logic in the report SQL itself. e.g. case when ... then '< a href=..' else '< a href=...' end and make sure the column display type is Standard Report column
2. Have the declarative column link go to a dummy/intermediate page and setup On Load: Before-Header branches on that page to redirect to the desired page based on the item value(s) passed in to the intermediate page. -
How to use single column in a group by clause
hi frs
i hve used sum function in a sql how to use a single column in a query.
for ex
select sum(sal),ename,job,deptno,empno from emp
group by deptnowhether its possible to use single column in a group by class.
i want like this because in my custom report i need it. Report query has more than 30 column so its not possible to use 30 columns in a group by.
pls help.
Thanks
RajeshMaybe something like this -
Select ename, job, deptno, empno, sal, col1, col2, col3, col4 ......, coln
From
Select SUM(sal) sal, deptno deptno_i
From Emp
Group By deptno
,Emp
Where deptno = deptno_i
Shailender Mehta -
Merge two column value in single column
Team,
I have a requirement where in I need to merge 2 column values in a single column.
ex. I have Percent_complete column in my table. and my table has only one record.
I need to query such that I need to store the values of percent_complete and (100- percent_complete) values in a single column.
ex
Percent complete has 30 value.
I need to select 30 and 70(100-30) both in a single column.
Thanks,SQL> select *
2 from tbl
3 /
PERCENT_COMPLETE
30
SQL> select abs(grouping(1) * 100 - max(percent_complete)) percent_complete
2 from tbl
3 group by rollup(1)
4 /
PERCENT_COMPLETE
30
70
SQL> select nvl(percent_complete,100 - max(percent_complete)) percent_complete
2 from tbl
3 group by rollup(percent_complete)
4 /
PERCENT_COMPLETE
30
70
SQL>
SY. -
How to identify missing records in a single-column table?
How to identify missing records in a single-column table ?
Column consists of numbers in a ordered manner but the some numbers are deleted from the table in random manner and need to identify those rows.Something like:
WITH t AS (
SELECT 1 ID FROM DUAL UNION ALL
SELECT 2 ID FROM DUAL UNION ALL
SELECT 3 ID FROM DUAL UNION ALL
SELECT 5 ID FROM DUAL UNION ALL
SELECT 8 ID FROM DUAL UNION ALL
SELECT 10 ID FROM DUAL UNION ALL
SELECT 11 ID FROM DUAL
-- end of on-the-fly data sample
SELECT '[' || (id + 1) || ' - ' || (next_id - 1) || ']' gap
FROM (
SELECT id,
lead(id,1,id + 1) over(order by id) next_id
FROM t
where id != next_id - 1
GAP
[4 - 4]
[6 - 7]
[9 - 9]
SQL> SY.
P.S. I assume sequence lower and upper limits are always present, otherwise query needs a little adjustment. -
Getting parent-child data from a single column in a table
Hi,
I have a parent-child data in a column.
Eg:
0
00
01
010
011
1
10
11
These values are present in the single column itself. My need is to get the parent values for the given child value.
For eg: If I am giving the input as 011, the query should return all its parents, i.e. 01 and 0
Could you please give me any inputs on this?
Thanks,
GVFrank Kulash wrote:
Assuming that each child's id is formed by adding exactly one character to the end of its parent's id:
SELECT id
FROM table_x
START WITH id = :target_id
CONNECT BY PRIOR id LIKE id || '_';
Small tweak to yours Frank if it's just the parents that need identifying...
SQL> ed
Wrote file afiedt.buf
1 with t as (select '0' as x from dual union all
2 select '00' from dual union all
3 select '01' from dual union all
4 select '010' from dual union all
5 select '011' from dual union all
6 select '1' from dual union all
7 select '10' from dual union all
8 select '11' from dual)
9 -- end of test data
10 SELECT x
11 FROM t, (select '&required' as req from dual) req
12 WHERE x != req.req
13 START WITH x = req.req
14* CONNECT BY PRIOR x LIKE x || '_'
SQL> /
Enter value for required: 011
old 11: FROM t, (select '&required' as req from dual) req
new 11: FROM t, (select '011' as req from dual) req
X
01
0
SQL> /
Enter value for required: 11
old 11: FROM t, (select '&required' as req from dual) req
new 11: FROM t, (select '11' as req from dual) req
X
1
SQL>
Maybe you are looking for
-
Dear Team, During archiving log backup , I am faccing the problem. Job started Step 001 started (program RSDBAJOB, variant &0000000000008, user ID BASIS) Execute logical command BRARCHIVE On host sapprd Parameters:-u / -jid LOG__20090729213120 -c for
-
"untitled DVD' that won't go away!
Recently I burned CDs and DVDs. Now there are to folders "untitled DVD" and "Utitled CD" in my finder window and I can't make them go away! help? kt
-
All, Has any one implemented webutil on Solaris 64 bit server. We are having issues with it in both Development Suite and Forms 10g environment. Thanks Akshaya
-
Dear Experts, kindly help me getting the PS acitvity updated once there is a status change in Document management system. In this cse what we want is that either a pop up comes on the screen at the time a document is released in DMS so that the activ
-
Right and Left sound is reversed
As the title says, my right headphone plays left sound, and vice versa. I looked through some of the pages for relevant info but found none that I could use. Do anyone of you know how to switch them over. (and no, i have no ability to change the chor