DISTINCT Select List SQL
I am trying to create a distinct select list with a substr to remove either everything after a ":" or a word at the end of the field and am having a little trouble. Hope someone can help.
We are on Version 4.1 and I am in the Shared Components for current database. I can get the distinct to work but not the substr.
This works without :
select distinct GROUP_VP_DESC D,
GROUP_VP_DESC R
from xxc.XXC_GL_DIV_REG_FAC
order by 1
This works in TOAD, so tried to insert into sql above but keep getting error about in-line query:
select distinct(substr(group_vp_desc, 1,instr(group_vp_desc, ':',1)-1)) "Group"
from xxc.XXC_GL_DIV_REG_FAC
order by 1
Any assistance is appreciated, thank you in advance.
Krise
You are missing the return value in the query, but in case you just mis typed, I have had to wrap select statements with another select for lists with complex code.
e.g.
Select group, ret from
select distinct(substr(group_vp_desc, 1,instr(group_vp_desc, ':',1)-1)) "Group", distinct(substr(group_vp_desc, 1,instr(group_vp_desc, ':',1)-1)) "Ret"
from xxc.XXC_GL_DIV_REG_FAC
order by 1
Similar Messages
-
How to create dependent Select Lists?
Hi,
Found in the documentation that to create dependent select list we have to do these 3 things:
1. In the parent select list, choose the option "select list with submit".
2. Defining a branch that branches back to the current page.
3. In the child select list sql, use the value of the parent (eg. :P6_PARENT_SELECT_VALUE).
When I change the value of parent select list the page is getting submitted and its going to the parent page. I've a branch that goes to the parent page but how to create a branch that comes back to the same page and then use it in parent select list?
Thanks,
HozyHi Hozy,
1. Make the branch conditional...
2. Create a new branch while will run when you make a selection in parent select list.
Also check this site to create dependent select list without sumbitting the page....
http://www.dba-oracle.com/t_html_db_apex_ajax_application_express.htm
Regards,
Shijesh -
Setting current values in Multiple Select List in SQL Query based Report
Hi,
I have a report based on a sql query that contains a multiple select list. Unfortunately I cannot get the multiple select list to display the current values (p_value) correctly. I have created a page item, :p311_current_versions, that is set using a pre-header process and it returns a value with a colon delimited format e.g. '10.1.2.1.0:10.1.2.2.0'. Then this item is used in the sql query to set the current value (p_value) of the apex_item.select_list_from_query function. However when the table is displayed, instead of having two entries, 10.1.2.1.0 and 10.1.2.2.0 selected, it has an extra entry '10.1.2.1.0:10.1.2.2.0' selected.
Here is my code:
select distinct a.product, a.version from (
select distinct
apex_item.display_and_save(2,product)||apex_item.hidden(1,env_product_id) PRODUCT,
APEX_ITEM.SELECT_LIST_FROM_QUERY(3,decode(product, 'HTTP Server' , :p311_current_versions, version), 'SELECT distinct version d, version r FROM ebs_tech_stack where
product ='''||PRODUCT||'''',
decode(PRODUCT, 'HTTP Server' ,'multiple="multiple" style="width:170px"','style="width:170px"'),
'NO') as version
from ebs_environment_tech_stack
where environment_id = :p311_umgebung_id) a order by a.product
If anyone can help me figure out how to set the current values correctly I'd be really grateful!!
Thanks in advance,
JeanJean,
I don't think this is possible using the apex_item package. The select_list_from_query function accepts only a single value for the second parameter.
Scott -
LOV an SQL : how to configure a select list to get all records
Hello,
I am using Oracle 10g with APEX 2.0.
Here is my question:
I have a report and I am using 3 text fields and a select list to search through a join of two tables. The select list is composed of a "list of values" and the parameter, which is used in the SQL-sentence, has a numeric value.
Result table after the join operation looks like this:
Field1 Field2 Field3 Field4 (By assuming the field3 is the one which used in the select list.)
21a this 1000 bn
21a that 1001 vb
33c thus 1012 ct
What I want to do is to set another parameter-value pair in the select list to let user choose the "ALL" of the mentioned items in the select list so that the search will return all the records without having taken this select list-field into consideration.
Is it possible to do it with LOV and SQL? Do I need any other functions? or configurations?
Thanks in advance,
SedefHi user630478!
I always use a select list with submit and the option to get a NULL-Value for such things. To solve your problem do the following things:
1.) Create two named LOVs. One as you already did and another one for all values.
2.) Your select list with submit should be configured to show a NULL-Value e. g. it shows ALL with the value 0.
3.) Create two conditional branches that work together with your select list. One that show the normal results if a user has clicked on a normal value and the second should act only if a user has clicked on ALL.
4.) Write a process that switches the LOVs in your select list from one to the other. This process should only be fired if the second conditional branch has been actived.
Maybe if I understood right that's what you want to know.
yours sincerely -
Refresh PL/SQL Report Region (not Page) using Select List value
Hi,
I've got a report region based on a 'PL/SQL function body returning a SQL query'which gets generated on selecting a value from a Select list item, The Select List action is 'Redirect and Set value' but this causes the whole page to refresh rather than just the report region. I've tried to refresh the report only using a dynamic action on the Select List item (Action now reset to 'None') but now the report is not appearing on choosing from the List. Can anyone suggest a solution that will allow me to refresh this report without refreshing the page? I am using APEX 4.2.2 and the report syntax is as follows:
DECLARE
v_statement VARCHAR2(500);
BEGIN
SELECT query_text
INTO v_statement
FROM sql_queries
WHERE query_id = :P2_QUERY ;
RETURN v_statement ;
END ;
where P2_QUERY is Select List Item,
regards,
Kevin.KevinFitz wrote:
The report region being displayed is conditional on P2_QUERY item being NOT NULL. I assume the region not appearing is because the Action for the Select List Item is set to None and so P2_QUERY is always NULL.
No, the region is not appearing because it is conditional on P2_QUERY being NOT NULL. This means that the report region never exists on the page shown in the browser, so it can't be dynamically refreshed. (Dynamic refresh doesn't evaluate region conditions, and it only re-renders the report content, not the entire region.)
Remove the condition on the report region, check the refresh is working, then reconsider exactly what the requirements here are. If you want the region to appear only when P2_QUERY has a value, and you want it to be refreshed without submitting and re-rendering the page, then the region needs to be hidden rather than conditionally rendered, and shown via a dynamic action when P2_QUERY gets a value.
I tried adding an additional Set Value True Action for the DA event but got an error as listed above,
All irrelevant if Page Items to Submit on the region is used properly. -
How to use a select list value in a PL/SQL function body returning SQLquery
Hi Friends,
I have a select list P6_TEST with values 'nav' anf 'jyo'. I am trying to create a report using "SQL Query (PL/SQL
function body returning SQL query)". In my report query can i check if P6_TEST='nav' and do something like the
code shown below.How can i do that.
DECLARE
v_sql VARCHAR2(3000);
BEGIN
IF :P6_TEST = 'nav' THEN
v_sql :=
'SELECT
* from department';
........................Thanks,
NavNav:
What you have should work. Give it a go. Post back if you run into issues.
Varad -
Multiple Select List looping thru PL/SQL function body returning SQL query
Hi,
I have a Multiple Select List. I want to loop through the values from the Select List and process them in a PL/SQL function body returning a SQL query. Currently, my code only returns the SQL SELECT results of one item in the select list. How do I change my code to make it return the results of all of the items in the select list? (I tested it and it is definitely picking up all the values in the select list).
<b>
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(20);
q varchar2(32767);
BEGIN
selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
-- htp.p('COUNT: '||selected_items.count);
FOR i in 1..selected_items.count LOOP
s := TO_CHAR(selected_items(i));
-- htp.p('First: '||s);
-- htp.p('Second: '||:s);
-- htp.p('Third: '||TO_CHAR(selected_items(i)));
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END LOOP;
END;</b>
Thank you,
LauraLaura,
First, I would be careful of introducing SQL Injection possibilities. Any time I see
'Select ... ' || :P123_FOO || ' ... '
I worry about sql injection. In your case you are converting :P50_SELECTED_INSTRUMENTS into selected_items and then selected_items into s. So when I see
'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
I think, "I could use sql Injection and hack this."
So, I would do some validation on :P50_SELECTED_INSTRUMENTS or some other method to avoid this.
I'm not certain I understand your query. Do you really intend to allow the user to select the beginning of a string and then find all rows that start with that string? Or, do you just want to let them find when it matches the string. This is one way if you want to do matching:
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(32767);
q varchar2(32767);
BEGIN
-- Change the : separate string to be comma separated with quoted strings
s := '''' || replace(:P50_SELECTED_INSTRUMENTS, ',', ''',''')|| '''' ;
-- htp.p('COUNT: '||selected_items.count);
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE TO_CHAR(orig_geo_loc_sys) in (' || s ||' ) '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END;
If you want to do something more like you originally stated, try this:
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(20);
q varchar2(32767);
BEGIN
selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
-- htp.p('COUNT: '||selected_items.count);
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE 1=1 ';
FOR i in 1..selected_items.count LOOP
s := TO_CHAR(selected_items(i));
q := q || ' and TO_CHAR(orig_geo_loc_sys) LIKE '''|| s ||'%'' ' ;
END LOOP;
q := q || ||'%'' '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END;
Hope this helps...
Anton -
Problem writing a sql query for a select list based on a static LOV
Hi,
I have the following table...
VALIDATIONS
ID Number (PK)
APP_ID Number
REQUESTED Date
APPROVED Date
VALID_TIL Date
DEPT_ID Number (FK)
I have a search form with the following field item variables...
P11_DEPT_ID (select list based on dynamic LOV from depts table)
P11_VALID (select list based on static Yes/No LOV)
A report on the columns of the Validations table is shown based on the values in the search form. So far, my sql query for the report is...
SELECT v.APP_ID,
v.REQUESTED,
v.APPROVED,
v.VALID_TIL,
d.DEPT
FROM DEPTS d, VALIDATIONS v
WHERE d.DEPT_ID = v.DEPT_ID(+)
AND (d.DEPT_ID = :P11_DEPT_ID OR :P11_DEPT_ID = -1)
This query works so far. My problem is that I don't know how to do a search based on the P11_VALID item - if 'yes' is selected, then the VALID_TIL date is still valid. If 'no' is selected then the VALID_TIL date has passed.
Can anyone help me to extend my query to include this situation?
Thanks.Hello !
Let's have a look at my example:create table test
id number
,valid_til date
insert into test values( 1, sysdate-3 );
insert into test values( 2, sysdate-2 );
insert into test values( 3, sysdate-1 );
insert into test values( 4, sysdate );
insert into test values( 5, sysdate+1 );
insert into test values( 6, sysdate+2 );
commit;
select * from test;
def til=yes
select *
from test
where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
=decode('&til','yes',1,-1);
def til=no
select *
from test
where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
=decode('&til','yes',1,-1);
drop table test; It's working fine, I've tested it.
The above changes to my first idea I did because of time portion of the DATE datatype in Oracle and therefore the wrong result for today.
For understandings:
1.) TRUNC removes the time part of DATE
2.) The difference of to date-values is the number of days between.
3.) SIGN is the mathematical function and gives -1,0 or +1 according to an negative, zero or positiv argument.
4.) DECODE is like an IF.
Inspect your LOV for the returning values. According to my example they shoul be 'yes' and 'no'. If your values are different, you may have to modify the DECODE.
Good luck,
Heinz -
How-To populate SELECT LIST default value from SQL Query
OK, I've done my homework, and did not find my answer in the Forum, so here it is.
I have a Page that displays fields from a SQL Query. The Page also has below that radiogroups, checkboxes, and Select Lists to allow the user to change values in the fields that are displayed at the top of the Region. I am able to pre-populate the radiogroups and checkboxes by performing a SELECT in the 'Source value or expression' of the Source area of the Page Item.
However, I am unable to do the same for the Select List fields. Their default value ends up being the first value in the LOV ('-- None --' for NULL values). Source Used: Only when current value in session state is null. Source Type: SQL Query. Also, when I first go into the Page when running it, and check the Session State values, they are all null, so I don't understand why the field is not populated by the SQL Query statement as the radiogroups and checkboxes are.
Any suggestions??? I've tried all sorts of combinations.Thank you for the suggestion.
I had considered that, but cannot do so, because we are using Oracle Application Express more for development than for data containment.
We have all our data in an Oracle 10.g DB which is separate from the OAEX server, and the OAEX app will reference that data via VIEWs and DB LINKs. We are doing so primarily as an added data security layer, where the data is housed separate from the app, in case the Web site is ever compromised. The data that can be viewed is restricted to a subset of the actual data that is available.
Since the data is on a separate server, (I assume) we will not be able to set the source type to Database column, because (I asume) that is dependent upon the data being housed by the OAEX server.
That still leaves me with having to populate the field with a SELECT statement from the Oracle DB. This unfortuneately is almost a show-stopper for me because of down-stream processing data requirements. Have not been able to come up with contingencies yet. -
Resolved: Use value from select list in pl/sql block
Hello,
I have a form with a select list: P18_BONUSTYPE, the values of which come from a LOV.
When the user clicks a button, a page process is used to insert a row into a table.
When I use the :P18_BONUSTYPE bind variable in my insert statement I get an error "Invalid number" I get an "Invalid number" error. I assume that APEX is using the displayed text in that bind variable, not its actual (html option) value.
I checked the HTML of the page, and the correct values are in the select list.
Can someone tell me how to get the value into a bind variable that can be used in a pl/sql block for a page process?
Thanks
Message was edited by:
Neeko
Issue was a value in another item.Did you tried changing the value using "to_number"? (i.e. to_number(:P18_BONUSTYPE)).
Max. -
Using HANA SQL Functions in select list of CDS Views
Dear Expert,
Kindly please let me know if we can use the HANA SQL Function (Ex: ADD_DAYS, SECONDS_BETWEEN) in the select list of CDS Views?
If I create a CDS like below I get error that timestamp is not supported.
For Example:
@AbapCatalog.sqlViewName: 'ZMR_H_CA'
@EndUserText.label: 'CAG A'
define view viewname
with parameters start_ts:abap.dec( 15, 0 ) , end_ts:abap.dec( 15, 0 )
as select from table {
key resource_key,
TO_TIMESTAMP(begtstmp) as start_tmp,
TO_TIMESTAMP(begtstmp) as end_tmp
where
(begtstmp > $parameters.start_ts or endtstmp > $parameters.start_ts )
and
(begtstmp < $parameters.end_ts or endtstmp < $parameters.end_ts )
Thanks,
GiriHi Giri,
the list of provided features can be found in the ABAP Language Documentation (F1 in the CDS View).
As CDS in ABAP is abstracted from the database layer, the database features are not directly accessible. That means, you cannot use any HANA or MaxDB feature available. So the answer to your question is no. The reason for this is, that ABAP CDS views can be created on all SAP-supported databases, hence, we can only provide those features, supported by all databases.
Having said this, there are some exception, e.g. the CDS views with input parameters, which are not supported by all databases. In these cases, you'd have to additionally use the utility class CL_ABAP_DBFEATURES (see http://scn.sap.com/community/abap/blog/2014/10/10/abap-news-for-740-sp08--abap-core-data-services-cds) for more details.
Best,
Jasmin -
Apply distinct to all the columns in a select list
Select distinct name, date , venue , duration from tableA
the above query distinct onlu the first column in the select list but is it possible to distinct all the columns.
current out put is
1 , raj, 25-may-2009, uk , 10
1 , raj, 25-may-2009, usa , 10
1 , raj, 25-may-2009, uk , 20
requried output....
1 , raj, 25-may-2009, uk , 10
the first found row is enogh...
thanks in advance :)
rajBut all these tree rows are distinct. Doesn't it? Why you want to take only first row? What's the logic?
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com
[Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/] -
ORA-01007 - variable not in select list error in pl\sql code
Hi,
When I tried to run this program I am getting below error:
ORA-01007 - variable not in select list.Please help to resolve.
Code:
create or replace procedure "XX_BPM_DATA_P" (P_PROCESS_ID IN VARCHAR2)
is
TYPE l_entity_type IS TABLE OF xx_BPM_data.ENTITY%TYPE INDEX BY PLS_INTEGER;
TYPE l_data_type IS TABLE OF XX_BPM_DATA.DATA%TYPE INDEX BY PLS_INTEGER;
TYPE l_count_type IS TABLE OF XX_BPM_DATA.count%TYPE INDEX BY PLS_INTEGER;
l_Entity_v l_Entity_type;
l_data_v l_data_type;
l_count_v l_count_type;
l_security_group_id number;
app_id number(20);
l_Actual_value XX_BPM_DATA.DATA%TYPE;
cursor BPM_CUR is select id,process_id , sequence, to_char(query) query,report_num from xx_test_bpm_dynamic
where
process_id = p_process_id
and report_num=1
order by process_id, sequence;
BEGIN
--delete xx_bpm_data where process_id = p_process_id;
for bpm_rec in bpm_cur
loop
delete xx_bpm_data
where process_id = bpm_rec.process_id
and sequence = bpm_rec.sequence
and report_num = bpm_rec.report_num;
l_security_group_id := apex_custom_auth.get_session_id_from_cookie;
--dbms_output.put_line(l_security_group_id);
execute immediate bpm_rec.query BULK COLLECT INTO l_ENTITY_v,l_DATA_v,l_count_v;
if (bpm_rec.report_num=2) then
app_id:= 108;--NV('APP_ID');
FORALL i IN l_ENTITY_v.FIRST..L_ENTITY_V.LAST
INSERT INTO XX_BPM_DATA
(EnTITY,
value,data,count,
Process_ID,
Sequence,report_num)
VALUES(l_entity_v(i),
l_data_v(i),
'<A HREF="f?p='||app_id||':301:'||':APP_SESSION'||'::::P301_process_id,p301_sequence,p301_id,p301_entity:'||bpm_rec.process_id||','||bpm_rec.sequence||','||bpm_rec.id||','||l_entity_v(i)||':">'||l_data_v(i)||'</A>',
l_count_v(i),bpm_rec.process_id,
BPM_rec.sequence,
bpm_rec.report_num);
else
FORALL i IN l_ENTITY_v.FIRST..L_ENTITY_V.LAST
INSERT INTO XX_BPM_DATA(EnTITY,data,
count,
Process_ID,
Sequence,report_num)
VALUES(l_entity_v(i),
l_data_v(i),
l_count_v(i),
bpm_rec.process_id,
BPM_rec.sequence,
bpm_rec.report_num);
end if;
select round(avg(value),2) into l_actual_value from xx_bpm_data where process_id=bpm_rec.process_id and sequence=bpm_rec.sequence and report_num=bpm_rec.report_num;
update xx_test_bpm_dynamic set value=l_actual_value where process_id=bpm_rec.process_id and sequence=Bpm_rec.sequence and report_num= bpm_rec.report_num;
end loop;
Commit;
END;When I tried to run this program I am getting below error:
ORA-01007 - variable not in select list.Please help to resolve.
You likely would not need any help in you wrote and tested your code using standard best practices.
Your code has NO exception handler and you are NOT identifying each step in the code so that the exception handler could print/log a message telling you EXACTLY which step raised the exception.,
v_step NUMBER;
-- before step 1
v_step := 1;
-- before step 2
v_step := 2;
Then in the exception handler the value of 'v_step' will tell you which step raised the exception.
The exception you posted refers to a 'select list' so examine ALL of the select lists in your code. If you do that you will see that the primary query being run is obtained from a database table and then executed using dynamic SQL
execute immediate bpm_rec.query BULK COLLECT INTO l_ENTITY_v,l_DATA_v,l_count_v;
We have no way of knowing what query is in 'bpm_rec.query' when the exception happens or what columns that query returns. For all we know the query returns 2 columns and you are trying to load 3 collections. Or maybe the query returns 8 columns and you are trying to load 3 collections.
Why don't you print out the query and execute it manually so you can see exactly what the result set looks like?
dbms_output.put_line(bpm_rec.query);
And don't even get us started on why you are using such security-prone dynamic sql to perform this processing instead of using ordinary SQL statements. Or why you are using associative arrays for the BULK COLLECT instead of nested tables.
In short your code could blow up in several places and, because you have NO logging statements, control statements or exception handlers, anyone having to troubleshoot that code would have absolutely no idea what part of it may be the problem. -
Using Multi Select List in SQL Query
Hi all,
I am trying to using a Multi Select list for filtering of a report. I have :P2_RISK_SEVERITY which has has the possibility of values Very Low:Low:Medium:High:Very High. How do I use this Multi Select in the where section of a SQL query?
I need to say something along the lines of:
Select RISK_SEVERITY from TBL_RMD_RISKS where RISK_SEVERITY = (one of the options selected in the multi select)
Thanks for the help.Hi there,
The above suggestion will work perfectly as long as the table you're querying is relatively small, but keep in mind that applying the INSTR to the left side of the WHERE clause will always result in a full table scan. This means that if your table is large and RISK_SEVERITY is indexed, the index will never be used. Here is another approach (credit to AskTom) that converts your colon-delimited string of selected values to a list that can be used in an "IN(...)" clause, which will use an index on RISK_SEVERITY as long as the optimizer otherwise deems it appropriate:
-- creates a type to hold a list of varchars
CREATE OR REPLACE TYPE vc2_list_type as table of varchar2(4000);
-- converts a colon-delimited string of values to a list of varchars
CREATE OR REPLACE FUNCTION vc2_list(p_string in varchar2)
return vc2_list_type is
l_string long default p_string || ':';
l_data vc2_list_type := vc2_list_type();
n pls_integer;
begin
loop
exit when l_string is null;
n := instr(l_string, ':');
l_data.extend;
l_data(l_data.count) := ltrim(rtrim(substr(l_string, 1, n - 1)));
l_string := substr(l_string, n + 1);
end loop;
return l_data;
end vc2_list;
-- your WHERE clause
where risk_severity in(
select *
from the(select cast(vc2_list(:P2_RISK_SEVERITY) as vc2_list_type)
from dual))
...Hope this helps,
John -
Using select list value as column name in SQL
Folks,
Thanks in advance for any help with this
I have a select list with two values (Instance and Username) created by
STATIC2:Username;USERNAME,Instance;INSTANCE
I am trying to pass the value of this (:P2_SELECT) and use it as a column name in a SQL query as below
select USERNAME,
INSTANCE
from table_name
where :P2_SELECT like '%'||:P2_TEXTSEARCH||'%'
When I substitue the :P2_SELECT for one of the values (either instance or username) this works fine
I suspect it is due to how Application Express interprets the value of :P2_SELECT
Any help would be much appreciated!
GarethThanks Munky that worked a treat!
The next hurdle I have now is that because I have changed the region type to "PL/SQL Function(returning SQL Query)" there is no longer the option to add sorting to the columns as I have had to change the Source option to "Use Generic Column Names (parse query at runtime only)"
I will have a scout around and see how I can get around this
Gareth
Maybe you are looking for
-
My ipod 5th gen ios 7.0.6 crashed and keeps going from the apple logo, going to a black screen, back to the apple logo, then back to the black screen and so on. Furthermore, my laptop doesn't recognise that the iPod is connected. What do I do? Please
-
Black screen while installing 64 bit Windows 7 on early 2010 MBP.
Hi, I just tried doing a clean install of Windows. After partioning the hardrive my system booted into a black screen. It does not have the blinking cursor like I see on other forums. I was trying to install a 64 bit Windows 7 on my MBP Early 2010.
-
Hi, I'm using the Open/Create/Replace File.vi. I have it set up so that once the user clicks a button to start logging data, the Open/Create/Replace File.vi is called. Once this is called a window pops up asking the user where to save the file. Is th
-
Strange issue - Excel summing not done
Hi, We have a report where we have some data shown for revenue along with its Project & period . But when we export it on excel & trying summing the revenue returned we cannot. it works for some prj njum & it doesnt for few of them.. straange.. we ev
-
Community SSU in FAM catalogue
Must be doing something stupid here, no issues with catalogue listing in application manager There are no problems with apt-get upgrade but if I enter Community SSU details in FAM catalogues I just get error about either url incorrect or connection e