Using Bind Variables in Parameter Form's Query
I want to use bind variables in the query of Parameter form. But
it does not allows. What is the other way out. The structure of
my Parameter form is as under:
State:
Customer:
Now I want that I want to list only those customer in the
Customer LOV which belongs to the selected state.
Thanks.
Muhammad Nadeem
Can we just link to an oracle form using a url still as we can with reports? I've built a report that requires the user to select from a dynamic list as well, and I know how to do this through forms, but can I simply call the form from a webpage?
Similar Messages
-
BUG ? : ADF creating extra VO instance using bind variables in a LOV query
ADF 11.1.1.1.0
After "playing around" with bind variables Setting bind variables in view objects for LOV I've come across something strange that I've reproduce using the HR schema and tables Employees and Departments. Its a bit long but here goes :
Using the HR schema tables departments and employeesI'm trying to create a LOV (selectOneChoice) for the
employee department, the LOV having a bind variable that limits the values returned in this case returning only DepartmentId = 50
I've create a VO lovDepartment (not based on an EO) with the following query :
SELECT Departments.DEPARTMENT_ID,
Departments.DEPARTMENT_NAME,
Departments.MANAGER_ID,
Departments.LOCATION_ID
FROM DEPARTMENTS Departments
where DEPARTMENT_ID = :pDeptIdA LOV has been defined on the DepartmentId attribute of the EmployeesView.
The lovDepartmentImpl overrides the executeQueryForCollection to set the bind variable value.
@Override
protected void executeQueryForCollection(Object object, Object[] object2,
int i) {
setNamedWhereClauseParam("pDeptId", "50");
super.executeQueryForCollection(object, object2, i);
}When using an ADF form to create a new employee the DepartmentId lov is empty.
Enabling SQL tracing shows the following :
[370] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1_0 ViewRowSetImpl.doSetWhereClause(-1, pDeptId, null)
[371] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1_0 ViewRowSetImpl.execute caused params to be "un"changed
[372] Column count: 4
[373] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1_0 ViewRowSetImpl.doSetWhereClause(-1, pDeptId, null)
[374] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1 ViewRowSetImpl.setNamedWhereClauseParam(pDeptId, 50)
[375] ViewObject: _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1 Created new QUERY statement
[376] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1>#q computed SQLStmtBufLen: 235, actual=195, storing=225
[377] SELECT Departments.DEPARTMENT_ID,
Departments.DEPARTMENT_NAME,
Departments.MANAGER_ID,
Departments.LOCATION_ID
FROM DEPARTMENTS Departments
where DEPARTMENT_ID = :pDeptId
[378] Bind params for ViewObject: _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1
[379] For RowSet : _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1_0
[380] Binding null of type 12 for "pDeptId"
[381] No Resource Bundle found but null value id:LOV_DepartmentId_LOVUIHints_NullValueId is defined in an ListBinding Definition.It would seem that 2 lovDepartment instances are used one at line 370 LOCALVIEW_USAGE_model_EmployeesView_lovDepartment1_0
and one at line 374 LOCALVIEW_USAGE_model_EmployeesView_lovDepartment1
The one at line 374 LOCALVIEW_USAGE_model_EmployeesView_lovDepartment1 gets the variable bound at line 374
however LOCALVIEW_USAGE_model_EmployeesView_lovDepartment1_0 gets a null value and would explain the empty LOV
Can anybody explain what is happening here ? (and how to use bind variables in LOV queries)
Regards
Paul
(bump)
Edited by: Paul (MITsa) on Jul 14, 2009 10:46 AM
I've now tried all types of LOV from ChoiceList to Radio groupe by testing the application module - none of them work.....
Edited by: Paul (MITsa) on 14-Jul-2009 22:52when you rinvoke executeQueryForCollection the bind variables are allready set and they exist in Object[] object2 method parameters.
in order to change them you need something like:
private void changeGenericBindVariable(Object[] params, String paramName, Object paramValue) {
for (int i = 0; i < params.length; i++) {
if (paramName.equals(((Object[])params)[0].toString()))
((Object[])params[i])[1] = paramValue;
* executeQueryForCollection - overridden for custom java data source support.
protected void executeQueryForCollection(Object qc, Object[] params,
int noUserParams) {
changeGenericBindVariable(params, "pDeptId", "50")
super.executeQueryForCollection(object, object2, i);
But its better to set bind variables before you executeQueryForCollection. like when you invoke LOV.
For cascading LOVs and the problems i have check:
[http://adfbugs.blogspot.com/2009/07/jdeveloper-11-r1-cascading-lov-bugs.html] -
Query don't use the right index when using bind variables
Hi people !
I need some help because I have an issue with a query that don t use the right Indexes as it should
First of all, I have mainly three tables :
ORDER : Table that contains description for each Order (approximately 1 000 000 Records)
ORDER_MVTS : Table that contains the tasks made (called movements) to set up each Orders
with quantity of packages prepared for each product (approximately 10 000 000 Records)
PRODUCT : Tables that contains the products (approximately 50 000 Records)
When I launch the query with hard coded values, it brings back response very fast
because it uses the right index (ORDER_DHR_VALID) which represent the date and hour of the order
(with format 'DD/MM/YYYY HH24:MI:SS'). The selectivity for this index is good.
NB 1: I have to use the trick " >= Trunc(date) and < trunc(date) +1 " to filter on a simple date because
the index contains hour and minutes (I know it wasn't probably a bright idea at conception time).
NB 2: The index on ORDER_MVTS.PRODUCT_CODE is'nt discriminating enough because there is'nt enough different products.
It's the same for index on CUSTOMER_CODE and on MVT_TYPE so only the index on ORDER.DHR_VALID is good.
Here is the correct explain plan when I execute the query with hard coded values :
SELECT SUM(ORDER_MVTS.NB_PACKAGE)
FROM ORDER_MVTS, PRODUCT, ORDER
WHERE ORDER.DHR_VALID >= TRUNC(to_date('14/11/2008 10:04:56','DD/MM/YYYY HH24:MI:SS'))
AND ORDER.DHR_VALID < TRUNC(to_date('14/11/2008 10:04:56','DD/MM/YYYY HH24:MI:SS')) + 1
AND ORDER_MVTS.MVT_TYPE = 'DELIVERY'
AND PRODUCT.CODE = ORDER_MVTS.PRODUCT_CODE
AND ORDER_MVTS.ORDER_CODE = ORDER.CODE
AND ORDER.CUSTOMER_CODE = 'ADIDAS'
AND PRODUCT.CODE = 1234
Rows Row Source Operation
1 SORT AGGREGATE
2 NESTED LOOPS
4 NESTED LOOPS
2 INDEX UNIQUE SCAN (object id 378548) --> PRODUCT_PK
4 TABLE ACCESS BY INDEX ROWID ORDER
777 INDEX RANGE SCAN (object id 378119) --> ORDER_DHR_VALID
2 TABLE ACCESS BY INDEX ROWID ORDER_MVTS
30 INDEX RANGE SCAN (object id 377784) --> ORDER_MVTS_ORDER_FK
Now the problem is when the query is used in a Cursor with bind variables.
It seems like Oracle don't use index on ORDER.DHR_VALID because he can't figure out that he have
to actually filter on a short period of time (only one day).
So Oracle uses the index on ORDER_MVTS.PRODUCT_CODE which is'nt a bright idea (it takes 10 secondes instead of just one)
Here is the bad explain plan :
Rows Row Source Operation
1 SORT AGGREGATE
2 NESTED LOOPS
722 NESTED LOOPS
2 INDEX UNIQUE SCAN (object id 378548) --> PRODUCT_PK
722 TABLE ACCESS BY INDEX ROWID ORDER_MVTS
1790 INDEX RANGE SCAN (object id 377777) --> ORDER_MVTS_PRODUCT_FK
2 TABLE ACCESS BY INDEX ROWID ORDER
1442 INDEX UNIQUE SCAN (object id 378439) --> ORDER_PK
Now I have found two solutions to this problem :
1) using a Hint to force the use of index on ORDER.DHR_VALID (with /*+ INDEX(ORDER ORDER_DHR_VALID) */ )
2) Using Dynamic SQL and keeping the date hard coded (but not the other values except mvt_type)
For example :
QUERY :=
'SELECT SUM(ORDER_MVTS.NB_PACKAGE)
FROM ORDER_MVTS, PRODUCT, ORDER
WHERE ORDER.DHR_VALID >= TRUNC(TO_DATE('''||To_char(P_DTE_VAL,'DD/MM/YYYY')||''',''DD/MM/YYYY'')) '||
AND ORDER.DHR_VALID < TRUNC(TO_DATE('''||To_char(P_DTE_VAL,'DD/MM/YYYY')||''',''DD/MM/YYYY'')) + 1 '||
AND ORDER_MVTS.MVT_TYPE = 'DELIVERY'
AND PRODUCT.CODE = ORDER_MVTS.PRODUCT_CODE
AND ORDER_MVTS.ORDER_CODE = ORDER.CODE
AND ORDER.CUSTOMER_CODE = :CUSTOMER
AND PRODUCT.CODE = :CODE ';
These two solutions work but Number 1 is bad in theory because it uses a Hint
and Number 2 may be difficult to code.
So my question is : Does someone knows another solution to force the use of index ORDER_DHR_VALID that can be simple and reliable.
Thank you very much for support
Edited by: remaï on Apr 1, 2009 4:08 PMWhat version of oracle you have? CBO work is different in 9i and 10g.
Usually cost based optimizer do not want to use index for >< condition with binding variables because optimizer can not use statistic to determine selectivity, and by default selectivity of <> operators is low.
(As I remember '>' selectivity by default is 5%, you have two conditions > and <, therefore resulting selectivity will be 0.05*0.05=0.0025 as two independent events, but selectivity of other conditions
ORDER_MVTS.MVT_TYPE = 'DELIVERY' or ORDER.CUSTOMER_CODE = 'ADIDAS' looks much better for CBO)
The best solution I see is do not use binding variables. Actually your query looks as searching query, which executes not so often, therefore you will not have perfomance win along of skipping execution plan creation.
Edited by: JustasVred on Apr 1, 2009 10:10 AM -
Query taking too long when using bind variable
Hi All,
There is a query in our prod DB which runs very slow (approx 2 hours) when it uses Bind Variables (using JDBC thin client), and when i try passing the variable using TOAD/SQL developer it runs fine.
Explain Plan for running Query
SELECT STATEMENT ALL_ROWSCost: 146 Bytes: 379 Cardinality: 1
21 SORT ORDER BY Cost: 146 Bytes: 379 Cardinality: 1
20 NESTED LOOPS Cost: 145 Bytes: 379 Cardinality: 1
17 HASH JOIN Cost: 22 Bytes: 42,558 Cardinality: 123
15 MERGE JOIN CARTESIAN Cost: 15 Bytes: 8,910 Cardinality: 27
12 FILTER
11 NESTED LOOPS OUTER Cost: 9 Bytes: 316 Cardinality: 1
8 NESTED LOOPS OUTER Cost: 8 Bytes: 290 Cardinality: 1
5 NESTED LOOPS Cost: 6 Bytes: 256 Cardinality: 1
2 TABLE ACCESS BY GLOBAL INDEX ROWID TABLE GDP.GDP_FX_DEALS_INCREMENTOR Cost: 4 Bytes: 28 Cardinality: 1 Partition #: 9 Partition access computed by row location
1 INDEX RANGE SCAN INDEX GDP.GDP_FX_DEALS_INC_IDX_01 Cost: 3 Cardinality: 1
4 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_FX_DEALS Cost: 2 Bytes: 228 Cardinality: 1
3 INDEX UNIQUE SCAN INDEX (UNIQUE) GDP.GDP_FX_DEALS_KEY Cost: 1 Cardinality: 1
7 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_FX_DEALS Cost: 2 Bytes: 34 Cardinality: 1
6 INDEX UNIQUE SCAN INDEX (UNIQUE) GDP.GDP_FX_DEALS_KEY Cost: 1 Cardinality: 1
10 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_COUNTERPARTIES Cost: 1 Bytes: 26 Cardinality: 1
9 INDEX UNIQUE SCAN INDEX (UNIQUE) GDP.PK_CPTY Cost: 0 Cardinality: 1
14 BUFFER SORT Cost: 14 Bytes: 448 Cardinality: 32
13 TABLE ACCESS FULL TABLE GDP.GDP_CITIES Cost: 6 Bytes: 448 Cardinality: 32
16 TABLE ACCESS FULL TABLE GDP.GDP_AREAS Cost: 6 Bytes: 2,304 Cardinality: 144
19 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_PORTFOLIOS Cost: 1 Bytes: 33 Cardinality: 1
18 INDEX UNIQUE SCAN INDEX (UNIQUE) GDP.PORTFOLIOS_KEY Cost: 0 Cardinality: 1
Explain Plan for Slow Query
Plan
SELECT STATEMENT ALL_ROWSCost: 11,526,226 Bytes: 119,281,912 Cardinality: 314,728
21 SORT ORDER BY Cost: 11,526,226 Bytes: 119,281,912 Cardinality: 314,728
20 HASH JOIN Cost: 11,510,350 Bytes: 119,281,912 Cardinality: 314,728
2 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_PORTFOLIOS Cost: 1,741 Bytes: 177,540 Cardinality: 5,380
1 INDEX FULL SCAN INDEX (UNIQUE) GDP.PORTFOLIOS_KEY Cost: 14 Cardinality: 5,380
19 HASH JOIN Cost: 11,507,479 Bytes: 87,932,495,360 Cardinality: 254,140,160
3 TABLE ACCESS FULL TABLE GDP.GDP_AREAS Cost: 6 Bytes: 2,304 Cardinality: 144
18 MERGE JOIN CARTESIAN Cost: 11,506,343 Bytes: 18,602,733,930 Cardinality: 56,371,921
15 FILTER
14 HASH JOIN RIGHT OUTER Cost: 3,930,405 Bytes: 556,672,868 Cardinality: 1,761,623
5 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_COUNTERPARTIES Cost: 6,763 Bytes: 892,580 Cardinality: 34,330
4 INDEX FULL SCAN INDEX (UNIQUE) GDP.PK_CPTY Cost: 63 Cardinality: 34,330
13 HASH JOIN OUTER Cost: 3,923,634 Bytes: 510,870,670 Cardinality: 1,761,623
10 HASH JOIN Cost: 2,096,894 Bytes: 450,975,488 Cardinality: 1,761,623
7 TABLE ACCESS BY GLOBAL INDEX ROWID TABLE GDP.GDP_FX_DEALS_INCREMENTOR Cost: 2,763 Bytes: 52,083,248 Cardinality: 1,860,116 Partition #: 14 Partition access computed by row location
6 INDEX RANGE SCAN INDEX GDP.GDP_FX_DEALS_INC_IDX_01 Cost: 480 Cardinality: 334,821
9 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_FX_DEALS Cost: 1,734,205 Bytes: 8,320,076,820 Cardinality: 36,491,565
8 INDEX FULL SCAN INDEX (UNIQUE) GDP.GDP_FX_DEALS_KEY Cost: 104,335 Cardinality: 39,200,838
12 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_FX_DEALS Cost: 1,733,836 Bytes: 1,331,145,696 Cardinality: 39,151,344
11 INDEX FULL SCAN INDEX (UNIQUE) GDP.GDP_FX_DEALS_KEY Cost: 104,335 Cardinality: 39,200,838
17 BUFFER SORT Cost: 11,499,580 Bytes: 448 Cardinality: 32
16 TABLE ACCESS FULL TABLE GDP.GDP_CITIES Cost: 4 Bytes: 448 Cardinality: 32
How can I avoid that.
ThanksHello
Could you reformat your execution plans because they aren't particularly readable. The forums allow you to preserve the formatting of code or output by putting the symbol {noformat}{noformat} before and after the section of text you want to preserve formatting for.
If you write
{noformat}select * from v$version
{noformat}
it will be displayed asselect * from v$version
So can you run this above statement and post the output here so we know the full oracle version you are working with? And finally, it would be really helpful to see the query you are running. When you say it runs fine in Toad, is that when you replace the bind variables with the values or are you also using bind variables in Toad?
Cheers
David -
ORA-01006 Using Bind Variables In A Dynamic SQL Contains Query
I have the following dynamic SQL query :-
declare
TYPE typ_sql IS REF CURSOR;
ltyp_sql typ_sql;
lv_sql VARCHAR2(100);
begin
lv_sql := 'SELECT arx_id FROM arx WHERE CONTAINS ';
lv_sql := lv_sql || (arx_full,''(:b1) WITHIN ui'') > 0';
open ltyp_sql FOR v_sql USING ln_id;
fetch ......
close ......
end;
When the code tries to open the cursor it gives the above error. I presume it is the way Oracle is expanding the bind variable but I cannot find anything in the docs to say why this is happening or whether you can do this or not using bind variables ( CONTAINS query ). Any help would be appreciated, thanks,
Stuart.lv_sql || '(arx_full, :b1 || '' within ui'') > 0';
-
How to use bind variables in the following query
CREATE OR REPLACE PROCEDURE MMDB.test IS
sel_qtn VARCHAR2 (10);
CURSOR PT_QUANTITY IS select * from mmdb.product_tree WHERE QUANTITY_CHECK ='E'
AND run_id = 100
a PT_QUANTITY%ROWTYPE;
BEGIN
FOR i IN PT_QUANTITY
loop
sel_qtn := i.quanttity-1;
While sel_qtn>=1
loop
insert into mmdb.product_tree (BILLING_ACCOUNT_NO ,S_CODE) values (i.BILLING_ACCOUNT_NO ,i.S_CODE||'E');
sel_qtn :=sel_qtn -1;
End loop;
commit;
end;Don't duplicate threads: How to use bind variables in the following query
-
Using bind variable in existsnode?
Is there a way to use bind variables in an XPath query?
SELECT sys_xmlagg(sys_xmlgen(xmlconcat(extract(value(x),'//title'),extract(value(x),'//description')))).transform(pkg_xslt_dao.getIndexContentXSLT).getClobVal() into v_html from iwgeneric x where existsnode(value(x),'//audiences[id="'|| p_audience_id_in ||'"]') = 1;
As you can see from the sql above, I am concatenating the parameter in the SQL. This SQL is wrapped in a PL/SQL function, which in turn will be called by a JSP.
Any help or advice is appreciated.If you want to create this LOV in the standard parameter form of Oracle Reports, the answer is: no.
Create your own parameter form, e.g. in Oracle Forms if you are calling Reports from Forms. -
Hey Everyone,
I'm having a bit of trouble creating a report. I need the FROM part of the code to use bind variables. I have come up with this peice of code below but im getting the following error:
failed to parse SQL query:
ORA-06550: line 1, column 8:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin function package pragma procedure subtype type use
form
current cursor
The symbol "" was ignored.
ORA-06550: line 2, column 24:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin function package pragma procedure subtype type use
form
current
Can anyone see where im going wrong?
Thanks in advance,
-N.S.N.O.
Code*
DECLARE
x VARCHAR2 (4000);
BEGIN
x := x || 'select *';
x := x || 'from ';
x := x || :p13_schema;
x := x || '.ddl_log@';
x := x || :p13_db_name;
x := x || '_DBAAPEX.TNTEWW.COM';
RETURN (x);
END;Hey Roel and Daylocks,
After getting frustrated for a while i deleted the page and started again. I put in the exact same code and it worked just how i wanted in the first place :S
The only thing i did different is when i was creating the report region the first time around i used a normal SQL query, For Example:
select sysdate from dual;
Then i modified it to
DECLARE
x VARCHAR2 (4000);
BEGIN
x := x || 'select ';*
x := x || 'from ';
x := x || :p14_schema;
x := x || '.ddl_log@';
x := x || :p14_db_name;
x := x || '_DBAAPEX.TNTEWW.COM';
RETURN (x);
END;
Whereas on the second attempt i used the peice of code in question straight away. Its been a bit of a frustrating morning because i used a similar peice of code for a different application, nevermind tho :)
Thanks for your replys, much appreciated.
-N.S.N.O. -
Using bind variables in creating new recordgroup
hi
i am creating a new recordgroup and assigning it to the LOV using forms personalization in new item instance trigger .
when i use the bind variables in the record group query i am getting errored out. if i remove the bind variables in the query then RG is creating and is assigned to the LOV and i can use it.
can anyone help me how to refer the values from the exising form to build a dynamic record group query.Can you please send me the code you used in Forms Personalization to create new RecordGroup and attach it to an item. my mail id is [email protected]
-
Bind Variables and Shared Component Report Query
I have a query in a region report which I have replicated to a shared component report query.
Both queries reference page items as bind variables in the where clause.
The report region on screen shows the correct results but the report query shows "no data". This is the case when running "Test Query" and "Download XML data" from the shared component report query definition. If I hardcode the variable names I get rows returned, If I use bind variables - and specify the values for these variables I get no data. THe XML file contains the tags for each bind variable I have specified but has no data between the tags. I have Ticked the box to include application and session state but it appears that the bind variables are not being used.
When I use my report query in the application (URL tied to a button) I get the same problem, the binds are not being passed to the report query.
Can someone please clarify if this is a bug or not? And if not, how can I get it to work.
I am using Apex 4.0.2
Thanks
KathrynHi
To confirm, yes I selected the bind variables. I used these in the report layout, but the xml file has them as empty i.e.
<P0_START_DATE><P0_START_DATE/> with nothing in between.
IN the Test Query section, if I put real values in the boxes for the bind variables, I get no data found. If I hardcode the values into the query, I get the data.
I've repeated the create report query many times and have created a report layout in RTF. I can use the layout with my region - in the print attributes and the layout works with the query but I need to create a PDF using 2 queries - ROWSET1 and ROWSET2. I can generate the XML but the values in the rows are all empty. When I use the layout with a report query instead of the region, I get no data even though I have used the same sql and have selected the bind variables. I was using variables from page items on page zero but have also tried using page items on the current page, the result is the same.
I need to use a report query and a report layout as I need data from 2 queries in the PDF.
I looked at your demo - what happens if you add a second sql query to the report query - is there any chance I can look at the back end (developer access?)
Thanks for your input
Kathryn -
Csv no data found when using bind variables
Hi,
I have created a report, that uses 2 date variables to limit the query and rows display as they should. But clicking the csv link opens csv having one row stating 'No data found...'. If I set static values in place of variables, I get the right result. How could I use bind variables and get the right answer in csv (without coding my own function)?
KajaI am having the same problem.
The export link opens a new session without submitting the current page. The page item values are therefor not saved to cache before the export is undertaken.
Any report using page item bind variables in the where clause will not export correctly as the bind values are either null or those of the previous page submit.
Any ideas on how to get round this?? -
Using Bind Variable in a SELECT
Hi,
I'm trying to build up my SQL query at run-time using bind variables and in the Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1) it says that 'After defining the bind variables, the next step is to reference them in the SQL statement. While SQL syntax allows bind variables to appear both in the SELECT list and in the WHERE clause, you'll typically use them in the latter context, as part of your WHERE clause.'.
However, when I try to use the bind variables in my SELECT list because I've had to set a type for the variable to String the variable gets inserted with inverted commas either side e.g. SELECT 'Service' FROM TestTable. Is it possible to use bind variables to insert a value into my select list without these inverted commas around it?
Thanks in advance,
TomOK, thanks for your response. Do you know of a way then where I can control my SELECT parameters programmatically? I'm currently trying to do it using the information in the chapter '35.9 Using Programmatic View Objects for Alternative Data Sources' from the Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1). I think I'm part way there, would this be the correct way of acheiving what I want?
Cheers, Tom -
Using bind variable with IN clause
My application runs a limited number of straight up queries (no stored procs) using ODP.NET. For the most part, I'm able to use bind variables to help with query caching, etc... but I'm at a loss as to how to use bind variables with IN clauses. Basically, I'm looking for something like this:
int objectId = 123;
string[] listOfValues = { "a", "b", "c"};
OracleCommand command = new OracleCommand();
command.Connection = conn;
command.BindByName = true;
command.CommandText = @"select blah from mytable where objectId = :objectId and somevalue in (:listOfValues)";
command.Parameters.Add("objectId", objectId);
command.Parameters.Add("listOfValues", listOfValues);
I haven't had much luck yet using an array as a bind variable. Do I need to pass it in as a PL/SQL associative array? Cast the values to a TABLE?
Thanks,
NickNevermind, found this
How to use OracleParameter whith the IN Operator of select statement
which contained this, which is a brilliant solution
http://oradim.blogspot.com/2007/12/dynamically-creating-variable-in-list.html -
Trying to pass array to stored procedure in a loop using bind variable
All,
I'm having trouble figuring out if I can do the following:
I have a stored procedure as follows:
create procedure enque_f826_utility_q (inpayload IN f826_utility_payload, msgid out RAW) is
enqopt dbms_aq.enqueue_options_t;
mprop dbms_aq.message_properties_t;
begin
dbms_aq.enqueue(queue_name=>'f826_utility_queue',
enqueue_options=>enqopt,
message_properties=>mprop,
payload=>inpayload,
msgid=>msgid);
end;
The above compiles cleanly.
The first parameter "inpayload" a database type something like the following:
create or replace type f826_utility_payload as object
2 (
3 YEAR NUMBER(4,0),
4 MONTH NUMBER(2,0),
83 MUSTHAVE CHAR(1)
84 );
I'd like to call the stored procedure enque_f826_utility_q in a loop passing to it
each time, new values in the inpayload parameter.
My questions are:
First, I'm not sure in php, how to construct the first parameter which is a database type.
Can I just make an associative array variable with the keys of the array the same as the columns of the database type shown above and then pass that array to the stored procedure?
Second, is it possible to parse a statement that calls the enque_f826_utility_q procedure using bind variables and then execute the call to the stored procedure in a loop passing new bind variables each time?
I've tried something like the following but it's not working:
$conn = oci_pconnect (....);
$stmt = "select * from f826_utility";
$stid = oci_parse($conn, $sqlstmt);
$r = oci_execute($stid, OCI_DEFAULT);
$row = array();
$msgid = "";
$enqstmt = "call enque_f826_utility_q(:RID,:MID)";
$enqstid = oci_parse($conn, $sqlstmt);
oci_bind_by_name($enqstid, ":RID", $row); /* line 57 */
oci_bind_by_name($enqstid, ":MID", $msgid);
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC))
++$rowcnt;
if (! oci_execute($enqstid)) /* line 65 */
echo "Error";
exit;
When I run this, I get the following:
PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
ine 57
Entering loop to process records from F826_UTIITY table
PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
ine 65
PHP Warning: oci_execute(): ORA-06553: PLS-306: wrong number or types of argume
nts in call to 'ENQUE_F826_UTILITY_Q' in C:\Temp\enqueue_f826_utility.php on lin
e 65
PHP Notice: Undefined variable: msgnum in C:\Temp\enqueue_f826_utility.php on l
ine 68
Error during oci_execute of statement select * from F826_UTILITY
Exiting!Thanks for the reply.
I took a look at this article. What it appears to describe is
a calling a stored procedure that takes a collection type which is an array.
Does anyone from Oracle know if I can pass other database type definitions to a stored procedure from PHP?
I have a type defined in my database similar to the following which is not
an array but a record of various fields. This type corresponds to a payload
of an advanced queue payload type. I have a stored procedure which will take as it's input, a payload type of this structure and then enqueue it to a queue.
So I want to be able to pass a database type similar to the following type definition from within PHP. Can anyone from Oracle verify whether or not this is possible?
create or replace type f826_utility_payload as object
YEAR NUMBER(4,0),
MONTH NUMBER(2,0),
UTILITY_ID NUMBER(10,0),
SUBMIT_FAIL_BY VARCHAR2(30),
MUSTHAVE CHAR(1)
); -
Performance when using bind variables
I'm trying to show myself that bind variables improve performance (I believe it, I just want to see it).
I've created a simple table of 100,000 records each row a single column of type integer. I populate it with a number between 1 and 100,000
Now, with a JAVA program I delete 2,000 of the records by performing a loop and using the loop counter in my where predicate.
My first JAVA program runs without using bind variables as follows:
loop
stmt.executeUpdate("delete from nobind_test where id = " + i);
end loop
My second JAVA program uses bind variables as follows:
pstmt = conn.prepareStatement("delete from bind_test where id = ?");
loop
pstmt.setString(1, String.valueof(i));
rs = pstmt.executeQuery();
end loop;
Monitoring of v$SQL shows that program one doesn't use bind variables, and program two does use bind variables.
The trouble is that the program that does not use bind variables runs faster than the bind variable program.
Can anyone tell me why this would be? Is my test too simple?
Thanks.[email protected] wrote:
I'm trying to show myself that bind variables improve performance (I believe it, I just want to see it).
I've created a simple table of 100,000 records each row a single column of type integer. I populate it with a number between 1 and 100,000
Now, with a JAVA program I delete 2,000 of the records by performing a loop and using the loop counter in my where predicate.
Monitoring of v$SQL shows that program one doesn't use bind variables, and program two does use bind variables.
The trouble is that the program that does not use bind variables runs faster than the bind variable program.
Can anyone tell me why this would be? Is my test too simple?
The point is that you have to find out where your test is spending most of the time.
If you've just populated a table with 100,000 records and then start to delete randomly 2,000 of them, the database has to perform a full table scan for each of the records to be deleted.
So probably most of the time is spent scanning the table over and over again, although most of blocks might already be in your database buffer cache.
The difference between the hard parse and the soft parse of such a simple statement might be negligible compared to effort it takes to fulfill each delete execution.
You might want to change the setup of your test: Add a primary key constraint to your test table and delete the rows using this primary key as predicate. Then the time it takes to locate the row to delete should be negligible compared to the hard parse / soft parse difference.
You probably need to increase your iteration count because deleting 2,000 records this way probably takes too short and introduces measuring issues. Try to delete more rows, then you should be able to spot a significant and constant difference between the two approaches.
In order to prevent any performance issues from a potentially degenerated index due to numerous DML activities, you could also just change your test case to query for a particular column of the row corresponding to your predicate rather than deleting it.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/
Maybe you are looking for
-
Safari crashes when trying to play streams... HELP?
Hi guys. When trying to just watch streams online on certain sites, safari just crashes and I get an error message. When clicking the appropriate link, it seems to want to load a new page called 'adcash.com' and then crashes. When new windows opened
-
MM table for document extraction
Hi All, I need to extract SE16 contracts and purchase orders data from ECC 6.0 with the following details: Contract/order number, document date, delivery date, Supplier Code, material code, quantity, prices. Can anyone help me in find out from which
-
What is a NDSPCShowServer.bundle?
I received this for the first time today when I started my IMac? Does anyone know what this is?
-
I Need to Know how to access MyTunesRSS from outside my Local Network.
Ok, I was able to use this software: http://www.codewave.de/products/mytunesrss/ from everywhere before I bought the Airport Extreme, how can I do it again, I Mean Locally works fine, but when I try with the server address that it gaves me I can't no
-
ME21N VS ME51N Item Price (NETPR) Difference Validation
hi! For non-stock item, I want to implement an item price check between PO and PR e.g. if the net price in PR is 100 and I changed it in PO as 110 then a warning message. How to? Thanks, SAPRon