Conditional URL ( CASE ) within a Dynamic Query
I need extra eyes or help in RE-FORMATTING the following SELECT STMT. My approach was to formulate the following query to get a functioning URL to the page that displayed the corrections made on that record (if it was corrected)...which I did. So now I'm trying to move the CASE portion into a dynamic query report. I'm having difficulties rewriting the CASE into the dynamic query due to placement of single-quotes. Is there an easy way to do this...or do I still need to find the correct placement of quotes? HELP!
select "ID",
"EMP_ID",
"ENTRY_DATE",
"JOB_TITLE",
"START_DATE",
"END_DATE",
"MODIFIED_DATE",
"lkup_1"."DESCRIPTION" as "Status",
CASE
WHEN rec_status = 'CR' -- corrected record
THEN '<a href="'
|| 'f?p=&APP_ID.:90:&SESSION.::&DEBUG.::'
|| 'P90_RID,P90_TIMESTAMP:'
|| rid ||',' || TO_CHAR(modified_date,'MM/DD/YYYY')
|| ">'
|| 'See Update(s)'
|| '</a>'
|| '</a>'
ELSE NULL
END LINK,
"lkup_2"."DESCRIPTION" as "Action",
"CATEGORY",
apex_item.checkbox(1,rid) as "Confirm"
from "JOB_SUMMARIES",
"LOOKUPS" "lkup_1",
"LOOKUPS" "lkup_2"
where "REC_STATUS" <> 'CF'
and "REC_STATUS" = "lkup_1"."CODE"
and "ACTION" = "lkup_2"."CODE"(+)
Here is what I sort of come up with, but I'm getting dizzy looking at it so many times!
' CASE '||
' WHEN rec_status = ' || '''' || '''CR''' || '''' ||
' THEN ' || '''' || '<a href="' || '''' ||
' ||' || '''' || 'f?p=&APP_ID.:90:&SESSION.::&DEBUG.::' || '''' ||
' ||' || '''' || 'P90_RID,P90_TIMESTAMP:' || '''' ||
' ||' || ' id ||' || '''' || ''',''' || '''' || '|| TO_CHAR(modified_date,' || '''' || 'MM/DD/YYYY' || '''' || ')' || '''' ||
' ||' || '''' || ">' || '''' ||
' ||' || '''' || 'See Update(s)' || '''' ||
' ||' || '''' || '</a>' || '''' ||
' ||' || '''' || '</a>' || '''' ||
' ELSE NULL '||
' END LINK, '||
I'm still getting an error which is:
1 error has occurred
* Query cannot be parsed within the Builder. If you believe your query is syntactically correct,
check the ''generic columns'' checkbox below the region source to proceed without parsing.
ORA-00905: missing keyword
I still cannot get the insertion of the CASE to compile...I keep getting MISSING EXPRESSION error.
1 error has occurred
* Query cannot be parsed within the Builder. If you believe your query is syntactically correct,
check the ''generic columns'' checkbox below the region source to proceed without parsing.
ORA-00936: missing expression
Here is my dynamic query and I want to place the CASE as indicated. The numerous quotes or the Q syntax is really messing up my attempts to get this page working. I have a dynamic query because I am allowing search parameters. And I thought it would be nice to have a LINK to another page that displayed changed column values if a user CORRECTED one of their records. All changes must be verified and accepted by a REVIEWER.
declare
q varchar2(32767); -- query
w varchar2(4000) ; -- where clause
we varchar2(1) := 'N'; -- identifies if where clause exists
begin
q := 'select "ID", '||
' "EMP_ID", '||
' "ENTRY_DATE", '||
' "JOB_TITLE", '||
' "START_DATE", '||
' "END_DATE", '||
' "lkup_1"."DESCRIPTION" as "Status", '||
>WANT TO PLACE CASE RIGHT HERE
' "lk_up2"."DESCRIPTION" as "Action", '||
' "CATEGORY", '||
' apex_item.checkbox(1,rid) as "Confirm" '||
' from "#OWNER#"."JOB_SUMMARIES", '||
' "#OWNER#"."LOOKUPS" "lkup_1", '||
' "#OWNER#"."LOOKUPS" "lkup_2" '||
' where "REC_STATUS" <> ' || '''' || 'CF' || '''' ||
' and "REC_STATUS" = "lkup_1"."CODE" '||
' and "ACTION" = "lkup_2"."CODE"(+) ';
if :P16_EMP_ID != '-1'
then
w := ' AND EMP_ID = :P16_EMP_ID ';
we := 'Y';
end if;
if :P16_RECORD_STATUS != '-1'
then
w := w || ' AND REC_STATUS = :P16_RECORD_STATUS ';
we := 'Y';
end if;
if :P16_CATEGORY != '-1'
then
w := w || ' AND CATEGORY = :P16_CATEGORY ';
we := 'Y';
end if;
if we = 'Y'
then q := q || w;
end if;
return q;
end;
Edited by: JSandoval on Aug 10, 2009 3:42 PM
Similar Messages
-
Using CASE in a dynamic sql query
Hi,
I want to create a dynamic query using the CASE statement to replace the below 2 SQL statements:
+++++
select 'create or replace synonym '|| SYNONYM_NAME || ' for '||TABLE_OWNER||'.'||TABLE_NAME||'@'||SUBSTR(db_link,1,30)||' ;' FROM USER_SYNONYMS where db_link is not null;
select 'create or replace synonym '|| SYNONYM_NAME || ' for '||TABLE_OWNER||'.'||TABLE_NAME||' ;' FROM USER_SYNONYMS where db_link is null;
+++++
So that i have a single select query which will give the create synonym statements for all with/without db links
Using the CASE statement example like given below :
SELECT
FirstName, LastName,
Salary, DOB,
CASE Gender
WHEN 'M' THEN 'Male'
WHEN 'F' THEN 'Female'
END
FROM Employees
I am not getting how to write this CASE statement. Can someone guide me here?
Thanks,
KunwarKunwar wrote:
I am a Junior Oracle DBA. I would like to master SQL & PL/SQL concepts & tricks. Please guide me some books (apart from the oracle documentation links) which will improve my SQL & PL-SQL skills which are very weak right now. Personnally I started with the Oracle Class Training SQL&PL/SQL, then did a loooooooooooot of reading on [url http://asktom.oracle.com]AskTom (I even bought his book).
Also I tried (and I'm still trying) to answer to SQL/PLSQL problematic on this forum, then tried to see and learn from what other gave as answers.
I also spend and spent a lot of time in the Oracle Documentation. (I fear your "apart from the oracle documentation" to actually mean : apart reading the documentation)
Kunwar wrote:
TOAD alternative for create ddl statements for limited no. of objects
You need to learn to use dbms_metadata. I gave you an example, use the documentation and some self-testing to make it do what you need.
"Practice makes perfect"
And as an hint : To become a SQL & PL/SQL Master, you should first start by forgetting Toad : The real tool for learning is SQL*Plus.
Toad, as any tool, is only good in the hands of whom knows what they do and how things work. -
[SSRS] Abnormal behavior for parameter usage in checking case within query of dataset
Details :
Following error is displayed when I preview a report (SUR_EXPLORER-NG.rdl) in Microsoft Visual Studio:
“An error occurred during local report processing.
An error has occurred during local report processing.
Cannot set the command text for dataset 'GET_FDA_CONFIG_ID'.
Error during processing of the CommandText expression of dataset 'GET_FDA_CONFIG_ID'.”
Following is the query set in dataset 'GET_FDA_CONFIG_ID':
=IIF(
Parameters!IN_Dimension.Value = -1,
"SELECT -1 AS FDA_CONFIG_ID FROM DUAL WHERE :H_IN_InstanceId = :H_IN_InstanceId",
"SELECT RA_SUMM_RECON_MEASURE.FDA_CONFIG_ID AS FDA_CONFIG_ID FROM RA_SUMM_RECON_MEASURE, RA_SUMM_RECON_HISTORY WHERE RA_SUMM_RECON_MEASURE.RECON_ID
= RA_SUMM_RECON_HISTORY.RECON_ID AND RA_SUMM_RECON_HISTORY.SUMM_RECON_INSTANCE_ID = :H_IN_InstanceId"
As a trial, I change the report parameter used in the checking condition as follows (SUR_EXPLORER-OK.rdl):
=IIF(
Parameters!H_IN_InstanceId.Value = -1,
"SELECT -1 AS FDA_CONFIG_ID FROM DUAL WHERE :H_IN_InstanceId = :H_IN_InstanceId",
"SELECT RA_SUMM_RECON_MEASURE.FDA_CONFIG_ID AS FDA_CONFIG_ID FROM RA_SUMM_RECON_MEASURE, RA_SUMM_RECON_HISTORY WHERE RA_SUMM_RECON_MEASURE.RECON_ID
= RA_SUMM_RECON_HISTORY.RECON_ID AND RA_SUMM_RECON_HISTORY.SUMM_RECON_INSTANCE_ID = :H_IN_InstanceId"
Then the mentioned error message is not shown (of course I can’t get desired report generated as the logic is incorrect).
Besides, I try with other report parameters but the mentioned error message is not shown.Hi chrisd921,
According to your description, you want to do a dynamic query based on parameter select in your report dataset. Right?
In Reporting Services, if we use query to retrieve data when creating dataset, this query will only be processed one time during report processing. So we can't make it change to another query after we change the parameter selection. And we can't combine
the data from two query together in a dataset, because in a dataset, if multiple result sets are retrieved through a single query, only the first result set is processed, and all other result sets are ignored. For your requirement, it can't be achieved currently.
In this scenario, we suggest you add one more column, and put in "-1" in detail row. Then control the visibility to show either "-1" or report data.
Reference:
Report Embedded Datasets and Shared Datasets (Report Builder and SSRS)
If you have any question, please feel free to ask.
Best Regards,
Simon Hou -
Dynamic SQL within a SQL Query ?
is there any possibility to do like this ?
SELECT table_name, XXXXXXXX('SELECT Count(*) FROM '||table_name) tot_rows
FROM dba_tables
WHERE owner = 'SCOTT';or any other trick to run dynamic SQL within the SQL Query?
Hoping....that it should be.
Regards,
OrapdevOne small disadvantage: it is executing 202 SQL statements: 3 "user SQL statements" (the one above and the 2 "select count(*)..."), and 199 internal ones ...How did you get to those numbers?
I just traced this statement and found completely different results:
TKPROF: Release 10.2.0.3.0 - Production on Tue Jul 10 12:12:10 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Trace file: diesl10r2_ora_5440.trc
Sort options: default
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
declare cursor NlsParamsCursor is SELECT * FROM
nls_session_parameters;begin SELECT Nvl(Lengthb(Chr(65536)),
Nvl(Lengthb(Chr(256)), 1)) INTO :CharLength FROM dual; for NlsRecord in
NlsParamsCursor loop if NlsRecord.parameter = 'NLS_DATE_LANGUAGE' then
:NlsDateLanguage := NlsRecord.value; elsif NlsRecord.parameter =
'NLS_DATE_FORMAT' then :NlsDateFormat := NlsRecord.value; elsif
NlsRecord.parameter = 'NLS_NUMERIC_CHARACTERS' then
:NlsNumericCharacters := NlsRecord.value; elsif NlsRecord.parameter =
'NLS_TIMESTAMP_FORMAT' then :NlsTimeStampFormat := NlsRecord.value;
elsif NlsRecord.parameter = 'NLS_TIMESTAMP_TZ_FORMAT' then
:NlsTimeStampTZFormat := NlsRecord.value; end if; end loop;end;
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 0 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50
SELECT NVL(LENGTHB(CHR(65536)), NVL(LENGTHB(CHR(256)), 1))
FROM
DUAL
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.01 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 1
total 3 0.01 0.00 0 0 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50 (recursive depth: 1)
Rows Row Source Operation
1 FAST DUAL (cr=0 pr=0 pw=0 time=7 us)
SELECT *
FROM
NLS_SESSION_PARAMETERS
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 17
total 3 0.00 0.00 0 0 0 17
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50 (recursive depth: 1)
Rows Row Source Operation
17 FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=124 us)
select PARAMETER,VALUE
from
nls_session_parameters where PARAMETER in('NLS_NUMERIC_CHARACTERS',
'NLS_DATE_FORMAT','NLS_CURRENCY')
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 3
total 3 0.00 0.00 0 0 0 3
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50
Rows Row Source Operation
3 FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=57 us)
select to_char(9,'9C')
from
dual
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 1
total 3 0.00 0.00 0 0 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50
Rows Row Source Operation
1 FAST DUAL (cr=0 pr=0 pw=0 time=2 us)
SELECT table_name,
DBMS_XMLGEN.getxmltype ('select count(*) c from ' || table_name).EXTRACT
('//text').getstringval
() tot
FROM dba_tables
WHERE table_name IN ('EMP', 'DEPT') AND owner = 'SCOTT'
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.01 0.02 0 48 0 2
total 3 0.01 0.02 0 48 0 2
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50
Rows Row Source Operation
2 HASH JOIN (cr=42 pr=0 pw=0 time=2952 us)
2 MERGE JOIN CARTESIAN (cr=42 pr=0 pw=0 time=1206 us)
2 NESTED LOOPS OUTER (cr=42 pr=0 pw=0 time=478 us)
2 NESTED LOOPS OUTER (cr=36 pr=0 pw=0 time=421 us)
2 NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=379 us)
2 NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=365 us)
2 NESTED LOOPS (cr=22 pr=0 pw=0 time=312 us)
2 NESTED LOOPS (cr=16 pr=0 pw=0 time=272 us)
2 NESTED LOOPS (cr=8 pr=0 pw=0 time=172 us)
1 TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=56 us)
1 INDEX UNIQUE SCAN I_USER1 (cr=1 pr=0 pw=0 time=30 us)(object id 44)
2 INLIST ITERATOR (cr=6 pr=0 pw=0 time=111 us)
2 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=87 us)
2 INDEX RANGE SCAN I_OBJ2 (cr=4 pr=0 pw=0 time=54 us)(object id 37)
2 TABLE ACCESS CLUSTER TAB$ (cr=8 pr=0 pw=0 time=98 us)
2 INDEX UNIQUE SCAN I_OBJ# (cr=4 pr=0 pw=0 time=26 us)(object id 3)
2 TABLE ACCESS CLUSTER TS$ (cr=6 pr=0 pw=0 time=39 us)
2 INDEX UNIQUE SCAN I_TS# (cr=2 pr=0 pw=0 time=13 us)(object id 7)
2 TABLE ACCESS CLUSTER SEG$ (cr=8 pr=0 pw=0 time=37 us)
2 INDEX UNIQUE SCAN I_FILE#_BLOCK# (cr=4 pr=0 pw=0 time=21 us)(object id 9)
0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=4 us)(object id 36)
2 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=33 us)
2 INDEX UNIQUE SCAN I_OBJ1 (cr=4 pr=0 pw=0 time=23 us)(object id 36)
2 TABLE ACCESS CLUSTER USER$ (cr=6 pr=0 pw=0 time=28 us)
2 INDEX UNIQUE SCAN I_USER# (cr=2 pr=0 pw=0 time=12 us)(object id 11)
2 BUFFER SORT (cr=0 pr=0 pw=0 time=716 us)
1 FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=661 us)
1436 FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=1449 us)
select count(*) c
from
EMP
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 1 0 1
total 4 0.00 0.00 0 1 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50 (recursive depth: 1)
Rows Row Source Operation
1 SORT AGGREGATE (cr=1 pr=0 pw=0 time=96 us)
14 INDEX FULL SCAN EMP_IDX (cr=1 pr=0 pw=0 time=46 us)(object id 61191)
select metadata
from
kopm$ where name='DB_FDO'
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 2 0 1
total 3 0.00 0.00 0 2 0 1
Misses in library cache during parse: 0
Optimizer mode: CHOOSE
Parsing user id: SYS (recursive depth: 1)
Rows Row Source Operation
1 TABLE ACCESS BY INDEX ROWID KOPM$ (cr=2 pr=0 pw=0 time=42 us)
1 INDEX UNIQUE SCAN I_KOPM1 (cr=1 pr=0 pw=0 time=22 us)(object id 365)
select count(*) c
from
DEPT
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 1 0 1
total 4 0.00 0.00 0 1 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 50 (recursive depth: 1)
ALTER SESSION SET sql_trace=FALSE
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Parsing user id: 50
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 5 0.00 0.00 0 0 0 0
Execute 5 0.00 0.00 0 0 0 1
Fetch 3 0.01 0.02 0 48 0 6
total 13 0.01 0.03 0 48 0 7
Misses in library cache during parse: 0
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 5 0.00 0.00 0 0 0 0
Execute 5 0.01 0.00 0 0 0 0
Fetch 7 0.00 0.00 0 4 0 21
total 17 0.01 0.00 0 4 0 21
Misses in library cache during parse: 0
9 user SQL statements in session.
1 internal SQL statements in session.
10 SQL statements in session.
Trace file: diesl10r2_ora_5440.trc
Trace file compatibility: 10.01.00
Sort options: default
1 session in tracefile.
9 user SQL statements in trace file.
1 internal SQL statements in trace file.
10 SQL statements in trace file.
10 unique SQL statements in trace file.
132 lines in trace file.
0 elapsed seconds in trace file.I only see a ratio of 1:9 for user- to internal SQL statements?
michaels> select * from v$version
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production -
I have followed the tutorial in on dynamic query and created a region where the type is SQL Query (PL/SQL function body returning SQL Query)
The source is
declare
q varchar2(4000);
teatid NUMBER := :P305_TARGET_ID;
begin
wwv_flow.debug('teatid = ' || teatid);
q:=' select f.id, ';
q:=q||' f.eat_id ';
q:=q||' from xmlTransactions f ';
q:=q||' where f.eat_id = ' || teatid; -- I've also tried putting :P305_TARGET_ID here
wwv_flow.debug('sql = ' || q);
return q;
end;
I have chosen "Use Generic Column Names...".
When I run the page, I get NO ROWS FOUND. However, when I cut and paste the SQL statement printed out by the debug statement and run it, it returns rows. Both debug statements print correct values.
I'm not sure what the problem is here, but basically, I want to do a query where I substitute a value passed into the page from another page.
In this case the value in P305_TARGET_ID is passed in via a button spawning a popup as in var url = 'f?p=&APP_ID.:305:&APP_SESSION.::::P305_TARGET_ID:' + targetID;
APEX version is 3.0.1.00.08
Thank you.
- JohnWHi, JohnW
I don't understand why you use a dynamic query for that.
A "direct" SQL query like this :
select f.id,f.eat_id from xmlTransactions f where f.eat_id=:P305_TARGET_ID;
should work.
Mike -
Dynamic Query and default run-time values
I am trying to build a dynamic query within dreamweaver and
retain access from the bindings panel.
here is a simple pseudo-query I want to expand on.
"SELECT object FROM objects_table WHERE widget_number =
widgets"
widgets is set up as a variable with a run-time value that
relates to $_GET['widgets']
this works fine but now i want to expand on this so the query
returns all results if $_GET['widgets'] is undefined. I was hoping
I could set the default value for widgets to equal widget_number so
I would get....
"SELECT object FROM objects_table WHERE widget_number =
widget_number" but the runtime query is actually
"SELECT object FROM objects_table WHERE widget_number =
'widget_number' " which obviously doesn't work.
I can alter the query manually from the code view but then I
lose access to the bindings panel as dreamweaver doesn't parse the
query properly.
Any pointers?
Thanks in advance
- AndrewAndy Millne wrote:
> That will work fine server-side yeah but dreamweaver
cannot parse the code at
> design time so by altering the code in this way you lose
access to the bindings
> panel and all the server behaviours that depend on the
recordset have
> exclamation marks alongside.
This is simply a question of organizing your workflow. As you
have
discovered, Dreamweaver no longer recognizes a recordset if
you make
changes to the basic structure of the code. The answer is to
use
Dreamweaver to construct your page using an unaltered
recordset. Once
the design stage is complete, make the changes required by
inserting
your conditional statement. Yes, the fieldnames disappear
from the
Bindings panel, and you get exclamation marks in the Server
Behaviors
panel, but that's not important. If you need to restore them
for any
reason, just wrap the changes in /* */ comments. Remove the
comments
when you have finished.
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
Using jquery FullCalendar in APEX with dynamic query
Hi,
I am trying to implement jquery FullCalendar in APEX and came across thie following post but I am unable to get the events to work. I would really like to see it working with an Application_Process:
How we can highlight events in Calendar
Currently I created an Application Process that simply calls a DB table and convert it into json format.
DECLARE
v_sql varchar2(400);
BEGIN
v_sql := 'SELECT * FROM CAL_FEED';
apex_util.json_from_sql(v_sql);
END;
But I am unsure how to add the events via an Application_Process.
I have tried the following in numerious ways (events:function, url feed, etc). It does work if I just do an array but would like it as a dynamic query.
$('#calendar').fullCalendar({
events: "http://server:8080/apex/f?p=101:53:4352610578859707:APPLICATION_PROCESS=IAT_TEST_CAL_FEED"
Thank you in advance,
JimmyHi,
I was able to get the events into Fullcalendar with an Application Process but not sure if this would scale well with alot of events.
Would someone be able to tell me if there is a better way?
I am currently using an On Demand Application Process called IAT_TEST_FEED:_
DECLARE
lv_cal_list VARCHAR2(16000);
lv_return_str VARCHAR2(32000);
BEGIN
FOR i IN (SELECT "CAL_FEED"."ID" as ID,
"CAL_FEED"."title" as caltitle,
"CAL_FEED"."start" as calstart,
"CAL_FEED"."end" as calend
FROM "CAL_FEED")
LOOP
lv_cal_list := lv_cal_list || '{"id":' || CHR(39) || i.ID || CHR(39) || ',' ||
' "title":' || CHR(39) || i.caltitle || CHR(39) || ',' ||
' "start":' || CHR(39) || i.calstart || CHR(39) || ',' ||
' "end":' || CHR(39) || i.calend || CHR(39) || '},';
END LOOP;
lv_return_str := '[' || RTRIM(lv_cal_list,',') || ']';
htp.prn(lv_return_str);
EXCEPTION WHEN OTHERS THEN
htp.prn('error');
END;
In a HTML Region on a page within the Region Header:_
<link rel="stylesheet" type="text/css" href="#WORKSPACE_IMAGES#fullcalendar.css" />
<script type="text/javascript" src="#WORKSPACE_IMAGES#ui.core.js"></script>
<script type="text/javascript" src="#WORKSPACE_IMAGES#ui.draggable.js"></script>
<script type="text/javascript" src="#WORKSPACE_IMAGES#ui.resizable.js"></script>
<script type="text/javascript" src="#WORKSPACE_IMAGES#jquery.js"></script>
<script type="text/javascript" src="#WORKSPACE_IMAGES#fullcalendar.js"></script>
<script type="text/javascript" src="#WORKSPACE_IMAGES#fullcalendar.min.js"></script>
<script type='text/javascript'>
$(document).ready(function() {
$('#calendar').fullCalendar({
events: function(start, end, callback) {
$.ajax({
type: "POST",
url: "wwv_flow.show",
dataType: "json",
data: {
p_flow_id:$('#pFlowId').val(),
p_flow_step_id:$('#pFlowStepId').val(),
p_instance:$('#pInstance').val(),
p_request:"APPLICATION_PROCESS=IAT_TEST_FEED"
success:function(calevents){
$.each(calevents, function(i, calevent){
$('#calendar').fullCalendar('renderEvent', calevent, true);
</script>
The line within the ajax call is basically where my concern would be
$('#calendar').fullCalendar('renderEvent', calevent, true);
Thank you,
Jimmy -
Dynamic query configuration in sender jdbc adapter
Hi,
According my undertsnading in XI.3.0 dynamic query in sender JDBC adapter is not possible.
could any one confirms the possibility of this feature in XI 7.0 .
Thanks,
venuHi VJ,
sorry for late responding to your answer.
One of our requirements is the query statement that we write in sender communication channel should be changed dynamically, for example in where condition the condition parameters values required to change.
Thanks,
venu -
How to enhance Dynamic Query Object TerrSearch (Territory Management)?
Hello Friends,
In the TerrSearch dynamic query object, There are 2 fields Territory_ID and Level_ID. Now i have a requirement to Enhance the Search object using the new field called TERRITORY PATH ID. using which we can search all the entities not only for the terrritory level which we have selected (for example we have assigned the value '01' to LEVEL_ID) but also all the below territory levels of selected territory level.
If we enhance the search object structure CRMST_TMIL_SEARCH (structure of TerrSearch object) using AET to add the Z field called TERRITORY_PATH_ID then which is the suitable BADI where we can add the necessary code to select all the entities based on all the territory levels below the selected territory level.
Please guide me friends how to enhance the TerrSearch object.Hi friend,
Try using MACRO and dynamic WHERE condition.
Group simialr Select statements under a Macro.
Build a dynamic where by checking conditions
Call macro passing dynamic where condition.
TABLES afpo.
DATA: str TYPE string.
*Macro definition
DEFINE operation.
select single *
from afpo into afpo
where (&1). " Dynamic condition
END-OF-DEFINITION.
*Build dynamic WHERE by checking some conditions
*If conditon
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
*Else
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
*Endif.
*Call Macro passing dynamic WHERE condition
operation str. -
How to create a dynamic query in which I can vary number of parameters
I am writing a JDBC connector. I want to write a dynamic query in that. The query should be able to proceed variable number of parameters and also in the where clause the and/or/like parameters I want to place dynamically.
I can't write store procedures as we just have read only access to Database so I want to do it through query only.
Please help me out in doing that as I am not able to proceed further without it ...Hi,
Have a luk at :placeholder for IN condition in database adapter -
Unable to retrieve results using dynamic query
Hi Experts,
I have created a custom table and have created a custom bol to integrate it with web ui. I have redefined the dynamic query result method of genil layer. I find the data into LT_RESULT but when I invoke the root list method the LR_OBJECT does not contain the values.
Please see below the code that I have written.
====================================
METHOD IF_GENIL_APPL_INTLAY~GET_DYNAMIC_QUERY_RESULT.
DATA: LR_OBJECT TYPE REF TO IF_GENIL_CONT_ROOT_OBJECT,
LT_RESULT TYPE TABLE OF ZCRMST_XXXX,
LV_DYN_WHERE TYPE STRING,
LV_LEN TYPE I,
LS_RANGE TYPE SELOPTOBJ.
DATA: LT_XXXX TYPE TABLE OF SELOPTOBJ,
LT_YYYY TYPE TABLE OF SELOPTOBJ.
FIELD-SYMBOLS: <LFS_RESULT> TYPE ZCRMST_XXXX,
<LFS_SELECTION_RANGE> TYPE GENILT_SELECTION_PARAMETER.
decomposition of selection parameters and build a dynamic where condition
SELECT * FROM ZXXXX INTO TABLE LT_RESULT[].
CHECK LINES( LT_RESULT[] ) > 0.
LOOP AT LT_RESULT[] ASSIGNING <LFS_RESULT>.
LR_OBJECT = IV_ROOT_LIST->ADD_OBJECT( IV_OBJECT_NAME = 'Root'
IS_OBJECT_KEY = <LFS_RESULT>-XXXX ).
CHECK LR_OBJECT IS BOUND.
LR_OBJECT->SET_QUERY_ROOT( ABAP_TRUE ).
ENDLOOP.
ENDMETHOD.
==================================================
Thanks in advance,Hi,
Please check your get_objects method of the genil class. I made some changes to my implementation of get_objects method and it fixed the problem.
Regards,
Sandeep -
Receiver HTTP Adapter Dynamic Query String
Hello,
I am using HTTP Adapter on receiver side.
My URL is <b>http://server:port/abc/def?xyz=123&luw=345</b>
When I am using Adapter specific attributes.
If I check apply Parameters and pass
Parameter 1 as xyz and Parameter 2 as luw and pass their values through dynamic configuration will they get appended to the dynamic querystring
http://server:port/abc/def at the end and I get back the complete URL.
Can this be achieved? I am stuck on this.
Regards,Srihari,
The best way to debug this and check what is happening would be to use the TCP gateway tool as shown in this blog by Stefan Grube.
/people/stefan.grube/blog/2007/03/29/troubleshooting-soap-http-and-mail-adapter-scenarios-with-tcpgateway
Send the request to the TCP gateway and forward it from there to the correspionding target.
You will be able to see the URL being passed including the Query String parameters.
Regards
Bhavesh -
How to use dynamic query for this ??
hi , i am new to ABAP. i got a requirement to write dynamic query for the following code.
kindly address. two set of queries are same.but condition is different.
.IF p_psd EQ ' '.
*C--End of change DF 1232137- (Transport # :CIDK980530 )
*C--FETCH THE Deliverd Quantiity and Material Number
SELECT aufnr "ORDER number
wemng "Quantity of goods received for the order item
matnr "MATERIAL NUMBER
pwerk "PLANT
dauat "Order Type
FROM afpo
INTO TABLE t_afpo
WHERE aufnr IN s_order
AND wemng IN s_dqt
AND matnr IN s_matnr
AND pwerk IN s_plant
AND dauat = c_ro.
IF sy-subrc = 0.
SORT t_afpo BY aufnr matnr pwerk.
*C--FETCH THE OBJECT NUMBER
SELECT aufnr "ORDER number
objnr "Object number
FROM aufk
INTO TABLE t_aufk
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr.
IF sy-subrc = 0.
SORT t_aufk BY aufnr objnr.
*C--FETCH THE Target Quantiity
SELECT aufnr "ORDER number
gamng "Total order quantity target quantity
FROM afko
INTO TABLE t_afko
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr
AND gamng IN s_tqt.
IF sy-subrc = 0.
SORT t_afko BY aufnr .
ENDIF.
ENDIF.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
*C--Begin of change DF 1232137- (Transport # :CIDK980530 )
ENDIF.
IF p_psd EQ c_x.
SELECT aufnr "ORDER number
wemng "Quantity of goods received for the order item
matnr "MATERIAL NUMBER
pwerk "PLANT
dauat "Order Type
FROM afpo
INTO TABLE t_afpo
WHERE aufnr IN s_order
AND wemng > 0
AND matnr IN s_matnr
AND pwerk IN s_plant
AND dauat = c_ro.
if sy-subrc = 0.
*C--FETCH THE OBJECT NUMBER
IF NOT t_afpo[] IS INITIAL.
SORT t_afpo BY aufnr matnr pwerk.
SELECT aufnr "ORDER number
objnr "Object number
FROM aufk
INTO TABLE t_aufk
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr.
IF sy-subrc = 0.
SORT t_afko BY aufnr gamng.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
IF NOT t_afpo[] IS INITIAL.
*C--FETCH THE Target Quantiity
SELECT aufnr "ORDER number
gamng "Total order quantity target quantity
FROM afko
INTO TABLE t_afko
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr
AND gamng <> t_afpo-wemng .
IF sy-subrc = 0.
SORT t_afko BY aufnr gamng.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
Edited by: Thomas Zloch on Jan 5, 2011 1:30 PM please use code tagsHi friend,
Try using MACRO and dynamic WHERE condition.
Group simialr Select statements under a Macro.
Build a dynamic where by checking conditions
Call macro passing dynamic where condition.
TABLES afpo.
DATA: str TYPE string.
*Macro definition
DEFINE operation.
select single *
from afpo into afpo
where (&1). " Dynamic condition
END-OF-DEFINITION.
*Build dynamic WHERE by checking some conditions
*If conditon
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
*Else
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
*Endif.
*Call Macro passing dynamic WHERE condition
operation str. -
Parenthesis within a select query.
I have a doubt as whether i can include Parenthesis within a select query
as below:-
SELECT C.CITY_CODE,A.DOCUMENT_TYPE,SUM(A.INSTRUMENT_AMounT) FROM
ppbs_RECEIPT_HEADER A,ppbs_DISTRIBUTOR_MASTER C WHERE
A.DISTRIBUTOR_ID = C.DISTRIBUTOR_ID AND
( A.STATUS not in( 'CN','BO') or (A.STATUS ='CN' and a.INSTRUMENT_AMOUNT<>a.UNAPPLIED_AMOUNT))
as we do in a If condition. Please help in solving the doubt as it is urgent.No, the result is correct, but is it correct to put the parenthesises around a condition in a normal select query as we do in a 'if' condition or a sub-query. Will the condition in the query be evaluated first and then the other conditions in the normal select query.
-
How to create custom BOL object for dynamic query in CRM 7.0
Hi,
Could anyone please explain me with steps that how to create the custom BOL object for dynamic query in CRM 7.0, I did it in previous version but its throwing exception when i try to create the object of my dynamic query class. I just defined the entry of my in crmv_obj_btil to create the dynamic query BOL object. do i need to do any other thing also to make it work?
Regards,
Kamesh Bathla
Edited by: Kamesh Bathla on Jul 6, 2009 5:12 PMHi Justin,
First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
Thanks in Advance,
mallikj2.
Maybe you are looking for
-
Error in goods receipt with PO
Hi experts, I am getting the following error,when trying goods receipt with Purchase Order using BAPI_GOODSMVT_CREATE. "No goods receipt possible for pruchase order XXXXXX". What may be the reason for this,its urgent please help. Thanks & Regards K
-
HI, I get the "ORA-02049: timeout: distributed transaction waiting for lock" error message when i run the query it works fine when i run it in pl/sql developer but in apex.... no bueno what does this error mean and how can i fix it??? select a.object
-
Hi, Is it possible to link from one tab to another in the same set? For instance, could I link from a text object inside one tab to the content of another tab? Thanks. Barbara
-
Error while doing Intercompany billing
Dear All, When i am doing Intercompany Billing , system is giving me error " Sales Organisation is Not Defined". I have completed the entire sales process, but while doing this Intercompany billing , i am getting this error. I am trying to do this by
-
Attributes...Help with displaying File Type Icons
I have a document area folder(s) that content managers can upload files into. I know that they can place an image with these files by using the secondary tab, BUT, my question is this.... Is there a way to have the portal identify what type of file t