LOV SQL query dependent on column value
Hi Gurus,
I have a tabular form, a column of which I would like to display as a dropdown whose list of values is a SQL query containing a where clause on another column value.
For example, say the tabular form displays questions, and that the answers to the different questions are to be picked in list of values that are different for each question. I have tried the following queries for the dropdown list of values:
1- select value_text, value_text from list_of_values_table where question_id=#QUESTION_ID#
2- select value_text, value_text from list_of_values_table where question_id=:QUESTION_ID
3- select value_text, value_text from list_of_values_table where question_id=&QUESTION_ID.
In the 3 cases, I get an error when I run the application saying that the SQL statement is incorrect.
Any ideas?
Thanks in advance,
Guillauem
Anton,
Yes, I am creating a region based on a sql query. The query is the following:
select q.id quest_id, q.name, q.data_type_id, q.lov_flag, a.id answer_id, a.answer_text, a.org_id
from gwb_questions q left join gwb_answers a on q.id=a.question_id, gwb_answers ans right join gwb_orgs o on ans.org_id=o.id
where q.MODULE_ID=:P2_MODULE_ID and o.id=:P2_ORG_ID
Now, in the 'answer_text' column, I would like to display a dropdown containing values that come from a separate table and that depend on the value of the quest_id column. So in the Column Attributes for 'answer_text', I selected Select List (query based LOV) for the Tabular Form Element, and I entered the query mentioned before in the List of Values section (select value_text, value_text from list_of_values_table lov where lov.question_id= ?).
I am not using any API.
Does that make sense?
Thanks for your help,
Guillaume
Similar Messages
-
Result of an SQL query as a Column name of another query
Hi Friends,
Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
For eg :
I have a table where is store numbers;
select col1 from table1 where col1='5';
and i have another table where .. this value of col is a column name..
select ( select col1 from table1 where col1='5') from table2;
Thanks in advance.Hi,
ORAFLEX wrote:
Hi Friends,
Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
For eg :
I have a table where is store numbers;
select col1 from table1 where col1='5';
and i have another table where .. this value of col is a column name..
select ( select col1 from table1 where col1='5') from table2;
Thanks in advance.Do you really mean that?
select col1 from table1 where col1='5';That query will always return either '5' or nothing. Whatever you're trying to accomplish with that, you can do with an EXISTS query.
Perhaps you meant to reference two different columns in that query:
select col1 from table1 where col2='5';In that case, sorry, no, you can't do that without resorting to dynamic SQL.
If the same column is used throughout the query (but could change every time you run the query), then the dynamic SQL might be pretty easy. In SQL*Plus, for example, you could use substitution variables, defined in another query at run-time.
If there are only a few possible values that the sub-query could possibly return, and you know what they all are, then you can fake a dynamic query like this:
SELECT CASE ( SELECT col1
FROM table1
WHERE col2 = '5'
WHEN 'BONUS' THEN bonus
WHEN 'COMM' THEN comm
WHEN 'SAL' THEN sal
END AS col1
FROM table2
;Sorry to give such a vague answer, but it's the best I can do with the information I have.
It would help if you posted a little sample data (CREATE TABLE and INSERT statments for both tables), and the results you want to get from that data. If you want to pass a parameter to the query, give the results you want for a couple of different parameters. -
Create multiple capture processes for same table depending on column value
Hi,
is it possible to create multiple realtime downstream capture processes to capture changes for the same table depending on column value?
Prakashi found it - by using subset rules
prakash -
Write the sql query to find largest value in row wise without using great
write the sql query to find largest value in row wise without using
greatest fuction?Another not so good way, considering you want greatest of 4 fields from a single record:
SQL> ed
Wrote file afiedt.buf
1 with t as (Select 100 col1,200 col2,300 col3,400 col4 from dual
2 union select 500,600,700,800 from dual
3 union select 900,1000,1100,1200 from dual
4 union select 1300,1400,1500,1600 from dual
5 union select 1700,1800,1900,2000 from dual
6 union select 2100,2200,2300,2400 from dual
7 union select 2800,2700,2600,2500 from dual
8 union select 2900,3000,3100,3200 from dual)
9 SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) Max_value
10 FROM
11 (SELECT (CASE WHEN col1_col2 > col2_col3 THEN col1_col2 ELSE col2_col3 END) col1,
12 (CASE WHEN col2_col3 > col3_col4 THEN col2_col3 ELSE col3_col4 END) col2,
13 (CASE WHEN col3_col4 > col4_col1 THEN col3_col4 ELSE col4_col1 END) col3
14 FROM
15 (SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) col1_col2,
16 (CASE WHEN col2 > col3 THEN col2 ELSE col3 END) col2_col3,
17 (CASE WHEN col3 > col4 THEN col3 ELSE col4 END) col3_col4,
18 (CASE WHEN col4 > col1 THEN col4 ELSE col1 END) col4_col1
19* FROM t))
SQL> /
MAX_VALUE
400
800
1200
1600
2000
2400
2800
3200
8 rows selected.
SQL> Edited by: AP on Sep 21, 2010 6:29 AM -
SQL Query constructing for searching values in Tables single Column
I have Table USER_SERVICES with 2 Columns USER_NAME, Services. Please find below sample data on USER_SERVICES Table.
A user can be assigned with multiple services(service1, service2 etc.,). So we store data as below :
USER_NAME Services
user1 service1
user1 service2
user1 service3
user2 service1
user2 service2
user3 service3
user4 service4
I need to frame a SQL Query to 'select users assigned with Service A and Service B and Service n'.
Note: 'And' condition is used when Searching for multiple services.
Example: The SQL Query has to dynamically handle condition if i give Single Service, multiple Services(service1 and service2 e.t.c,)
If i say select users assigned with service1 and service2, from the above Table, result should be user1 and user2
If i say select users assigned with service1 and service2 and service3, from the above Table, result should be user1
If i say select users assigned with service4 from the above table, result should be user4
If i say select users assigned with service1 from the above table, result should be user2,user1
If i say select users assigned with service1 and service2 from the above table, result should be user2,user1
How do i construct the SQL Query. Any help will be appreciated.
Thanks,
Sathish
Alternate email: [email protected]How it will be stored? In a string or a table or a collection type?
If you have it in a table you can do like this.
with t
as
select 'user1' user_name, 'service1' services from dual union all
select 'user1', 'service2' from dual union all
select 'user1', 'service3' from dual union all
select 'user2', 'service1' from dual union all
select 'user2', 'service2' from dual union all
select 'user3', 'service3' from dual union all
select 'user4', 'service4' from dual
t1 as
select 'service1' services from dual union all
select 'service2' from dual
select distinct user_name
from (
select t.user_name, t.services, t1.services, count(t1.services) over(partition by t.user_name) cnt, t1.cnt cnt_1
from t
left join (select t1.*, count(*) over() cnt from t1) t1 on t1.services = t.services
where cnt = cnt_1 -
Item Selection on a dynamic LOV (SQL Query)
Hi,
I've a dynamic LOV with an SQL query who return a list of data (one column). When i select a data in this LOV to be use as an item (sql query) in the same page the data is always null. In debug mode substitution string is null.
FYI : when the data is selected, a button is clik to perform an sql query for a report in another page.
Thanks. Sorry Abasolute beginner
Message was edited by:
user581765Thanks for Your help.
The date is in fact a CHAR display (not really a date) so that is not the error.
For your information when i select a row in the list (format char YYYYMMDD_HHMM) it seems that Apex do not catch my select in the Session state.
I've change the item name with P2_DATE_FLOW but the problem remain.
This is the debug log if can help
0.03: Application 114, Authentication: CUSTOM2, Page Template: 3644802034190382
0.06: ...Session ID 1868105032215374 can be used
0.06: ...Application session: 1868105032215374, user=Neop
0.06: ...Determine if user "Neop" workspace "2859608277950243" can develop application "114" in workspace "2859608277950243"
0.06: Session: Fetch session header information
0.06: ...Metadata: Fetch page attributes for application 114, page 3
0.06: Fetch session state from database
0.06: Branch point: BEFORE_HEADER
0.06: Fetch application meta data
0.08: Computation point: BEFORE_HEADER
0.08: Processing point: BEFORE_HEADER
0.08: Show page template header
0.08: Computation point: AFTER_HEADER
0.08: Processing point: AFTER_HEADER
0.08: Computation point: BEFORE_BOX_BODY
0.08: Processing point: BEFORE_BOX_BODY
0.08: Region: Report 1
Report 1
0.08: show report
0.09: determine column headings
0.09: parse query as: CFM_MDRE
0.12: binding: ":P2_DATE_FLOW"="P2_DATE_FLOW" value="0"
0.14: print column headings
0.14: rows loop: 15 row(s)
No data found. -
Order query depending on column names passed at runtime
Hi
Can any one suggest how to order by at run time depending on column name passed as parameter.
create or replace procedure dummy_proc( p_orderby varchar2,p_refcursor out sys_refcursor)
is
begin
open p_refcursor for select * from
emp where Status='A'
order by (select p_orderby from dual);
end;
--execution part for testing
declare
v_outcursor sys_refcursor;
v_rec_data emp%rowtype;
v_cnt number;
begin
dummy_proc ('ename,sal',v_outcursor);
begin
loop
fetch v_outcursor into v_rec_data;
v_cnt:=v_outcursor%rowcount;
exit when v_outcursor%notfound;
dbms_output.put_line('empno '|| to_char(v_rec_data.empno));
dbms_output.put_line('empno '|| v_rec_data.ename);
end loop;
end;
dbms_output.put_line('Count is'|| to_char(v_cnt));
end;
we do not want to something like below as my actual query is very big with union statements and case expressions, (below is just an similar example)
how i tried to order by but its not working.
v_sql='select * from emp where empno= '|| p_empno || ' order by '|| p_orderby;
open p_refcursor for v_sql;
Thanks in advance
Vishalwe do not want to something like below as my actual
query is very big with union statements and case
expressions, (below is just an similar example)
how i tried to order by but its not working.
v_sql='select * from emp where empno= '|| p_empno ||
' order by '|| p_orderby;
open p_refcursor for v_sql;I agree, you really don't want to do that, you want to use BIND VARIABLES.
v_sql := ' select * from emp where empno = :bound_empno order by :bound_orderby';
open p_refcursor for v_sql using p_empno, p_orderby;
[pre]
The size of the statement shouldn't come in to play, if the only dynamic portion of it is the order by clause then declare a constant which is the large query (you can use a LONG datatype) and then concatenate in the order by clause before you return the reference cursor.
Unless you can give a legitimate reason for why you cannot use Dynamic SQL (not why you do not want to use it) this would be my approach.
And please, if you don't know what a bind variable is...read about them, or your system will suffer. -
Can Portal Report from SQL Query use where column IN (:bind_variable)
I would like to create a portal report from sql query with IN (:bind_variable) in the where clause. The idea is that the user would enter comma-separated or comma-quote-separated values for the bind_variable. I have tried this several ways but nothing seems to work. Can this be done?
TrentonHi,
Which version of portal are you using. This is a bug. It has been fixed in 30984.
Thanks,
Sharmila -
How to check the sql:query is return null value
I have use :
<sql:query var="sql1" dataSource="${db}">
select col_name from table_name
where a=<c:out value="${row.test1}"/>
and b='<c:out value="${row.test2}"/>'
</sql:query>
So, how can I check this statement return null value which is no record within this table?The Result should never be null but can be empty. You can check if the Result is empty using an if tag and checking the rowCount property:
<sql:query var="books"
sql="select * from PUBLIC.books where id = ?" >
<sql:param value="${bookId}" />
</sql:query>
<c:if test="${books.rowCount > 0}">
</c:if>http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSTL7.html#wp84217
Look for query Tag Result Interface -
SQL Query to find cumulative values for a Financial Year
Dear users,
My requirement is to create a SQL query for a table/view where I have day-wise data. I want to find out cumulative values for financial year by giving any date. It should add the values from start of financial year till that date in the financial year.
I think creating a view of such type will post heavy burden on resources since accuimulation will be done for each day upto that day.
ThanksDear users,
My requirement is to create a SQL query for a
table/view where I have day-wise data. I want to
find out cumulative values for financial year by
giving any date. It should add the values from start
of financial year till that date in the financial
year.
I think creating a view of such type will post heavy
burden on resources since accuimulation will be done
for each day upto that day.
ThanksKumar's solution will serve yours purpose but m not agreed
I think creating a view of such type will post heavy
burden on resources since accuimulation will be done
for each day upto that day. Khurram -
SQL query returns varchar - default value type!!!
On a field in my portal form there is a default value type of 'SQL query returns varchar', where can I put this sql to get a default value from a table?
Hi again
I have this code in 'additional pl/sql code' - '...before displaying the page'. But it comes up with an error when I run the form.
declare
prop_v varchar2(20);
group_v varchar2(3);
el1_v varchar2(3);
blk varchar2(10) := 'DEFAULT';
begin
prop_v := p_session.get_value_as_varchar2(p_block_name=>'DEFAULT', p_attribute_name => 'l_property_p');
group_v := p_session.get_value_as_varchar2(p_block_name=>'DEFAULT', p_attribute_name => 'l_group_p');
select element_code
into el1_v
from eh_risk_element_detail
where property_ref = prop_v
and group_code = group_v
and line_no = 1;
p_session.set_value(p_block_name => blk, p_attribute_name => 'L_ELEMENT1_P', p_value => el1_v);
end;
Rich -
HTML-DB 1.6 SQL Query (Concatenate two columns)
Hi everyone,
My query look like this. But I got this message
ORA-01403: no data found
Sql query(.....returning ... sql
What I can do ? I want to concatenate my two columns in one.
<pre>
-----Résultats de la recherche
BEGIN
DECLARE
requete varchar2(5000);
v_code_type varchar2(2000);
v_ordre varchar2(500);
BEGIN
:P1_NOM_BENEFICIAIRE := REPLACE(:P1_NOM_BENEFICIAIRE,' ', '%');
:P1_NOM_BENEFICIAIRE := REPLACE(:P1_NOM_BENEFICIAIRE,'-', '%');
requete := 'SELECT
(FEUI.NOM_BENEFICIAIRE || ''--'' || FEUI.PRENOM_BENEFICIAIRE) ABC,
FEUI.VALEUR_ID_BENEFICIAIRE,
FEUI.MONTANT,
FEUI.CODE_TYPE_DECLARATION,
FEUI.ANNEE_FISCALE,
FEUI.CODE_ENTITE,
FEUI.ID_FEUILLET_IMPOT,
FEUI.ID_AMENDEMENT,
FEUI.NO_RELEVE_ORIGINAL_PROV,
FEUI.ACRONYME_ID_BENEFICIAIRE,
TYPD.SIGNIFICATION
FROM
S29_FEUILLET_IMPOT FEUI,
S29_TYPE_DECLARATION TYPD
WHERE
(TYPD.CODE = FEUI.CODE_TYPE_DECLARATION) AND
(ANNEE_FISCALE = :P1_ANNEE_FISCALE) AND
(CODE_ENTITE LIKE ''%'' || SUBSTR(:P1_CODE_ENTITE,1,3) || ''%'') OR
(CODE_ENTITE = SUBSTR(:P1_CODE_ENTITE,1,3))
AND
((:P1_NAS IS NULL) OR (:P1_NAS = VALEUR_ID_BENEFICIAIRE))
AND
((:P1_NEQ IS NULL) OR (:P1_NEQ = VALEUR_ID_BENEFICIAIRE))
AND
((:P1_NOM_BENEFICIAIRE IS NULL) OR
((UPPER(NOM_BENEFICIAIRE) || UPPER(PRENOM_BENEFICIAIRE))
LIKE ''%'' || UPPER(:P1_NOM_BENEFICIAIRE) || ''%'') OR
((UPPER(PRENOM_BENEFICIAIRE) || UPPER(NOM_BENEFICIAIRE))
LIKE ''%'' || UPPER(:P1_NOM_BENEFICIAIRE) || ''%'') OR
((UPPER(RAISON_SOCIALE_LIGNE_1) || UPPER(RAISON_SOCIALE_LIGNE_2))
LIKE ''%'' || UPPER(:P1_NOM_BENEFICIAIRE) || ''%'') OR
((UPPER(RAISON_SOCIALE_LIGNE_2) || UPPER(RAISON_SOCIALE_LIGNE_1))
LIKE ''%'' || UPPER(:P1_NOM_BENEFICIAIRE) || ''%'') OR
(UPPER(SUBSTR(COORDONNEE_BENEFICIAIRE_SYGBEC,1,80))
LIKE ''%'' || UPPER(:P1_NOM_BENEFICIAIRE) || ''%'')
IF (:P1_CODE_RELEVE = 'A') OR
(:P1_CODE_RELEVE = 'M') OR
(:P1_CODE_RELEVE = 'C') THEN
v_code_type := '(
(FEUI.CODE_TYPE_DECLARATION = ''A'') OR
(FEUI.CODE_TYPE_DECLARATION = ''M'') OR
(FEUI.CODE_TYPE_DECLARATION = ''C'')
else
v_code_type :=
(:P1_CODE_RELEVE = CODE_TYPE_DECLARATION) OR
(:P1_CODE_RELEVE = ''%'')
end if;
WWV_FLOW.DEBUG('V_CODE_TYPE EST EGALE A :' || v_code_type);
v_ordre := 'ORDER BY NOM_BENEFICIAIRE, VALEUR_ID_BENEFICIAIRE,
ID_FEUILLET_IMPOT, ID_AMENDEMENT';
requete := requete || ' AND ' || v_code_type || v_ordre;
RETURN requete;
END;
END;
</pre>
Thanks. ByeThank you Scott,
I'm sorry, I should present you a reduce sql command.
I had construct my "long" sql command without concatenation. But, I decide to add a column just beside the other column.
After sending my message on OTN, I tried something else, I decided to copy my sql command without concatenation in an other region. I changed my sql command in the new region by adding my new column and this ''--'' and it works very well. Sometimes, It's really difficult to understand why it doesn't.
Thanks. Bye, -
SQL query to store float values in french culture.
Here is how my requirement goes..
I have an application where users can store float values into the SQL server. Here float values are period(.) based. I have now started supporting the users who use the french culture where the float values are Comma(,) based. Example: 13.75 is represented
as 13,75. Instead of making changes to my code i.e the way i am inserting/retrieving the date now, is there a way i can handle this requirement based on culture. Like, if I specify the culture, will I be able to insert float inputs as comma(,) based values
without disturbing my existing code?
Any help is appreciated
Thanks,
Chandrahas.
-Chandrahasis there a way i can handle this requirement based on culture.
Hello Chandrahas,
SQL Server don't store any culture info for numeric values; they are plain numeric.
It's part of the frontend to represent / accept values depending on the culture setting of the client.
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Need of SQL query in selecting distinct values from two tables
hi,
I need a query for selecting distinct values from two tables with one condition.
for eg:
there are two tables a & b.
in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
can anybody please help me.
Thanks in advance,
RatheeshNot sure what you mean either, but perhaps this will start a dialog:
SELECT DISTINCT a.empno,
a.name,
a.sex,
b.salary,
b.doj
FROM a,
b
WHERE a.empno = b.empno;Greg -
Sql query - Selecting last recorded values for each date in specified period
Hello,
Can someone please help me with my problem.
I'm trying to get last recorded balance for each day for specific box (1 or 2) in specified period of days from ms access database using ADOTool.
I'm trying to get that information with SQL query but so far unsuccessfully...
My table looks like this:
Table name: TestTable
Date Time Location Box Balance
20.10.2014. 06:00:00 1 1 345
20.10.2014. 12:00:00 1 1 7356
20.10.2014. 18:45:00 1 1 5678
20.10.2014. 23:54:00 1 1 9845
20.10.2014. 06:00:02 1 2 35
20.10.2014. 12:00:04 1 2 756
20.10.2014. 18:45:06 1 2 578
20.10.2014. 23:54:10 1 2 845
21.10.2014. 06:00:00 1 1 34
21.10.2014. 12:05:03 1 1 5789
21.10.2014. 15:00:34 1 1 1237
21.10.2014. 06:00:00 1 2 374
21.10.2014. 12:05:03 1 2 54789
21.10.2014. 15:00:34 1 2 13237
22.10.2014. 06:00:00 1 1 8562
22.10.2014. 10:00:00 1 1 1234
22.10.2014. 17:03:45 1 1 3415
22.10.2014. 22:00:00 1 1 6742
22.10.2014. 06:00:05 1 2 562
22.10.2014. 10:00:16 1 2 123
22.10.2014. 17:03:50 1 2 415
22.10.2014. 22:00:10 1 2 642
23.10.2014. 06:00:00 1 1 9876
23.10.2014. 09:13:00 1 1 223
23.10.2014. 13:50:17 1 1 7768
23.10.2014. 19:47:40 1 1 3456
23.10.2014. 21:30:00 1 1 789
23.10.2014. 23:57:12 1 1 25
23.10.2014. 06:00:07 1 2 976
23.10.2014. 09:13:45 1 2 223
23.10.2014. 13:50:40 1 2 78
23.10.2014. 19:47:55 1 2 346
23.10.2014. 21:30:03 1 2 89
23.10.2014. 23:57:18 1 2 25
24.10.2014. 06:00:55 1 1 346
24.10.2014. 12:30:22 1 1 8329
24.10.2014. 23:50:19 1 1 2225
24.10.2014. 06:01:00 1 2 3546
24.10.2014. 12:30:26 1 2 89
24.10.2014. 23:51:10 1 2 25
Let's say the period is 21.10.2014. - 23.10.2014. and I want to get last recorded balance for box 1. for each day. The result should look like this:
Date Time Location Box Balance
21.10.2014. 15:00:34 1 1 1237
22.10.2014. 22:00:00 1 1 6742
23.10.2014. 23:57:12 1 1 25
So far I've managed to write a query that gives me balance for ONLY ONE date (date with highest time in whole table), but I need balance for EVERY date in specific period.
My incorrect code (didn't manage to implement "BETWEEN" for dates...):
SELECT TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
FROM TestTable
WHERE Time=(SELECT MAX(Time)
FROM TestTable
WHERE Location=1 AND Box=1 );
Tnx!
Solved!
Go to Solution.For loop
following query keep day (here 24 in below query) Variable from ( 1 to 28-29/30/31 as per month)
SELECT TOP 1 TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
FROM Test Table.
WHERE Time=(SELECT MAX(Time) FROM TestTable WHERE Location=1 AND Box=1 )
AND DATE = "2014-10-24";
PBP (CLAD)
Labview 6.1 - 2014
KUDOS ARE WELCOMED.
If your problem get solved then mark as solution.
Maybe you are looking for
-
E-mail notification for streams errors
What should be done, that Oracle Streams Capture or Propagation or Apply sent e-mail to DBA that any these Proccesses has error. Right now I'm checking Grid Control every hour. I need setup that any errors in Oracle Streams I got e-mail about this pr
-
SAP Standard Cost Centre reports
Hi, I would like to use the following SAP Standard report S_ALR_87013614 but cannot exclude certain cost elements. The report unfortunately only has the functionality to include cost elements but there is no option to exclude any cost elements. The "
-
Adobe Form - Data Binding for static text
Hi Experts, I'm trying to create a new label with Adobe Forms (not interactive). So I've created an interface with a table LABEL_DATA (import) and many variables (import) and a new Form with Layout. I tried to bind some text fields with the imported
-
Hi. I am having much trouble with what is discussed in this old forum http://forums.adobe.com/thread/882978?start=0&tstart=0 It seems that the guy who was helping is no longer with Adobe because when I email him as instructed I get this Delivery to t
-
Unable to update column through ODI
H , i am facing some strange issue while from ODI i am trying to update a column it not working , but if i run that same code in DB , it updated that column is their any issue , i am not getting it , here is my code DECLARE V_CNT NUMBER(10); V_SESS_N