Sql substitution
Hi,
I have a query like this:
select company,
productfamily,
sum(fy_quota),
sum(ytd_orders),
max(order_perf)
from view_order_test
where lower(region) like lower(:P66_REGION || '%')
group by company,
productfamily
now I need some help on how to substitute the max(oder_perf). If the result of max(oder_perf) is 1, then replace it with a <--img src="#WORKSPACE_IMAGES#green.gif" -->, if 2, replace it with <--img src="#WORKSPACE_IMAGES#yellow.gif" -->, if 3, then <--img src="#WORKSPACE_IMAGES#red.gif" -->.
Can anyone help me on how to substitute on a report?
Thanks,
Helen
Try an inline view. Something like this:
select company,
productfamily,
fy_quota,
ytd_orders,
decode(order_perf, 1, '<--img src="#WORKSPACE_IMAGES#green.gif" -->',
2, '<--img src="#WORKSPACE_IMAGES#yellow.gif" -->',
3, '<--img src="#WORKSPACE_IMAGES#red.gif" -->') order_perf
from (select company,
productfamily,
sum(fy_quota) fy_quota,
sum(ytd_orders) ytd_orders,
max(order_perf) order_perf
from view_order_test
where lower(region) like lower(:P66_REGION || '%')
group by company, productfamily)
Similar Messages
-
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 -
Substituion variable not available as data source in "Open SQL"
Setup as follows:
right-click on server name->Edit->Variables:
all apps, all dbs, SQL_SOURCE, 3G.DEV
In app_A, if I open a rules file, then File-Open SQL, I can select SQL_SOURCE as a substitution variable.
In app_B, if I open a rules file, then File-Open SQL, substitution variables is greyed out and can't be selected.
Does anyone have any clues or hints on whats wrong? I have set both rules files the same as far as I can see.That was my first thought, rebooted machine to no avail.
If in the server variables section, I explicitly define a variable for that app/database it's OK. So:
all apps,all dbs,SQL_SOURCE,3G.DEV
Only works for db_1 in the app. If I go:
app_1,db_1,SQL_SOURCE,3G.DEV
app_1,db_2,SQL_SOURCE,3G.DEV
That works.
My only solution therefore it would seem is to define the variable per db per app where needed? -
Report 2.5 : How to get error
Hi,
I have done the migratation of our application from report 2.0 to
report 2.5.
When a preview is starting, a window 'Report Progress' appeared
with a cancel press button.
If I press this button during "Initialilizing report" message, a
REP-0099 report is aborted at upon user request, after cliquink
on Ok, no report preview appears. It's Ok for me.
The same actions during "Formating Page x" make the message
REP-0099 appeared and the preview is ran. By navigating on the
report preview (next page), the REP-099 message appeared at the
page number for which the cancel operation have been processed.
I had tried to get the error number (srw.geterr_run) in all form
triggers. It doesn't work.
What i want is to stop the Report preview if the user had pressed
the Cancel button.
So, I would like to know if you have a method to stop the report
when Cancel button is pressed on the "Report Progress" window (by
getting error message in forms, or any other method).
Thanks.
DAVID RONGEAT.
nullIt's not possible to use wild-cards in sql-substitution.
Here are your choices :
1) write xquery that does what you need - something like :
if ( sum( $whatever) ne 0 ) then
sum( $whatever )
else (: need to distinguish between sum==0 and sum==null :)
if ( some $x in TABLE()
where $x/key eq $thekey ) then
0 (: there were matching rows, but whatever we were summing was still 0 :)
else (: no matching rows, sum was 0 )
-9999
This is likely going to result in some ugly/less efficient sql
2) use sql substitution where needed. I don't see this as being any more evil than (1). If you have ten places where you need to do sql substitution - there will be ten places where you need to do (1), correct?
3) Create a Physical Data Service based on the sql-statement that you want to have executed. This is about as much work as (2), and about twice as hard to get correct.
4) open a case with customer support for a product enhancement. You won't get this enhancement - trust me.
5) change your requirements
6) Post here again asking "but can I do xyz instead?" - in which case I will point you to this case with the six options. -
*** Urgent - How to view Cursor output in TOAD ***
Hi,
I know how to view the output of a sysref cursor that is an out parameter from an SP, in SQL*PLUS
But is there a way to see the resultset of a cursor in TOAD?
This is urgent.
Thanks for the helping hands.
SunTOADs SQL Editor works (almost) the same as SQL*Plus.
You can work with VAR's and PRINT's in the very same way as SQL*Plus.
Furthermore you can do the following:
- Write an SQL statement with a bound cursor (with colons)
- right-click in TAODs Editor
- check for SQL Substitution variables.
- run the script (F9) and a substition pop up »pops up«, from where you can choose CURSOR.
The results will show up in the Data grid.
Note: I am working with TOAD ver. 9 -
Using substitution variable in sql -- Issue
Hello All
I am trying to do a sql operation from command prompt of my system and that sql requires substitution variable which i am passing it but when i pass the variable ( there are two) the first one assign as " \c" and second gets both what i am passing.
I am not sure what exactly happening here, i have done this on AIX but here its not working any ideas?
System : uname -a
Linux ## 2.6.18-128.1.1.el5 #1 SMP Mon Jan 26 13:58:24 EST 2009 x86_64 x86_64 x86_64 GNU/LinuxAIX and Linux are not the same. An output of "\c" may indicate a compatibility issue of your shell script with your current command line interpreter (shell). A \c can be used to suppress a newline with the echo command. Bash understands both formats echo -n and echo \c, but other shells like Ksh don't. Try to run your script under a Bash, which is the default under Linux. If the problem persists you will need to post your script for any further analysis.
-
Error with define substitution variable in SQL
Hi there,
I am using PL/SQL developer and trying to define a substitution variable as follows:
define freq = 'Weekly'
Then later on, in my SQL statement, I used this variable in WHERE statement as follows:
WHERE ... (&freq = 'Weekly') and ...
But I got the "ORA-00904: "WEEKLY": invalid identifier" error.
Where is the problem?
Thanks in advance!I don't know about PL/SQL developer but in sqlplus you need single quotes around the variable.
SQL> define freq = 'Weekly'
SQL> select null from dual
2 where &freq = 'Weekly';
old 2: where &freq = 'Weekly'
new 2: where Weekly = 'Weekly'
where Weekly = 'Weekly'
ERROR at line 2:
ORA-00904: "WEEKLY": invalid identifier
SQL> edi
Wrote file afiedt.sql
1 select null from dual
2* where '&freq' = 'Weekly'
SQL> /
old 2: where '&freq' = 'Weekly'
new 2: where 'Weekly' = 'Weekly'
N
SQL> -
SQL Injection and variable substitutions
Hello helpful forum, I'm trying to understand what really goes on "behind" the scenes
with the variable substitutions in order to protect from sql injections.
I'm using apex 3.0.0.00.20
The trickiest component seems to be a Report of type "pl/sql returning sql", since
multiple dynamic sql interpretations are done there.
consider the following innocent looking disaster:
DECLARE
l_out VARCHAR2(2000);
BEGIN
l_out := 'select * from test_injection t where t.name like ''%' || :NAME || '%''';
RETURN l_out;
END;
if NAME is a single quote the report will return:
failed to parse SQL query: ORA-00911: invalid character
which hints to the fact that NAME is not escaped, and you are in fact able to access db functions
as in: '||lower('S')||'
I also tried to put there a function that runs in a autonomous transaction to log its calls, and
I see that it's called five times for each request.
consider now the similar solution (notice the two single quotes):
DECLARE
l_out VARCHAR2(2000);
BEGIN
l_out := 'select * from test_injection t where t.name like ''%'' || :NAME || ''%''';
RETURN l_out;
END;
with this second example nothing of the above is possible.
So my theory (please confirm it or refute it) is that there is a first variable substitution done
at the pl/sql level (and in the second case :NAME is just a string so nothing is substituted).
Then the dynamic sql is executed and it returns the following string:
select * from test_injection t where t.name like '%' || :NAME || '%'
now another substitution is done (at an "APEX" level) and then query is finally executed to return
the rows to the report.
The tricky point seems to be that the first substitution doesn't escape the variable (hence the error
with the single quote), while the second substitution does.
Please let me know if this makes sense and what are the proper guidelines to avoid sql injection with
the different kinds of reports and components (SQL, pl/sql returning sql, processes, ...)
ThanksGiovanni,
You should build report regions like this using the second method so that all bind variables (colon followed by name) appear in the resultant varchar2 variable, l_out in your example, which will then be parsed as the report query. This addresses not only the SQL injection problem but the shared-pool friendliness problem.
Scott -
Substitution variable in sql load rules file
Okay gurus,
I need a little guidance, I have to replace the value of 201020 and 2008 from substitution variables. I have created the variables and set them up globally on the essbase server.
201020 = FW00
2008 = FY00
WHERE ACT.FISCAL_WEEK_ID <= 201020
AND ACT.FISCAL_YEAR_ID > 2008
AND RTDIV.DIV IN (1,2,3,4,5,6,7,8,9,99) (This is the query with hard coded values of week and year)
When i m trying to put sub variables there , its throwing the error. please find below the way i was trying to do it.
WHERE ACT.FISCAL_WEEK_ID = '&FW00'
AND ACT.FISCAL_YEAR_ID = '&FY00'
But unfortunately, its throwing error Error: 1021001 Failed to Establish Connection With SQL Database Server. See log for more information
I know that this is the generic error because if i put the hard coded value in sql load rules it works fine.
Is it the right way to out sub var in sql load rules???
Please advice and thanks in advance.Hi Genn,
I tried to see the app log for sql but i m afraid that there is nothing in there, the only error message which I am getting in app log is this:
Failed to Establish Connection With SQL Database Server. See log for more information
Its an ASO cube and initially i was using the variable as FY00 AS "2008" it did not work and than i tried without quotes in variable but is still not working.
Any idea..thanks in advance. -
Unit Test Variable Substitution in PL/SQL User Vailidation code not running
Hi
I am using new Unit Test Feature in SQL Developer 2.1.0.62.
I have created a test implemented to test a function. The function has a VARCHAR2 parameter as input and returns a BINARY_INTEGER.
I would like to perform 'Process Validation instead of specifying an explicit 'Result'. The check box 'Test Result' is unchecked.
I have seen in the doc. that I can use substitution variables in my user defined PL/SQL code. I try
IF {RETURNS$} < 0
THEN ...
but I always get the error
ERROR
<RETURN> : Expected: [Any value because apply check was cleared], Received: [-103]
Validation User PL/Sql Code failed: Non supported SQL92 token at position: 181: RETURNS$
Obviously, the program doesn't recognize {RETURN$}.
Am I missing something?
br
ReinerHi all,
I have installed the latest version of SQL Developer (2.1.1) that fixed the problem - must have been a bug.
The only problem was that I got an ORA-904 TEST_USER_NAME... error. I export my tests, dropped the repository, created a new one and reimported everything. Now it works as it should.
br
Reiner -
this photo illustrate how that (Substitution Variables) not working in "SQL Developer" Environment :-
http://www.imagehosting.com/show.php/1555180_ddddd.PNG.html
any solve for this problem ?????!!!!!!!!!!There is a dedicated forum for SQL Developer related questions
SQL Developer
I should admit however, that query you have provided ( with substitution variables) works like a charme in my environment (SQL Developer 1.1.0.23 build 23.64)
Best regards
Maxim -
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,
SwaroopSwaroop,
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 -
Essbase server - automatic change of substitution variable from SQL
Hi,I would like to automaticaly change the substitution variable in Essbase Server. Is it posible to change the substitition variable from external source e.g. SQL statement?Simple sample:I would like to assign value "2003" to "CurYear" substitution variable. But value "2003" I would like to get from SQL:"select year(current date) from table".There are commands in Esscmd and MaxL Shell, see bellow.Esscmd command:CREATEVARIABLE "CurYear" "localhost" "" "" "2003";MaxL Shell:alter system set variable CurYear '2003';Is it possible to get the value '2003' from SQL and pass this value to Esscmd command or MaxL Shell?My system:Windows 2000 Professional Service pack 4Essbase at 6.5.3 levelThanks,Grofaty
You can create a text file from the SQL server that writes the command like"CREATEVARIABLE "CurrYear" "Servername" "AppName" "DBName" "2005";then you can create a schedule job that would run this script which can update the variable. CREATEVARIABLE creates/replaces the current variable.
-
&& Substitution Variable in Package Body using SQL Developer
Hi Folks,
I've moved over to working to in SQL Developer (its a very early version - 1.0.0) from a combination of SQL*Plus command line and a text editor. I'm trying to get this upgrgraded, but I think the question will be the same with a newer version anyway.
I am creating a package, and in the package body I have some &&my_var substitutions that I was previoulsy prompted for when calling the .sql from the command line SQL*Plus. I need this as the variable needs to be different for the development and live environment.
When working in SQL Developer, I can load the package body from Connection->Packages->My Package->My Package Body, and click the edit button to edit the code, however, when I click the Compile button in the top of the window my code error's because of the substituion variablle. An example is:
CREATE OR REPLACE
PACKAGE BODY MY_PACKAGE AS
PROCEDURE MY_PROCEDURE
BEGIN
my_variable := &&my_function_from_live_or_dev_database
END MY_PROCEDURE
Can anyone tell me if there is a way of defining a compiler variable within the IDE widow while editing a package body stored in the database, without manually copying the code into the Worksheet and running it as a script?
Thanks,
AM953104 wrote:
Thanks for the reply, the code was just quickly typed to show the sort of thing I am doing, it wasn't actual code form my project.
I've come from a C background so what I would have done would be create a #define and changed to when on live or development - or passed the variable to the build environment from the IDE or makefiles and the change would have reflected through my whole project.
What I want to be able to do is alter a definition of some sort that will reflect throughout my whole project, so I can change it in one location to minimize code changes before going live. I don't really want to be prompted at all. On one system it needs to be DEV_10 and on the other it needs to be LIVE_10.Is there a possibility to elimiante this difference at all?
For example if DEV_10 is the oracle schemauser on the development database and LIVE_10 would be the one on the production system. THen you could just remove all references to the schema from your code.
IF you are already connected to this schema, then you don't need to specify the schema name anymore.
example
instead of
create or replace package dev_10.myPackage
...you can simply use
create or replace package myPackage
...If needed you can alter the cuurently connected user just before you run the script.
alter session set current_schema = LIVE10;
create or replace package myPackage
...This would be a different working window in the developer (script worksheet, instead of direct pl/sql editor).
Substitution variables are allowed there. -
Storing the contents of a substitution or bind variable in a PL/SQL var
Hi,
I would like to create a substitution or bind variable to store the name of a sequence to use in SQLPlus and then reference this in a PL/SQL procedure and assign the contents of the substitution or bind variable in the PL/SQL variable. Is this possible?
Regards,
SeanA substitution variable can only be used in an anonyomous PL/SQL block, not a stored procedure. You would pass the sequence name in via an input parameter to that stored proc.
In an anonymous block though:
sql>declare
2 v_seq_name user_sequences.sequence_name%type;
3 v_value number;
4 begin
5 v_seq_name := '&seq_name'; -- assign substitution to variable
6 execute immediate 'select ' || v_seq_name || '.nextval from dual' into v_value;
7 dbms_output.put_line( v_value );
8 end;
9 /
Enter value for seq_name: SEQ
old 5: v_seq_name := '&seq_name';
new 5: v_seq_name := 'SEQ';
24
PL/SQL procedure successfully completed.
Maybe you are looking for
-
Urgent: Performance problem with where clause using IN and an OR condition
Select statement is: select fl.feed_line_id from ap_expense_feed_lines_all fl where ((:1 is not null and fl.feed_line_id in (select distinct r2.object_id from xxdl_pcard_wf_routing_lists r2, per_people_f hr2 where upper(hr2.full_name) like upper
-
Uploading movie from DVD to my hard drive
I have a movie on DVD that I want to put onto my hard drive. How do I take it from the disc to the hard drive on my computer. I am using Nero 12.
-
I am not able to view all the text in my chatpter/scene selections buttons.
I created chapters in iMovie. However, when I create the DVD in iDVD6, the chapter text gets cut off. I tried to decrease the font size, but that didn't work. It did make the text smaller, but it was still cut off (just smaller). Does anyone know how
-
Hi All I want to create work item that will run a Transaction/Report. when the user will execute the work item from his inbox It will run a Transaction "z*" with some parameters and display the result (ALV Rp) Thanks in Advance For Any Help.
-
IPhone stuck in recovery mode after attempted to downgrade from iOS5 Beta
Hi, There was a bug being reported in one of my apps, but I couldn't replicate it. I tried to downgrade back to 4.3.5 to see if iOS 5 was the reason that I couldn't replicate it, but now my phone is stuck in Recovery Mode. I have restored Xcode 4.1