Substitution strings in chart sql query
Hi Guys,
I am creating line charts and bar charts based on a query in HTML DB 1.5. I am using substitution strings in the query. Though I can use substitution strings in the line chart, I cannot do it in the bar chart. I am using almost the same sql query in both line and bar charts.
The sql query in line chart is
SELECT null, TO_CHAR(t1.extract_date, 'W-MON-YYYY') extractdate,
MIN_OF_AVERAGES(AVG(&P40_METRICS.),:P40_REGION_LIST,:P40_SUBREGION_LIST,NULL,:P40_METRICS,'ind') orgid
FROM ind t1,geography t2
WHERE t1.country_id = t2.country_id(+)
AND t2.region_name like
DECODE(:P40_REGION_LIST,'ALL REGIONS','%',:P40_REGION_LIST)
AND t2.subregion_name like
NVL(:P40_SUBREGION_LIST,'%')
GROUP BY TO_CHAR(extract_date, 'W-MON-YYYY')
order by to_date(extractdate,'DD-MON-YY')
The sql query in bar chart is
SELECT null, TO_CHAR(t1.extract_date, 'W-MON-YYYY') extractdate,AVG(&P40_METRICS.) orgid
FROM ind t1,geography t2
WHERE t1.country_id = t2.country_id(+)
AND t2.region_name like
DECODE(:P40_REGION_LIST,'ALL REGIONS','%',:P40_REGION_LIST)
AND t2.subregion_name like
NVL(:P40_SUBREGION_LIST,'%')
GROUP BY TO_CHAR(extract_date, 'W-MON-YYYY')
order by to_date(extractdate,'DD-MON-YY')
The min_of_averages function in the line chart query is some function I am calling. Even if I cut-paste the line chart query in the bar chart I get the error.
The substitution string which is giving the problem is "&P40_METRICS."
The error I am getting is
Query cannot be parsed, please check the syntax of your query. (ORA-00909: invalid number of arguments)
The only difference I see is that line chart query is inside a series and bar chart is not, does this make a difference??? Or is it because I am using the substitution string in choosing the column??? Please help!!!!
Thanks,
Swaroop
Swaroop,
You might be using an HTML bar chart and an SVG line chart, I can't tell, but their implementations differ. You won't be able to use a substitution string to replace a column name in the query in the situation you found, you'd have to figure out a way to construct the query string before it gets executed and I'm not sure the chart pages will let you do that.
Scott
Similar Messages
-
Passing a string into an SQL query IN statement
Hello,
I need to connect to a database to pull some data to dynamically create a form based on the data I pull back. My SQL query works fine when I manually run it through a SQL client tool, but when I try to pass it through my workflow I'm having trouble with passing my string into the IN part of the statement. So if for example my SQL query is:
SELECT Field1, Field2, Field3 FROM Table1 WHERE Field4 IN (?)
I have a process variable that has the string I'm trying to pass into the ?, but I don't seem to be able to get the query to run. I have tried setting up my query to run as a Parameterized Query (passing my string process variable into the ?), and by setting the query up through xPath (where I am calling my process variable with an xPath declaration), but am not having any luck.
The process variable I am trying to pass is formatted such that I'm passing 'Value1','Value2','Value3' but I can reformat this string if need be. Even with using test data I can't get the query to return anything. For test data I have tried: 'Value1','Value2','Value3' ; Value1','Value2','Value3 ; Value1,Value2,Value3 but the query never returns any data. I can't seem to see how to format the string to pass into the query. The Query will work with a single Value in the test data, but as soon as I try to pass multiple values within the string it fails. Any suggestions?The problem looks to be a limit on what I can pass into the SQL query component. My string is coming from data returned from another database. I take the xml output from that database call, pass it through a set variable component to remove my xml tags from the string, and then format the string in a script component (I have to do it this way because of the way the data coming out of my first database call). I've put in loggers, and can see that the string I'm passing into my query that is giving me problems, is formatted the same way as if I were to use the concat function Scott listed above. It looks like there is a limitation on what can be passed in my variable. I have tried creating my entire SQL query statement in a set variable component, and then just calling the process variable that holds that statement, but there is a character limit of 128 character for what can be passed in a variable through xpath in the SQL query component.
The next thing I tried was changing my SQL where clause. Instead of passing my variable directly into the IN statement I set up a PATINDEX('%:'+countyname+ ':%', ?) > 0 call to check for the values in my database call. As you can see I took out the "," that I was passing as part of my string, thinking that the SQL component was getting confused by them, and placed ":" characters around my values being passed in my string variable. No matter what I try to do though I'm not able to get the query to run. The component looks like it is taking my string, and is seeing the whole thing as a string instead of passing it as individual values within a string.
I think I'm getting close, but I keep getting a Content not allowed in prolog exception in the server logs. -
Substitution string inside PL/SQL generated content (single column source)
Hi! I have a contents table that contains the HTML source (using the HTML Editor Standard item) stored on a single varchar2 column like this.
-- some other HTML source here ---
href="f?p=&APP_ID.:17:&APP_SESSION."
-- other HTML source here --
(Sorry, this forum is parsing my HTML source but it's just as simple as that)
I'm using a PL/SQL Dynamic Content region to select and display my contents using the htp.p procedure. But the problem is the built-in substitution strings in the URL of my content is just displayed as it is. I know that this maybe because htp.p will treat the parameters just like a regular string and the Application Express Engine don't have a chance to parse it. But can somebody show me an alternative solution for this?
Right now, I'm just using a static HTML region as a temporary solution. But I really am curious on how can this be done using PL/SQL dynamic content region. Or what design is best on content management-like application.
Thanks!
MertzMertz,
I'm not sure I understand but say your database table's column contains 'Hello the session id is &APP_ID. ...'. Using a PL/SQL region you could emit that column thus:for c1 in (select content_col from content_tab) loop
htp.p(replace(c1.content_col, '&' || 'APP_ID.', :APP_ID));
end loop;Splitting up the substitution item name into concatenated strings avoids problems with the Builder doing substitutions when you don't want it to.
Scott -
Cluster bar chart- sql query please help-
Hi,
I am trying to create cluster bar chart and am stumped with this sql query.Any help is appreciated.
Here is my table
city region issue value
c1 north i1 y
c1 north i2 y
c2 north i1 n
c2 north i2 y
c3 south i1 y
c3 south i2 n
c4 east i1 n
c4 east i2 n
The bar chart will have 3 series, north south and east.
And labels will be i1 and i2. value will be number of times this issue was encountered(y) in this region.
How can I get something like this from the above table-
region issue count(yes)
north i1 1
north i2 2
south i1 1
south i2 0
east i1 0
east i2 0
thanksWITH table1 AS
(SELECT 1435177 qte_id, 2 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no
FROM dual
table2 AS
SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
FROM dual
SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
FROM
(SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
FROM table1 t1, table2 t2
WHERE t2.qte_id = t1.qte_id (+)
AND t2.seq_no = t1.seq_no(+)
ORDER BY 1,2
WHERE t1_seq_no IS NOT NULL
ORDER BY 1,2
QTE_ID T2_SEQ_NO DIFF
1435177 2 0
1435177 5 0
1435177 7 0
1435177 8 0
1435177 12 0
1435177 14 0 -
Need to return CLOB as String type from SQL query
I have a table that contains a CLOB column, which should be accessible to a JDBC client (JReports) that does not understand how to extract CLOB from a result set.
A possible workaround would be to translate the CLOB type into a normal string on the database side as part of the SQL query (or a view), so that the client can handle it. For that to work, we would need a type conversion within the query itself.
Rather then
SELECT clob_column FROM my_table
we would need something like
SELECT to_char(clob_column) FROM my table
Unfortunately to_char does not work, but possibly there are other ways to achieve it.
nullHi Christo
Works fine. Just had to change the parameter order:
DBMS_LOB.substr(clob_column,4000,1) converts the CLOB to a VARCHAR
Thanks a lot,
Thomas
null -
Replacing a set of characters from a string in oracle sql query
I want to replace a set of characters ( ~ ! @ # $ % ^ * / \ + : ; | < > ? _ ,) from a STRING in sql
select 'TESTING ! ABC 123 #'
FROM DUAL;
What is the best way to do it? Please provide examples also.What is your expected output... The query I posted just removes them, it never replaces them with spaces..your string already has space.. if you want to remove space as well .. try this...
SELECT TRANSLATE ('TESTING ! ABC 123 #', '-~!@#$%^*/\+:;|<>?_, ', ' ') FROM DUAL;
Output:
--TESTINGABC123
Else post your expected output..
Cheers,
Manik. -
How to reference template substitution string in PL/SQL condition
hi -- I need to conditionally display an item based on the value of #TITLE#. I'm currently trying a pl/sql expression function body returning boolean
DECLARE
page_type VARCHAR2(1000);
BEGIN
page_type := lower(substr(:TITLE,instr(:TITLE,'Query')));
if (page_type = 'query') then
return TRUE;
else
return FALSE;
end if;
END;
There are no errors, but the condition is not being met when it should be.
I tried setting some app items to the value of #TITLE# and I'm obviously not referencing it correctly; they're all null:
:TEST_VALUE := &TITLE.;
:TEST_VALUE2 := :TITLE;
:TEST_VALUE3 := V('TITLE');
Help?
Thanks,
CarolHi,
You can use javascript on page HTML header
<script>
function getDocTitle(pItem){
$x_Value(pItem, document.title);
</script>And page body
onload=" getDocTitle('Px_YOUR_ITEM');"Br, Jari -
Footer navigation using pl/sql - substitution strings
Hi
I want to make a footer navigation (a BLAF like footer with the same captions and links that appear in the Tabs and the Navigation Bar) using a PL/SQL region. The code I want to use should work for any HTML DB application.
The procedure could be defined like this:
PROCEDURE prb_footer_navigation( p_application_id VARCHAR2
, p_page_id VARCHAR2
, p_session_id VARCHAR2);
p_application_id will be used to get the caption and links of the specific application and p_page_id will be used to know which tab is selected.
I'm using this query in the procedure:
SELECT t.tab_text caption
, t.tab_target link
, t.tab_sequence num
FROM flows_010600.wwv_flow_toplevel_tabs t
WHERE t.flow_id = p_application_id
ORDER BY t.tab_sequence
(the user has been granted select from flows_010600.wwv_flow_toplevel_tabs)
The problem is:
tab_target has substitution strings like '&XXX.' or '&PX_XXX.', so how can I get the real link with resolved substitution strings using pl/sql?
Something like function_resolve_string(p_string, p_session_id) would be appreciated...
Thanks in advance!A.U.,
Have you considered looking at how the navigation bar gets onto your page by examining the page template? You'll find something like this in the body section:
<table width="100%" cellpadding="0" cellspacing="0" border="0" summary="">
<tr>
<td valign="top" class="t1Logo">#LOGO#</td>
<td align="right" valign="top">#NAVIGATION_BAR#</td>
</tr>
</table>Just copy and paste that onto the end of the body section, or into the footer section of the template, although the footer might not support all the same substitution patterns.
If that's the kind of result you have in mind, do the same thing for the (html) tables that contain #PARENT_TAB_CELLS# and #TAB_CELLS#. I don't guarantee this will work, but it's worth experimenting with.
Scott -
Need Help in Splitting a String Using SQL QUERY
Hi,
I need help in splitting a string using a SQL Query:
String IS:
AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
Sample Output should look like:
SNO STRING
1 AFTER PAINT
2 ACOUSTICAL
3 1
4
5 9" MEMBRAIN
{code}
FYI i am using Oracle 9.2There's this as well:
with x as ( --generating sample data:
select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
select str,
row_number() over (partition by str order by rownum) s_no,
cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
from x,
table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
STR S_NO RES
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 1 AFTER PAINT
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 2 ACOUSTICAL
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 3 1
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 4
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 5 9" MEMBRAIN
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 1 BEFORE PAINT
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 2 ELECTRIC
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 3 2
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 4
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 5 45 caliber MEMBRAIN
{code} -
Can substitution strings be used for table name references?
Hi,
I was wondering if it's possible to use substituion strings for table names in SQL queries. This would allow for me to edit all references to a table at one location. For instance, if a table name or dblink changed, I could edit the substitution string or application item to ensure all the queries reference the new table.
For example:
select * from &table1.
table1 would be the substitution string for the actual table name
I know this is possible if I used a pl/sql function returning a query, but I would much rather use a substition string in a SQL query.
Thanks in advance.
Briani think not
because how create the fields of * in this case
in the other because all is dynamic, i think that you obtain only an error -
MAKING A SQL QUERY WITH LIKE SINTAX
Im trying to make a string with a sql query.
the object is return a select statement in the var string and the select statement must be return a string like that :
select item1, item2, item3 from table where
item1 like '%PEPE%' and item2 like '%COSA2%';
then I make a string like that :
lq_sql := 'select item1, item2, item3 from table where item1 like '||'%'||:P1_NOMBRE||'%'
but this give errors.
Any help? thanks in advanced and regards everybody.Hello,
If you check your statement in sql*plus this is how it will look like:
select 'select item1, item2, item3 from table where item1 like '||'%'||&P1_NOMBRE||'%' txt
from dual
Enter value for p1_nombre: 3
result:
TXT
select item1, item2, item3 from table where item1 like %3%
***You are missing single quotes before and after the % statement, as follows:
select 'select item1, item2, item3 from table where item1 like '||'''%'||&P1_NOMBRE||'%''' txt
from dual
Enter value for p1_nombre: 3
result:
TXT
select item1, item2, item3 from table where item1 like '%3%'BTW, i changed colon (:) to ampersand (&) to run it in SQL*plus but it should be a colon.
-Marilyn -
Having troubles passing values of Shuttle control to SQL Query of Report and Chart Region
Hello,
I am very new to APEX and need help for one of the Pa.I have a shuttle control on my page which populates Categories. Once user selects Categories from this control, I wish to pass the values to following SQL query :
select * from emp_class where category IN ( LIST of VALUES FROM RIGHT SIDE SHUTTLE).
I tried various ways of doing this including writing a java scripts which reads shuttle value, converts it into below string
'Category1',Category2',Category3'. Then I set this value to a text box. And then I was expecting that below trcik would work
select * from emp_class where category IN (:TXT_VALUES)
I am sure this is not right way and hence its not working. Can you please guide me here with options?
Many Thanks,
Tushb96402b4-56f7-44ba-8952-fb82a61eeb2c wrote:
Please update your forum profile with a real handle instead of "b96402b4-56f7-44ba-8952-fb82a61eeb2c".
I am very new to APEX and need help for one of the Pa.
Don't understand what this means. What is "Pa"?
select * from emp_class where category IN (:TXT_VALUES)
I am sure this is not right way and hence its not working. Can you please guide me here with options?
This is a common fallacy. In
select * from table where columnvalue in (7788, 7839, 7876)
(7788, 7839, 7876) is an expression list and the predicate is evaluated as a membership condition.
In
select * from table where columnvalue in :P1_X
:P1_X is a scalar string, incapable of containing multiple values.
In an APEX standard report, a PL/SQL function body returning an SQL query report source with lexical substitution can be used to produce a "varying IN-list":
return 'select * from table where columnvalue in (' || :P1_X || ')';
where P1_X contains fewer than 1000 values, has been sanitized for SQL injection, and string values are properly quoted.
Some people suggest the following approach, which will also work in APEX interactive reports:
select * from table where instr(':' || :P1_X || ':', ':' || columnvalue || ':') > 0
However this is non-performant as it eliminates the possibility of the optimizer using indexes or partition pruning in the execution plan.
See varying elements in IN list on Ask Tom, and emulating string-to-table functionality using sql for efficient solutions. -
Using a SQL Query in an Alert and Matching a String
I've created an alert in 12.0.4 using a SQL Query and the field that I'm trying to match is a string. Originally the query returned multiple rows but when the alert still didn't fire, I modified the query WHERE clause to return only one row:
NAME RESPONSE
Are area lights working? No
My expression in the metric is RESPONSE. In the Monitor I'm matching a string equal to No. (Do I need double quotes around the matchvalue? Single quotes? No quotes?) The metric is in the 15min scan group, the role is xMII Developers and I'm in that role. The monitor alert string is ' = '. Both metric and monitor are active and I've subscribed to the monitor. Other alerts in the 15min scan group (all based on tag queries) are firing off properly.
Why is nothing showing up in the Alert Log?
David MacindoeDavid,
Did you figure out the answer? If not, I will try to find someone to address your question.
Mike -
I am trying to execute the following SQl query, SELECT * FROM Failure WHERE ID = '123' AND RepairAction = ' ';, using the DB Tools Execute Query.vi. This query never finds the record in my database. My database contains a record where the ID filed contains the value of '123' and the RepairAction field is an empty string. If I remove the 'AND RepairAction ' ';' text from my query statement, the record is found. I believe my problem is that I am not using the correct syntax to describe and empty string. I have tried the following: '', ' ', "", " ", and NULL as empty string arguments, and none of these work.
I was hoping someone might be able to tell me what the correct syntax is for an empty string or if there is another approach I need to take.
Thank you in advance for your help,
Jim
Solved!
Go to Solution.Hi,
While creating your table "Failure", was the column "ID" delclared as intiger or varchar? If it is intiger and you use '123' , it wont return the results. You will have to try without the inverted comas ' '.
Regards,
Nitzz
(Giver Kudos to good Answers, Mark it as a solution if your problem is Solved) -
How to pass a string value from XL sheet cell to SQL query.
Hi,
I am using SQL query in XL sheet to fetch some data. for that i am using ODBC connection. Now I want to pass a string from XL sheet Cell value in the where clause of Select statement, Please let me know how to do this.
Below is My code:
nge("A4").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER={Microsoft ODBC for Oracle};UID=xyz;PWD=xyz;SERVER=xyz;" _
, Destination:=Range("A4"))
.CommandText = Array( _
"SELECT CRYSTAL_REPORT1.PROJECT, CRYSTAL_REPORT1.OBJECT" & Chr(13) & "" & Chr(10) & "FROM NAIODEV.CRYSTAL_REPORT1 CRYSTAL_REPORT1" _
.Name = "Query from gg"
Thanks,
PriyaWhat does "XL" (whatever that is) have to do with Crystal Reports which is what you are obviously working with have to do with the Oracle database?
The rules for using Crystal with Oracle are quite clearly described in all the Crystal Reports docs ... you MUST use IN OUT ref cursors unless you are doing direct table or view access.
Maybe you are looking for
-
Dear Gurus, Please help on the below issue.I had made standard release for payment configuration and assigned the workflows.When am doing vendor invoice work flow is triggering but getting an error. Error in workflow Customizing of payment release Me
-
Spry Horizontal Menu Submenus Won't Appear - Help
OK, I have a Spry Horizontal Menu Bar done through DW CS5. The root menu items work just fine. And the arrow graphics indicating there are submenus are shown, however when you hover over the main menu item the submenus do not appear in browser previe
-
Application builder (using OpenG source)
I just made a LV program and executable thing in LV8.2.0. Only one function (for converting cluster->ini) from OpenG was used to make the program easily. When I copy the program folder, so many OpenG (maybe related to the converting routine) codes we
-
Cannot Download Podcasts - iTunes 10.5.1 x64
Good Morning All - For the past few days, I've been unable to download Podcasts in iTunes. What Happens I can subscribe to Podcasts via the iTunes Store and they show up in my Podcasts section, but are greyed out. (below) When I try to click on "G
-
How do I get rid of a sidebar that pop ups no matter what webpage I am searching?
I have a sidebar that pop up on the left hand side of my screen whenever I am on the internet. It does contains a X and will close with you press that, but reopens as soon as I click on something else. It is very annoying and gets in the way of looki