Selecting a column in a table according to a value
Hi,
I am stuck with a little problem here. I need to fill a column according to a value. I have an xml that will looks like this to make it simple. (Don't worry, I am not managing the status of a stock of Candy ;-))
I have to build in rtf.
<?xml version="1.0" encoding="UTF-8" ?>
- <ROWSET>
- <ROW>
<CANDY>Bubble gum</CANDY>
<SUGAR>SUGARFREE</SUGAR>
</ROW>
- <ROW>
<CANDY>Cinnamon candy</CANDY>
<SUGAR>SUGARFREE</SUGAR>
</ROW>
- <ROW>
<CANDY>Gummy candy</CANDY>
<SUGAR>SUGAR</SUGAR>
</ROW>
</ROWSET>
I have a table with two columns. I need to put on the left column the "SUGARFREE" candy and on the right the "SUGAR" candy.
Is there any condition to make this happen. Or do I have to make two table of one column next to the other and adapt a if condition in the for-each.
best regards,
Olivier
Have the same table structure with two columns and have for-each with conditions in each of your columns.
Say in column1: <?for-each:ROW[SUGAR='SUGARFREE']?>text to print <?end for-each?>
column2: <?for-each:ROW[SUGAR='SUGAR']?>text to print <?end for-each?>
Hope this is what you want
Similar Messages
-
How to get the selected rows & columns in the table?
hi everybody,
In my application the table is kept inside the event structure.I select the cells in the table (using mouse) on running time.How to get the selected number of rows & columns in that table?Hello,
You can fill selected values of the table by writing to it or the corresponding property using a property node - the table is just a 2D array of strings. I think for your "disable" question you are referring to the shortcut menu (when you right click). If you are using LabVIEW 8.x, you can edit or disable that shortcut menu - just right click on your table at edit time and choose Advanced >> Run-Time Shortcut Menu.
Best Regards,
JLS
Best,
JLS
Sixclear -
Selecting only columns from a table
Could someone help me with a SQL query to select all the columns in a table as an array?
Hello
if you are on 9i upward, you can define a pl/sql table of the rowtype and use bulk collect to populate that table, otherwise, you can create separate array types for each column:
create table dt_test_tab (id number, col1 varchar2(10));
insert into dt_test_tab values(1, 'X');
insert into dt_test_tab values(2, 'X');
insert into dt_test_tab values(3, 'X');
insert into dt_test_tab values(4, 'X');
insert into dt_test_tab values(5, 'X');
commit;
declare
type tt_TestTab is table of dt_test_tab%rowtype index by binary_integer;
type tt_TestTabid IS TABLE OF dt_test_tab.id%type index by binary_integer;
type tt_TestTabcol1 IS TABLE OF dt_test_tab.col1%type index by binary_integer;
lt_TestTab tt_TestTab;
lt_Id tt_TestTabId;
lt_col1 tt_TestTabcol1;
begin
--use the rowtype array
select
id,
col1
BULK COLLECT INTO
lt_testtab
FROM
dt_test_tab;
--use the individual column arrays
select
id,
col1
BULK COLLECT INTO
lt_id,
lt_col1
FROM
dt_test_tab;
dbms_output.put_line('loop through the rowtype array');
FOR x in lt_TestTab.FIRST..lt_TestTab.LAST LOOP
dbms_output.put_line(to_char(lt_TestTab(x).id)||to_char(lt_TestTab(x).col1));
end loop;
dbms_output.put_line('loop through the two column arrays');
FOR x in lt_Id.FIRST..lt_Id.LAST LOOP
dbms_output.put_line(to_char(lt_Id(x))||to_char(lt_Col1(x)));
end loop;
END; -
Re: Getting the current selected Row & column in adf table
Hi,
Our requirement is we have to retrieve both the current row and column in adf table.
We can retrieve the current row in the backing bean like
ViewObject view = getViewObject();
view.getCurrentRow();
Is it possible to retrieve selected column id or column header text as we are getting for row?
please give some sample.
Thanks,
Vijay.
Edited by: Vijayakumar Palanisamy on Jun 23, 2011 2:23 AMHi John
My exact requirement,
1. We have collection of records in adf table
2. Each cell in the row has commandImageLink (Like adding approver, edit approver, delete etc)
Currently it’s working fine for me in the commandImageLink listener, but the problem is table is refreshed 2 time,
while selecting a record and commandImageLink is clicked, I have to avoid 2 times refreshing,
If it’s possible to identify a particular cell in the row selection, I can avoid the image link listener.
we are using Jdeveloper11.1.1.4.0
Please suggest.
Thanks,
Vijay -
Select sql running very long when made to select many columns from a table
Hi,
I am using an Oracle DB 10g. I have a table with 250 columns and I need to select 200 columns out of them. The table holds around 0.1 million rows. But when I run the select sql it takes 15 mins to return .1 million rows. Where as if I select only 10 or 15 columns the sql runs in less than a minute returning same number of rows. My sql looks like below:
select p.col1,p.col2,.......,p.col200
from table Parent p;
The table also has a Primary key Index but it does not seem to be using it even when I forced an Index hint. Could you pls help?961796 wrote:
I am using an Oracle DB 10g. I have a table with 250 columns and I need to select 200 columns out of them. The table holds around 0.1 million rows. But when I run the select sql it takes 15 mins to return .1 million rows. Where as if I select only 10 or 15 columns the sql runs in less than a minute returning same number of rows. My sql looks like below:
As Sven points out, it is likely that most of your time is network (and client) time. You are sending 20 times as much data (based on column counts, at any rate) across the network, and concerned that it's taking 15 times as long.
If you're testing from SQL*Plus then setting the arraysize to a value larger than the default might help.
If you have control over the SQL*Net settings then you may get some benefit by adjusting the SDU sizes at both ends of the link.
If you have control over the tcp configuration (transmit and receive buffer sizes) then you may get some benefit by adjusting these.
Simple test, by the way, if you're on SQL*Plus
set autotrace traceonly statistics
select ...This will dump your data in the bit bucket as it arrives giving you
a) the database time plus network time
b) some statistics including the volume of data down the network and the number of network round-trips that Oracle saw.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
Author: <b><em>Oracle Core</em></b> -
Select the column details for table in one column as varchar2(32000)
Oracle Version: ORACLE 10G R 2
Problem : Select the column details for some tables and want to store the same in VARCHAR2(32000) separated by ||
Example:
TABLE_NAME COLUMN_NAME DATA_TYPE
EMP EMPNO NUMBER
EMP ENAME VARCHAR2
EMP JOB VARCHAR2
EMP MGR NUMBER
EMP HIREDATE DATE
EMP SAL NUMBER
EMP COMM NUMBER
EMP DEPTNO NUMBER
EMP RN NUMBER
Want to store
COLUMNS (empno||ename||job||mgr||hiredate||sal||comm||deptno||rn);SQL> var cur refcursor
SQL> declare
ctx number;
begin
ctx := dbms_xmlgen.newcontext('select * from emp');
dbms_xmlgen.setNullHandling(ctx, dbms_xmlgen.empty_tag);
open :cur for select * from xmltable('for $i in ROW return string-join($i/*, "||")' passing dbms_xmlgen.getxmltype(ctx).extract('ROWSET/ROW'));
end;
PL/SQL procedure successfully completed.
SQL> print cur
COLUMN_VALUE
7369||SMITH||CLERK||7902||17.12.1980 00:00:00||800||||20
7499||ALLEN||SALESMAN||7698||20.02.1981 00:00:00||1600||300||30
7521||WARD||SALESMAN||7698||22.02.1981 00:00:00||1250||500||30
7566||JONES||MANAGER||7839||02.04.1981 00:00:00||2975||||20
7654||MARTIN||SALESMAN||7698||28.09.1981 00:00:00||1250||1400||30
7698||BLAKE||MANAGER||7839||01.05.1981 00:00:00||2850||||30
7782||CLARK||MANAGER||7839||09.06.1981 00:00:00||2450||||10
7788||SCOTT||ANALYST||7566||19.04.1987 00:00:00||3000||||20
7839||KING||PRESIDENT||||17.11.1981 00:00:00||5000||||10
7844||TURNER||SALESMAN||7698||08.09.1981 00:00:00||1500||0||30
7876||ADAMS||CLERK||7788||23.05.1987 00:00:00||1100||||20
7900||JAMES||CLERK||7698||03.12.1981 00:00:00||950||||30
7902||FORD||ANALYST||7566||03.12.1981 00:00:00||3000||||20
7934||MILLER||CLERK||7782||23.01.1982 00:00:00||1300||||10
14 rows selected. -
Create a new column in a table that compares the value of one column with its previous value
The DDL:
DECLARE
@T TABLE
IDNO
int,
name
varchar(40),
[Date]
datetime2,
Price1
float,
Price2
float
DECLARE
@K TABLE
IDNO
int,
name
varchar(40),
[Date]
datetime2,
Price1
float,
Price2
float
INSERT
INTO @T
VALUES(22,'C_V_Harris','2014-01-02 10:23:49.0000000',
23.335,
23.347)
INSERT
INTO @T
VALUES(21,'C_V_Harris','2014-01-02 10:05:13.0000000',
23.357,
23.369)
INSERT
INTO @T
VALUES(20,'C_V_Harris','2014-01-02 09:56:15.0000000',
23.364,
23.377)
INSERT
INTO @T
VALUES(19,'C_V_Harris','2014-01-02 09:45:26.0000000',
23.351,
23.367)
INSERT
INTO @T
VALUES(18,'C_V_Harris','2014-01-02 09:43:20.0000000',
23.380,
23.396)
INSERT
INTO @T
VALUES(17,'C_V_Harris','2014-01-02 09:34:28.0000000',
23.455,
23.468)
INSERT
INTO @T
VALUES(16,'C_V_Harris','2014-01-02 09:30:37.0000000',
23.474,
23.486)
INSERT
INTO @T
VALUES(15,'C_V_Harris','2014-01-02 09:18:12.0000000',
23.419,
23.431)
INSERT
INTO @T
VALUES(14,'C_V_Harris','2014-01-02 09:16:06.0000000',
23.360,
23.374)
INSERT
INTO @K
SELECT
ROW_NUMBER()
OVER (ORDER
by IDNO)
AS RN,*
FROM
@T
SELECT
* FROM
@K
--not working:
SELECT
a.RN,a.Price2
FROM
@K a
INNER
JOIN @K
b
ON
a.RN=b.RN-1
WHERE
a.Price2>b.Price2
I need to create a view with a column (say 'Comp' below) that compares the value of each row in Price2 with the previous Price2 row, and it is greater then +1, the
same 0, and less -1.
The processed table should be:
IDNO
name
Date
Price1
Price2
Comp
22
C_V_Harris
1/2/2014 10:23:49
23.335
23.347
0
21
C_V_Harris
1/2/2014 10:05:13
23.357
23.369
1
20
C_V_Harris
1/2/2014 9:56:15
23.364
23.377
1
19
C_V_Harris
1/2/2014 9:45:26
23.351
23.367
-1
18
C_V_Harris
1/2/2014 9:43:20
23.38
23.396
1
17
C_V_Harris
1/2/2014 9:34:28
23.455
23.468
1
16
C_V_Harris
1/2/2014 9:30:37
23.474
23.486
1
15
C_V_Harris
1/2/2014 9:18:12
23.419
23.431
-1
14
C_V_Harris
1/2/2014 9:16:06
23.36
23.374
-1
How can I structure the statement to get (the most recent - order by date ) result for Comp?Satheesh Variath, I just had to make some corrections from your script to get the correct answer:
CREATE
VIEW vw_Comp
AS
SELECT
TOP 1 t.IDNO,t.name,t.[Date],t.Price1,t.Price2,
CASE
WHEN t.Price2
> LAG(Price2,1)
OVER (PARTITION
BY name
ORDER BY IDNO)
THEN 1
WHEN t.Price2
< LAG(Price2,1)
OVER (PARTITION
BY name
ORDER BY IDNo)
THEN -1
ELSE 0
END
AS Comp
FROM
@T t
ORDER
BY DATE
DESC
The adjustments: the selection of the most recent comparison (Top 1) and the use of the function LAG (instead of LEAD) to get the previous value of the column. -
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. -
Select LONG column from Remote table
Hi to all.
I have the following problem: I can't select a LONG column from remote database, when there are Join operation in the query. Example:
SELECT long_column FROM remote_table@DB
-> that's OK, but:
SELECT long_column FROM remote_table@DB INNER JOIN remote_table2@DB ON ...
-> returns: "ORA-00997: Illegal use of LONG datatype"
I cannot even perform (because there a LONG column in the joined table):
SELECT nonlong_column FROM remote_table@DB INNER JOIN remote_table2@DB ON ...
That's very strange to me because:
SELECT long_column FROM local_table INNER JOIN local_table2 ON ...
-> is OK!
Can someone help me to SELECT a long column from remote in SELECT query with JOIN clause!
Thanks a lot!Hi
"Distributed queries are currently subject to the restriction that all tables locked by a FOR UPDATE clause and all tables with LONG columns selected by the query must be located on the same database. " by otn docs.
I have no idea.
Ott Karesz
http://www.trendo-kft.hu -
Selecting a column from a table conditionally
I'm trying this select statement (example):
select np.phone_number from name_phone np, reservation_general_view rgv
where rgv.resort='HVILLA'
In this table there is a column called "phone_type" and I only want my column to display values that are associated to the column when the "phone_type" = 'EMAIL'
I tried this:
select np.phone_number(select np.phone_number from name_phone np where np.phone_type='EMAIL')
from name_phone np, reservation_general_view rgv
where rgv.resort='HVILLA'
This doesn't seem to work...can someone tell me how to do that?
Message was edited by:
JonnyOperaselect phone_number from name_phone
where resort='HVILLA'
and phone_type='EMAIL' -
Selecting date column from a table
hi
I have a problem that looks wierd for me.
I have a table called blog_post which has a date field called publish_date
I have done this first.
alter session set nls_date_format='dd/mm/yyyy';
then
SQL> select publish_date from blog_post;
PUBLISH_DA
09/07/2007
02/07/2007
02/07/2007
02/07/2007
09/07/2007
now the wierd thing is that when i am selectin the same date it is not returning anything
SQL> select publish_date from blog_post where publish_date='09/07/2007';
no rows selected
Thanks for any help.
GaneshI don't know anything about Hibernate, but the reason why you need to specify the trunc(publish_date) = to_date('09/07/2007','dd/mm/yyyy') is because of the way that Oracle stores date/time internally.
It's labelled as a date field, but the time is automatically stored as well. So, if you're just wanting to compare the date to another date, you need to ignore the time part of the column - the trunc function does this.
As for the "to_date(<date>, <date mask>)", well, you want to compare a date to a date, not a string. You could rely on the implicit conversion, governed by the nls settings, but I really, really, really wouldn't. In fact, I can't stress enough how much of a bad idea that would be! It's best to make things explicit. -
Select another column in same table in CF query
Hello..
I'm curious as to the best way to run this query..
When my CF template page loads I would like it to grab a number value in one column and match it up to the table ID in the same table and display the name for that ID.
Do I have to make another table to do this...? QoQ's?
Thanks!Hi Dan..
Sorry I wasnt clearer.. here is a picture.
Thanks for the help! -
[10g] Simple question on selecting a column in same record as a min value
I have the following sample data to illustrate my question:
CREATE TABLE t_1
( c_a VARCHAR2(1)
, c_b NUMBER(2)
, c_c DATE
INSERT INTO t_1
VALUES('A',1,SYSDATE);
INSERT INTO t_1
VALUES('A',2,SYSDATE+1);
INSERT INTO t_1
VALUES('A',3,SYSDATE+2);
INSERT INTO t_1
VALUES('A',4,SYSDATE+3);
INSERT INTO t_1
VALUES('B',3,SYSDATE+6);
INSERT INTO t_1
VALUES('B',4,SYSDATE+7);
INSERT INTO t_1
VALUES('B',5,SYSDATE+8);I have the following query which allows me to select the value of c_c that corresponds with the minimum value of c_b grouped by c_a. In other words, my goal is: for each value in c_a, I want the value of c_c that corresponds with the minimum value of c_b.
SELECT t1.c_a
, t1.c_c
FROM t_1 t1
SELECT c_a
, MIN(c_b) AS min_c_b
FROM t_1
GROUP BY c_a
) t2
WHERE t1.c_a = t2.c_a
AND t1.c_b = t2.min_c_b
;This query works, but I'm wondering if there is a more efficient way to do this. Something without a subquery? I can't come up with anything else... It just gets a bit ugly with my real data, as there are probably 10 columns of data instead of 3. (Still only 1 minimum value though).Hi,
Since you're using Oracle 10, you can do this:
SELECT c_a
, MIN (c_c) KEEP (DENSE_RANK FIRST ORDER BY c_b) AS c_of_min_b
FROM t_1
GROUP BY c_a
;This won't work in earlier versions.
What do you want in case of a tie?
For example, if we add one more row to the sample data:
INSERT INTO t_1 (c_a, c_b, c_c)
VALUES ('A', 1, DATE '2001-01-01');Now there are two rows, one dated today and one dated 2001, that have an equal claim to being the "first" in group 'A', since they have the exact same value of c_b.
The query above would display the row from 2001, that is, the earliest of the contenders. That's what MIN means in the query above. Instead of MIN, you can use any aggregate function, but, of course, that function has to work on your data type.
If you want to show all the contenders in case of a tie, then you can stick with your original query, or you could use the analytic RANK function.
WITH got_rnk AS
SELECT c_a, c_c
, RANK () OVER ( PARTITION BY c_a
ORDER BY c_b
) AS rnk
FROM t_1
SELECT c_a, c_c
FROM got_rnk
WHERE rnk = 1
;This approach requires a sub-query, because analytic functions (like RANK) are computed after the WHERE clause is applied. If we want to use the results of an anlytic func tion in a WHERE clause, we have to compute the function in a suib-query first. -
Dynamic selection of columns in Portal Report
I have to create a Report, in Oracle Portal, where I select the columns to be displayed according to the value of the language parameter returned by a PL/SQL procedure.
(So, if "English" I display columns A and B, if "French" I display columns A and C, and so on... )
How should I do?
Helps are welcome.
ThanksThe strings replaced by expression <%= v_cell %>
should print the field values contained in col1,col2,col3 columns, but nothing is printed . i think the custom tags (rw...) are not replaced by the jsp expression properly. -
Selecting columns from two table is slow but same
I am selecting 27 columns from two tables
which running for more than 30 minutes. but
if I select count(*) with the same query
except the columns it is coming in seconds.
Where is the error?If you post
1) The table definitions for the underlying tables
2) The indexes that are on the tables
3) The two SQL statements you're running
4) The explain plan for both statements
we can probably be of some assistance.
My guess is that the count(*) is able to return much more quickly because the optimizer is able to use a significantly faster query plan that is based on an index which the longer-running query cannot utilize. Without the information I've requested, though, it's hard to do more than speculate.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
Maybe you are looking for
-
How do I stop iWeb outputting multiple image files? It makes my site slow!
I'm a professional web designer (but don't let that put you off) who uses Dreamweaver and also handcodes HTML & CSS websites at work on a PC, but having got a new Mac for home use I thought I'd give iWeb a go for a personal site hosted on .Mac, showc
-
Default prompt values in webI report???
I am using BO XI 3.1 on BW universe, I have a prompt A in the prompt window which has many Lov's but user will freequently use only three values out of it. So I want to make those three values to be default for that promp A when ever the report gets
-
Reverse Date in YYYYMMDDHHMMSS format.
Hi I want system date in YYYYMMDDHHMMSS format...
-
Hi All, can anyone plz tell what are the parameters(like stored dimesions,rule file) we need to consider to estimate the size of the Essbase cube?? Is there any formula to calculate the same?? Regards, Lolita
-
I can't plan my itunes playlists on my computer nor can I preview songs from the Itunes Store. Help?