SQL IN clause with Bind parameter?

Hi
I have a simple task that hasn't been so simple to figure out. I want to allow a user to search for one or more comma-separated values in a simple JClient ADF app. Is there a way to use a SQL IN clause with a single bind variable? e.g. SELECT TITLE FROM CITATION WHERE ID IN (:0)
When I pass a single value it works fine but a comma separated list doesn't.
Thanks
John

Update: I wanted to combine the techniques found in two of Steve Muench's articles -
1) Providing Default Values for View Object Bind Variables (so I could display an ADF-bound JPanel with defaults)
http://radio.weblogs.com/0118231/stories/2004/10/07/providingDefaultValuesForViewObjectBindVariables.html
2) Array of String Domain Example (so a user could enter one or more comma-separated values into a text box for DB searches)
http://radio.weblogs.com/0118231/stories/2004/09/23/notYetDocumentedAdfSampleApplications.html
I learned some helpful stuff about the framework but spent lots of time banging my head against the wall because the two examples wouldn't work when directly combined. To best understand this, be sure to study Steve's examples above.
In example 1 Steve passes an array of objects (Object[] DEFAULT_VALUES) to the ViewObject's where clause using the setWhereClauseParams(Object[] values). However, in example 2 he creates an Oracle Array which contains an Oracle ArrayDescriptor, Connection, and array of values to pass to the "IN" bind variable. Also, example 1 allows for multiple bind vars to be included whereas example 2 allows for an array of data to be passed to a single bind var. Even though my code provides an array to a single bind var (per ex. 2) it should still allow for the passage of multiple bind vars with minimal code modification.
Code from Steve's example 1 was copied into my EmpView ViewObject but certain modifications were necessary:
1) Change the ViewObject's DEFAULT_VALUES from Object[] to String[].
2) Modify the executeQueryForCollection() method in the ViewObject to call a function which will set the bind variables as Oracle Arrays (effectively converting the "params" data type from that of String[] to Oracle Array[])
3) Create a setManagerID(String[]) method in the EmpView object and expose it to the client.
(there are a number of others so it's best for you to go through the code and compare)
I finally got it working so I'm attaching the code, however beware - I'm new to this so there may be other, better ways to go about it. Also, there are no framework bind vars so that section of code is never executed...it compiles but may fail at run time.
In order for this to work I suggest you use JDev to re-create the EmpView and Panel1 objects. This will ensure that the necessary ADF framework components are generated. Once complete, then copy in the code provided.
*File: EmpViewImpl.java
*Created as Read-Only access view object with the
*query:
*select manager_id, last_name from hr.employees
*where manager_id IN
*(select * from TABLE(CAST(:0 as TABLE_OF_VARCHAR)))
*order by manager_id
package model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import oracle.jbo.domain.Array;
import oracle.jbo.server.ViewObjectImpl;
import oracle.sql.ArrayDescriptor;
// --- File generated by Oracle ADF Business Components Design Time.
// --- Custom code may be added to this class.
// --- Warning: Do not modify method signatures of generated methods.
public class EmpViewImpl extends ViewObjectImpl implements model.common.EmpView
private ArrayDescriptor descriptor;
private final static String[] DEFAULT_VALUES_STRING = new String[]{"100"};
private final static int NUM_DEFAULT_VALUES = DEFAULT_VALUES_STRING.length;
* This is the default constructor (do not remove)
public EmpViewImpl()
protected void executeQueryForCollection (Object qc, Object[] params, int numUserParams)
Object pars[] = null;
// Bind default variables only if none have been provided by the user
if (numUserParams == 0)
numUserParams = NUM_DEFAULT_VALUES;
int numFwkSuppliedBindVals = (params != null) ? params.length : 0;
if (numFwkSuppliedBindVals > 0)
// Allocate a new Object[] array with enough room for both user- and framework-supplied vars
Object[] newBinds = new Object[numFwkSuppliedBindVals + numUserParams];
// Copy the framework-supplied bind variables into a new Object[] array
// leaving enough slots at the beginning for the user-supplied vars
System.arraycopy(params, 0, newBinds, numUserParams, numFwkSuppliedBindVals);
// Now copy in the user-supplied vars to the beginning of the array
System.arraycopy(DEFAULT_VALUES_STRING, 0, newBinds, 0, numUserParams);
params = newBinds;
} else
params = DEFAULT_VALUES_STRING;
// We have to call this method to convert the default values into the proper Oracle Array expected by the query.
// If you set a debugger breakpoint at this line you can see that the "params" data type changes from String[] to Object[]
setWhereClauseParamsToDefaultValues();
// Now retrieve the params of the new data type
params = this.getWhereClauseParams();
super.executeQueryForCollection(qc, params, numUserParams);
private void setWhereClauseParamsToDefaultValues()
this.setManagerID(DEFAULT_VALUES_STRING);
private Connection getCurrentConnection() throws SQLException
// Create a bogus statement so that we can access our current connection
// JBD note - Does this get run each time??
PreparedStatement st = getDBTransaction().createPreparedStatement("commit", 1);
Connection conn = st.getConnection();
st.close();
return conn;
private synchronized void setupDescriptor(Connection conn) throws SQLException
descriptor = new ArrayDescriptor("TABLE_OF_VARCHAR", conn);
* setManagerID
* Exposed to client to accept an array of values (presumably passed in by user-entry into text box
* @param aryMan
public void setManagerID(String[] aryMan)
Array arr = null;
try
// Find the connection
Connection conn = getCurrentConnection();
//Create the ArrayDescriptor by looking for our custom data type in our connected DB
if(descriptor == null)
setupDescriptor(conn);
// Create the Oracle Array by passing in the descriptor, connection, and object array of data
arr = new Array(descriptor, conn, aryMan);
} catch (SQLException se)
System.out.println("SQL Exception: " + se.getMessage());
// Now we can set the WHERE clause parameter bind variable (index = 0) to the Oracle Array
if (arr != null) setWhereClauseParam(0, arr);
* FILE: Panel1.java
* Created as an empty panel. Then a JTextField, a
* JButton, and an EmpView1 table were dragged on.
* A custom actionPerformed method was created for the
* JButton which grabs the data from the text box.
* The user can enter either a single manager id or
* multiple, comma-separated ids.
* All code in this class was created by JDev except
* for the Jbutton action
package view;
import java.awt.*;
import javax.swing.*;
import model.common.*;
import oracle.jbo.ApplicationModule;
import oracle.jbo.SQLStmtException;
import oracle.jbo.uicli.jui.*;
import oracle.jbo.uicli.controls.*;
import oracle.jbo.uicli.binding.*;
import oracle.jdeveloper.layout.*;
import oracle.adf.model.*;
import oracle.adf.model.binding.*;
import java.util.ArrayList;
import oracle.jdeveloper.layout.VerticalFlowLayout;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Panel1 extends JPanel implements JUPanel
* NOTE: You need to have previous created the Oracle8 type named
* ==== TABLE_OF_VARCHAR by doing the following at the SQL*Plus
* command prompt:
* create type table_of_varchar as table of varchar2(20)
// Panel binding definition used by design time
private JUPanelBinding panelBinding = new JUPanelBinding("Panel1UIModel");
private VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
private JTextField jTextField1 = new JTextField();
private JButton jButton1 = new JButton();
private JTable jTable1 = new JTable();
* The default constructor for panel
public Panel1()
* the JbInit method
public void jbInit() throws Exception
this.setLayout(verticalFlowLayout1);
jTextField1.setText("jTextField1");
jButton1.setText("jButton1");
jButton1.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
jButton1_actionPerformed(e);
this.add(jTextField1, null);
this.add(jButton1, null);
this.add(jTable1, null);
jTable1.setModel((TableModel)panelBinding.bindUIControl("EmpView1", jTable1));
public static void main(String [] args)
try
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
catch(Exception exemp)
exemp.printStackTrace();
Panel1 panel = new Panel1();
panel.setBindingContext(JUTestFrame.startTestFrame("DataBindings.cpx", "null", panel, panel.getPanelBinding(), new Dimension(400, 300)));
panel.revalidate();
* JUPanel implementation
public JUPanelBinding getPanelBinding()
return panelBinding;
private void unRegisterProjectGlobalVariables(BindingContext bindCtx)
JUUtil.unRegisterNavigationBarInterface(panelBinding, bindCtx);
private void registerProjectGlobalVariables(BindingContext bindCtx)
JUUtil.registerNavigationBarInterface(panelBinding, bindCtx);
public void setBindingContext(BindingContext bindCtx)
if (panelBinding.getPanel() == null)
panelBinding = panelBinding.setup(bindCtx, this);
registerProjectGlobalVariables(bindCtx);
panelBinding.refreshControl();
try
jbInit();
panelBinding.refreshControl();
catch(Exception ex)
panelBinding.reportException(ex);
private void jButton1_actionPerformed(ActionEvent e)
// Get the user-supplied values
String txt = jTextField1.getText();
String[] mIds = txt.split(",");
// Now trim
for (int i=0; i<mIds.length; i++)
mIds[i] = mIds.trim();
ApplicationModule am = (ApplicationModule)panelBinding.getDataControl().getDataProvider();
EmpView vo = (EmpView)am.findViewObject("EmpView1");
vo.setManagerID(mIds);
try
vo.executeQuery();
} catch (SQLStmtException s)
System.out.println("Query failed: " + s.getMessage());

Similar Messages

  • SQL IN clause with a Tool variable

     

    We are using using Forte 3.M.2 (just upgraded from 3.G, finally).
    Platform is AIX 4.3. Database is DB2 (UDB) (version 5.2 i think).
    True, I haven't tried my code on any other platform. I think it should work on NT, because one of our other teams members has set up an NT laptop for portable demos. And it has DB2 (NT version i guess) loaded on it.
    Dynamic sql is not really that bad, if you have to go that route to build your list.
    Let me know how it goes.
    Steven Barnes
    Daniel Gonz&aacute;lez de Lucas <danieleam.es> 07/28/00 04:06AM >>>We are getinng some trouble, the DB Manager seems to try to convert
    :OfficeList to a unique integer lets say:
    :OfficeList value is 3,4,7
    so the IN clause
    trying with Oracle 8.1.5 converts 3,4,7 in a unique integer (a extrange
    value because doesn't match with 3,4 nor 7).
    trying with SQL Server 6.5 gives an error converting 3,4,7 to a unique
    tinyint.
    The idea is that with your sintax the DB Manager must split the TextData
    into 3 integer values. I think that it works fine in some DB Managers and
    not in others.
    Which release and vendor of DB Manager you use?
    Which Fort&eacute; release?
    Thank you very much in advance.
    Daniel.
    ----- Original Message -----
    From: "Steve Barnes" <DHS9126dhs.state.il.us>
    To: <danieleam.es>; <kamranaminyahoo.com>
    Sent: Thursday, July 27, 2000 1:55 PM
    Subject: Re: (forte-users) SQL IN clause with a Tool variable
    I needed to have an "IN" clause for some numbers. Here's how I did it:
    GetOffices():TextData method...
    Offices : TextData = new ;
    for (x : integer) in sql select MyIntegerColumn
    from MY_TABLE
    where whatever condition
    on session MyDBSession do
    Offices.Concat(x) ;
    Offices.Concat(',') ;
    end for ;
    return (Offices.CopyRange(0,Offices.ActualSize -1)) ; // get rid of lastcomma
    in actual sql.....
    OfficeList : TextData ;
    OfficeList = GetOffices() ;
    sql select * from MyTable where MyField in (:OfficeList)
    on session MyDBSession ;
    Works very well.
    Steven Barnes
    Daniel Gonz&aacute;lez de Lucas <danieleam.es> 07/27/00 05:32AM >>>Hello,
    To do a select we have two options:
    select * from MyTable
    where MyField in ('a','b','c')
    we would like to do the same but using a fort&eacute; variable in the IN clause.
    select * from MyTable
    where MyField in (:ToolVar)
    What should we do and what kind of variable or array of variables shouldwe use in ToolVar to do the same than in first option?
    >
    Has anybody done this without a dynamic query?
    Best regards
    Daniel
    For the archives, go to: http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.com

  • Where clause with Bind Variable in ViewObject

    As per recomendations from Jdev team they say that using Bind varialbles in where clause will improve the performance (Option 1) But it is causing us to create more view objects.
    Example : Lets say we have a View Object EmpVO
    Option 1:
    ViewObject vo=context.getViewObject("EmpVO");
    vo.setWhereClause("EMPNO=?");
    vo.setWhereClauseParam(0,st);
    (or)
    Option 2:
    vo.setWhereClause("EMPNO="+st);
    If we want to use same View Object "EmpVO" in another Action Class
    ViewObject vo1=context.getViewObject("EmpVO");
    vo1.setWhereClause("DEPTNO=?");
    vo1.setWhereClauseParam(0,str);
    It this case it throws an error saying BIND VARIABLE already exits. So we have to make another View Object.
    Where as if we did not use bind variable but used Option 2 approach the same view object can be used in multiple pages.(at the expense of performance as per Jdev team)
    Are we doing something wrong here or are there other ways to use the same view object when using bind variable in where clause.
    Thanks

    I haven't been using BC4J for a while, but I seem to recall that the recommendations are that you don't set the where clause at runtime: You're supposed to define your view with the bind parameter already in it.
    So you'd probably define an EmpsForEmpNoVO and type "EMPNO = ?" in the where box. (There are other ways of finding a single row/entity and one of those may well be more efficient. Perhaps a better example of where you might want a view of employees is WHERE DEPTNO = ?.)
    IIRC, all instances of a particular type of view share the same definition, so you have to be careful if you alter that at runtime. However, I think everything's set up so that you can have many different (and separate) resultsets for a single view (instance) - meaning that it's possible to "run" a view for (e.g.) two different ids. (It's definitely possible to create two different instances of a view from its definition - and the resultsets will definitely be separate then. I think there's a "create" method on the application module; I remember that "find..." always returns the same instance of the view.)
    Hope that's a push in the right direction (since no-one else had replied - and I hope not too much has changed since 9.0.3)....
    Mike.

  • Writing order by clause with user parameter

    I have a user parameter where the user is supposed to choose what column they want to sort by.
    And they can choose between k.personnr and k.personnavn. I am trying to do this with a decode function.
    Now this would work fine if there was no union between these select statements.
    But with the union I get a ORA-01785, where they tell me to put in a number.
    Here is the sql:
    SELECT
    k.personnr as PERSON ,
    k.personnavn as NAVN,
    r.belop as SUM,
    concat(to_char(r.bilagdato,'MM'), to_char(r.bilagdato,'YYYY')) AS MND,
    PERIODE(concat(to_char(r.bilagdato,'MM'), to_char(r.bilagdato,'YYYY'))) AS PERIODE
    FROM
    reskontro r,
    klient k,
    kontoplan p,
    konto c
    WHERE
    r.distriktnr='21'
    and r.distriktnr=c.kontoid
    and r.distriktnr=k.distriktnr
    and r.personnr=k.personnr
    and r.kontonr=p.kontonr
    and (((r.bilagdato between :p_fra_dato and :p_til_dato) and (:p_fra_dato <= c.overfort) and (:p_til_dato <= c.overfort))
    or ((r.bilagdato between :p_fra_dato and c.overfort) and (:p_fra_dato <= c.overfort) and (:p_til_dato >= c.overfort)))
    UNION ALL
    SELECT
    k.personnr as PERSON ,
    k.personnavn as NAVN,
    (t.belop/100) as SUM,
    concat(to_char(t.bilagdato,'MM'), to_char(t.bilagdato,'YYYY')) AS MND,
    PERIODE(concat(to_char(t.bilagdato,'MM'), to_char(t.bilagdato,'YYYY')),:P_HORISONTAL) AS PERIODE
    FROM
    transaksjon t,
    klient k,
    kontoplan p
    WHERE
    t.distriktnr='21'
    and t.distriktnr=k.distriktnr
    and t.personnr=k.personnr
    and t.kontonr=p.kontonr
    and t.bilagdato between :p_fra_dato and :p_til_dato
    This is the order by clause I would like to use:
    order by decode(:p_order_by,'Personnavn',k.personnavn,k.personnr)
    I also get an error when I use:
    order by decode(:p_order_by,'Personnavn',2,1)
    Can anybody tell me how to work around this problem?

    Hi,
    One way you can do to get around this problem could be :
    select * from (
    SELECT
    k.personnr as PERSON ,
    k.personnavn as NAVN,
    r.belop as SUM,
    concat(to_char(r.bilagdato,'MM'), to_char(r.bilagdato,'YYYY')) AS MND,
    PERIODE(concat(to_char(r.bilagdato,'MM'), to_char(r.bilagdato,'YYYY'))) AS PERIODE
    FROM
    reskontro r,
    klient k,
    kontoplan p,
    konto c
    WHERE
    r.distriktnr='21'
    and r.distriktnr=c.kontoid
    and r.distriktnr=k.distriktnr
    and r.personnr=k.personnr
    and r.kontonr=p.kontonr
    and (((r.bilagdato between :p_fra_dato and :p_til_dato) and (:p_fra_dato <= c.overfort) and (:p_til_dato <= c.overfort))
    or ((r.bilagdato between :p_fra_dato and c.overfort) and (:p_fra_dato <= c.overfort) and (:p_til_dato >= c.overfort)))
    UNION ALL
    SELECT
    k.personnr as PERSON ,
    k.personnavn as NAVN,
    (t.belop/100) as SUM,
    concat(to_char(t.bilagdato,'MM'), to_char(t.bilagdato,'YYYY')) AS MND,
    PERIODE(concat(to_char(t.bilagdato,'MM'), to_char(t.bilagdato,'YYYY')),:P_HORISONTAL) AS PERIODE
    FROM
    transaksjon t,
    klient k,
    kontoplan p
    WHERE
    t.distriktnr='21'
    and t.distriktnr=k.distriktnr
    and t.personnr=k.personnr
    and t.kontonr=p.kontonr
    and t.bilagdato between :p_fra_dato and :p_til_dato)
    order by decode(:p_order_by,'Personnavn', NAVN, PERSON)
    /Uffe

  • Wrong SQL (WHERE Clause) with Generic DS based on Wiew

    Hi to all of you,
    we have a problem that happens sometimes (it seems to have a random behaviour).
    Generic Extractors based on Views sometimes are interpreted on R/3 ORACLE without considering Selection Conditions imposed in InfoPackages (that are in other words WHERE conditions). When this happens R/3 runs in abnorma termination (DUMP) after a long time.
    Any idea? We still haven't found any suitable OSS Note ...
    Many thanks in advance
    GFV
    Message was edited by: Gianfranco Vallese

    Try:
    update table1
    set matl_analyst_grp = (SELECT table1.testnew
                              from table1, table2
                             where (table1.catalog_id = table2.catalog_id)
                               AND (table2.vendor_code like '%PIPING %')
    HTH
    Ghulam                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Error in calling SQL plus program with parameter from Shell script

    This is my Shell script. I am trying to call in the SQL plus program with the parameter and the shell script is registered as a concurrent program.
    PARAMETERS=`echo $1 |tr -d '\"'`
    DB_USER_ID=`echo $PARAMETERS|cut -d" " -f3|cut -d"=" -f2`
    CONN_STRING=$DB_USER_ID
    REQ_DATE=`echo $PARAMETERS|cut -d" " -f9|cut -d"=" -f2`
    timestamp=`date +%m-%d-%y-%H:%M:%S-%Z`
    timestam=`date +%y-%m-%d`
    sqlplus -s $CONN_STRING @ar_statement.sql $REQ_DATE
    chmod 755 statement.sh
    . statement.sh
    My Sql plus program is like this.
    set pagesize 0
    set heading off
    set feedback off
    spool $GEC_TOP/log/ge_ar_statement.sh
    select output_file_name
    from fnd_concurrent_requests
    where trunc(actual_completion_date) = '&2';
    spool off;
    exit;
    When i run the concurrent program, i am getting the following error:
    ar_statement: line 14: REQ_DATE: command not found
    Enter value for 2:
    User requested Interrupt or EOF detected.
    ar_statement.sh: line 1: Enter: command not found
    ar_statement.sh: line 2: User: command not found
    ar_statement
    Program exited with status 127
    I am not strong at Unix Porgamming and i would request someone who can
    help me out as soon as possible.
    I need this solution quickly and thank everyone in advance.
    Thanks.

    Can you put your coding between code statements, like shown in the FAQ. It will be easier to read.
    Looking at your script, my first guess is that crontab will not find your sqlplus since your script does not have $HOME/bin in the $PATH. From what I understand, running .profile in your script will not work either because variables are exported to sub-shells, not to the shell above. You can call your script with a dot like . ./script which means that the script will run like it was typed at the command prompt. But it will be less confusing to define appropriate variables in the script. eg.
    ORACLE_SID=my_instance_name
    ORACLE_HOME=/my_path_to_oracle_home_directory
    LD_LIBRARY_PATH=$ORACLE_HOME/lib
    PATH=$ORACLE_HOME/bin:$PATH
    I remember some slightly different way of coding to handle the sqlplus return codes.
    For instance:
    sqlplus -s /nolog > /dev/null <<-EOF
    connect system/manager
    @ssm.sql
    whenever oserror exit failure
    whenever sqlerror exit failure
    EOF
    sql_err=$?
    if [ $sql_err -ne 0 ]; then
       echo "FAILURE"
    else
       echo "SUCCESS"
    fiThe - in -EOF supresses tab's
    Using connect will prevent ps from showing your login credentials
    In some versions of bash the ending EOF needs to be at the beginning of the line to work.
    Edited by: waldorfm on Jul 14, 2010 7:05 PM
    complaining about putting code between code delimiters and forgot myself ;-)
    Edited by: waldorfm on Jul 14, 2010 7:08 PM
    Btw, if you "source" a script running it like . .script, than an exit in that script will log you out.

  • SQL is slow with optimizer_mode=ALL_ROWS

    Hi.
    We have an application layer with htmldb 2.0 running on 10.2 on HP-UX Itanium.
    One of the applications runs a sql joining two tables and using bind variables as in the selection critieria.
    The two tables has the following number of rows;
    SQL> select count(1) from innsyn_kunde.kunde;
    COUNT(1)
    96708
    SQL> select count(1) from innsyn_kunde.regning;
    COUNT(1)
    1867136
    SQL>
    The following intialization parameters are set on instances level:
    SQL> show parameter optimiz
    NAME TYPE VALUE
    optimizer_dynamic_sampling integer 2
    optimizer_features_enable string 10.2.0.1
    optimizer_index_caching integer 80
    optimizer_index_cost_adj integer 10
    optimizer_mode string FIRST_ROWS
    optimizer_secure_view_merging boolean TRUE
    plsql_optimize_level integer 2
    SQL>
    All tables and indexes used by the application has fresh statistics gathered with dbms_stats.
    The following sql is defined in htmldb:
    select
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn
    , innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr(+)
    and regn.appl_kode = :P31_appl_kode
    and regn.kundenr like upper(decode(:P31_kundenr,null,'%',:P31_kundenr||'%'))
    and regn.regningnr like decode(:P31_regningnr,null,'%',:P31_regningnr||'%')
    and kund.kundenavn like upper(decode(:P31_kundenavn,null,'%',:P31_kundenavn||'%'))
    order by regn.regningdato desc
    1) If we substitute the bind variables with actual values in the actual sql in order to fetch one row the query runs very fast:
    select
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn
    , innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr(+)
    and regn.appl_kode = 'SKOL'
    and regn.kundenr like '%'
    and regn.regningnr like '1150456%'
    and kund.kundenavn like '%'
    order by regn.regningdato desc
    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 5 8 0 1
    total 4 0.00 0.00 5 8 0 1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 95 (INNSYN_KUNDE)
    Rows Row Source Operation
    1 SORT ORDER BY (cr=8 pr=5 pw=0 time=343 us)
    1 NESTED LOOPS (cr=8 pr=5 pw=0 time=315 us)
    1 TABLE ACCESS BY INDEX ROWID REGNING (cr=4 pr=1 pw=0 time=182 us)
    1 INDEX RANGE SCAN REGNING_IDX_03 (cr=3 pr=1 pw=0 time=165 us)(object id 68870)
    1 TABLE ACCESS BY INDEX ROWID KUNDE (cr=4 pr=4 pw=0 time=129 us)
    1 INDEX UNIQUE SCAN PK_KUNDE (cr=3 pr=3 pw=0 time=99 us)(object id 68356)
    Rows Execution Plan
    0 SELECT STATEMENT MODE: ALL_ROWS
    1 SORT (ORDER BY)
    1 NESTED LOOPS
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'REGNING'
    (TABLE)
    1 INDEX MODE: ANALYZED (RANGE SCAN) OF 'REGNING_IDX_03'
    (INDEX)
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'KUNDE'
    (TABLE)
    1 INDEX MODE: ANALYZED (UNIQUE SCAN) OF 'PK_KUNDE' (INDEX
    (UNIQUE))
    2) If we use bind variables to reproduce the problem in htmldb from sqlplus like this we get the following result;
    select
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn
    , innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr(+)
    and regn.appl_kode = :P31_appl_kode
    and regn.kundenr like upper(decode(:P31_kundenr,null,'%',:P31_kundenr||'%'))
    and regn.regningnr like decode(:P31_regningnr,null,'%',:P31_regningnr||'%')
    and kund.kundenavn like upper(decode(:P31_kundenavn,null,'%',:P31_kundenavn||'%'))
    order by regn.regningdato desc
    call count cpu elapsed disk query current rows
    Parse 3 0.00 0.00 0 0 0 0
    Execute 3 0.00 0.00 0 0 0 0
    Fetch 2 30.19 32.64 516728 1406955 0 1
    total 8 30.19 32.64 516728 1406955 0 1
    Misses in library cache during parse: 0
    Parsing user id: 64 (INNSYN_WEB) (recursive depth: 1)
    Rows Row Source Operation
    1 SORT ORDER BY (cr=1406955 pr=516728 pw=75 time=32643407 us)
    1 TABLE ACCESS BY INDEX ROWID REGNING (cr=1406955 pr=516728 pw=75 time=32643357 us)
    1354432 NESTED LOOPS (cr=106950 pr=42778 pw=75 time=17612677 us)
    50191 VIEW index$_join$_002 (cr=661 pr=736 pw=75 time=447634 us)
    50191 HASH JOIN (cr=661 pr=736 pw=75 time=297306 us)
    50191 INDEX RANGE SCAN PK_KUNDE (cr=258 pr=258 pw=0 time=163 us)(object id 68356)
    96705 INDEX RANGE SCAN KUNDE_IDX01 (cr=403 pr=403 pw=0 time=97049 us)(object id 68688)
    1304240 INDEX RANGE SCAN REGNING_IDX_01 (cr=106289 pr=42042 pw=0 time=3401535 us)(object id 68363)
    Rows Execution Plan
    0 SELECT STATEMENT MODE: ALL_ROWS
    1 SORT (ORDER BY)
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'REGNING'
    (TABLE)
    1354432 NESTED LOOPS
    50191 VIEW OF 'index$_join$_002' (VIEW)
    50191 HASH JOIN
    50191 INDEX MODE: ANALYZED (RANGE SCAN) OF 'PK_KUNDE'
    (INDEX (UNIQUE))
    96705 INDEX MODE: ANALYZED (RANGE SCAN) OF 'KUNDE_IDX01'
    (INDEX)
    1304240 INDEX MODE: ANALYZED (RANGE SCAN) OF 'REGNING_IDX_01'
    (INDEX)
    By using bind-variables it uses 30 seconds to fetch one row that is returned in less than a second with standard litherals
    3) And by doing something we probably not should, at least on 10.2 is to hint with RULE based optimization.
    Parsing user id: 95 (INNSYN_KUNDE)
    select /*+ RULE */
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn,
    innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr (+)
    and regn.appl_kode = :P31_appl_kode
    and regn.kundenr like upper(decode(:P31_kundenr,null,'%',:P31_kundenr||'%'))
    and regn.regningnr like decode(:P31_regningnr,null,'%',:P31_regningnr||'%')
    and kund.kundenavn like upper(decode(:P31_kundenavn,null,'%',:P31_kundenavn||'%'))
    order by regn.regningdato desc
    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.13 0.12 1109 1122 0 1
    total 4 0.13 0.12 1109 1122 0 1
    Misses in library cache during parse: 0
    Optimizer mode: RULE
    Parsing user id: 95 (INNSYN_KUNDE)
    Rows Row Source Operation
    1 SORT ORDER BY (cr=1122 pr=1109 pw=0 time=123795 us)
    1 FILTER (cr=1122 pr=1109 pw=0 time=123752 us)
    1 MERGE JOIN OUTER (cr=1122 pr=1109 pw=0 time=123735 us)
    1 SORT JOIN (cr=4 pr=0 pw=0 time=125 us)
    1 TABLE ACCESS BY INDEX ROWID REGNING (cr=4 pr=0 pw=0 time=83 us)
    1 INDEX RANGE SCAN REGNING_IDX_03 (cr=3 pr=0 pw=0 time=64 us)(object id 68870)
    1 SORT JOIN (cr=1118 pr=1109 pw=0 time=123601 us)
    96708 TABLE ACCESS FULL KUNDE (cr=1118 pr=1109 pw=0 time=199 us)
    Rows Execution Plan
    0 SELECT STATEMENT MODE: HINT: RULE
    1 SORT (ORDER BY)
    1 FILTER
    1 MERGE JOIN (OUTER)
    1 SORT (JOIN)
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF
    'REGNING' (TABLE)
    1 INDEX MODE: ANALYZED (RANGE SCAN) OF
    'REGNING_IDX_03' (INDEX)
    1 SORT (JOIN)
    96708 TABLE ACCESS MODE: ANALYZED (FULL) OF 'KUNDE' (TABLE)
    By using Rule based it uses 0.1 second to fetch one row from the database.
    Anyone seen this problems using Cost based with good statistics and bind variables giving such bad performance .
    Any help would be apreciated.
    rgds
    Kjell

    I have to add that sql that runs with bind variables is defined the following way:
    variable P31_appl_kode varchar2(10);
    variable P31_kundenr varchar2(10);
    variable P31_regningnr varchar2(10);
    variable P31_kundenavn varchar2(10);
    begin
    :p31_appl_kode := 'SKOL';
    :p31_kundenr :=NULL;
    :p31_regningnr :='1150456';
    :p31_kundenavn := null;
    end;
    select /*+ RULE */
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn,
    innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr (+)
    and regn.appl_kode = :P31_appl_kode
    and regn.kundenr like upper(decode(:P31_kundenr,null,'%',:P31_kundenr||'%'))
    and regn.regningnr like decode(:P31_regningnr,null,'%',:P31_regningnr||'%')
    and kund.kundenavn like upper(decode(:P31_kundenavn,null,'%',:P31_kundenavn||'%'))
    order by regn.regningdato desc;
    rgds
    Kjell

  • How to implement list of values with bind parameters

    Hi All,
    Please give me details about how to implement list of values with bind parameters.
    I have implemented with below things.
    1) created lov view object with query like select meaning, lookup_code from fnd_lookup_values where lookup_type=:1;
    2) The above vo added to applicationa module.
    3) created Controller class in the co class written code in processRequest();
    String vLookupType=pageContext.getParameter("LookupType");
    Serializable params={vLookupType};
    am.invokemethod("Initialize",params);
    4) In AM Impl Class invoke the VO
    5) In VO Impl class executed the query..
    But the above process working fine but when i give the value in lov text field like 'C' then press tab button the result will not showing instead of that i am getting error message, i want to implement standard lov functionality while implementing query with bind parameter.
    any thing reqired to add the code to controller for search criteria..
    Thanks
    Mateti

    Hi
    i am getting error as
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (SELECT meaning, lookup_code,lookup_type
    FROM fnd_lookup_values
    WHERE view_application_id = 200) QRSLT WHERE (lookup_type=:1 AND ( UPPER(MEANING) like :2 AND (MEANING like :3 OR MEANING like :4 OR MEANING like :5 OR MEANING like :6)))
    Thanks
    Mateti

  • ADF Groovy Expression with bind variable and ResourceBundle

    Now I have ViewObject which have WHERE clause with bind variable.
    This bind variable is for language. Within bind variable I can change Value Type to Expression and into Value: I put +(ResourceBundle.getBundle("model.ModelBundle")).getString("language")+.
    Now if I run Oracle Business Component Browser (on AppModule) this works. In my ModelBundle.properties there is language=1 name-value pair. And with different locale I have different language number.
    Now if I put that ViewObject on one JSF, this bind variable expression does not work any more. Error:
    *oracle.jbo.JboException: JBO-29000: Unexpected exception caught: java.util.MissingResourceException, msg=Can't find bundle for base name model.ModelBundle, locale my_locale*
    Any ideas?
    10x
    Zmeda

    The most wierd thing is that, if I make ViewObjectImpl and insert this method
    public String getLanguage() {
    return (ResourceBundle.getBundle("model.ModelBundle")).getString("language");
    and call it in Bind Variable Expression Value: viewObject.getLanguage()
    IT WORKS!
    But why with groovy expression it does not work?
    Zmeda

  • Binding parameters to dynamic VO with PL/SQL API call with no where clause

    Hi all,
    I am required to change exisiting queries to queries with "bind" parameters. Some of our VOs are dynamic and with PL/SQL api calls like below:
    String stmtStr = "selectXXX_API_UTILS.chk_urg_since_last_prg("
    + projectId + "," + PPCId + ",'XYZ_TASKS'," + taskId+ ")"
    +" from dual ";
    ViewObject tmpVO = transaction.createViewObjectFromQueryStmt(stmtStr);
    In this regard, I am unsure how to bind the PPCId and taskId parameters to the VO. setWhereClauseParams() would not work here as there is now where clause.
    Thanks in advance,
    Srini

    In case of preparedStatement, we mention bind parameters to be passed using "?". Then we pass paramters sequencially.
    But in the your case following is enough:
    int projectId = 100 ; (hardcoding values for example)
    int taskId = 500 ;
    String stmtStr = "selectXXX_API_UTILS.chk_urg_since_last_prg("
    + projectId + "," + PPCId + ",'XYZ_TASKS'," + taskId+ ")"
    +" from dual ";
    -Anand

  • Binding parameter to SQL/xpath query using java/jdbc

    I'm trying to execute a query containing an xpath.
    The query looks like this:
    select * FROM table  t where t.column.existsNode('/RootElement[contains(SubElement, "someVal")]/SubElement')In java replacing the "someVal" with a bind parameter "?" will not work:
    PreparedStatement ps = c.prepareStatement("select * FROM table t where t.column.existsNode('/RootElement[contains(SubElement, ? )]/SubElement') = 1");
    ps.setString(1,"someVal");
    =EXCEPTIONOn this forum I found that you can also use '||:namedParam||'
    So the query in java would be executed like;
    PreparedStatement ps = c.prepareStatement("select * FROM table t where t.column.existsNode('/RootElement[contains(SubElement, '||:1||' )]/SubElement') = 1");
    ps.setString(1,"someVal");This seems to work (I have no idea what the '|| ||' construct does, I don't seem to find any info about it)
    HOWEVER, it seems that doing it this way the value being bound is NOT escaped.
    So, doing this will yield in an orcale SQL/xpath exception:
    ps.setString(1,"som'eVal");
    I've went to all the oracle xml manual stuff I could find, but nowhere do they address this.
    Any one an idea how I can bind the value and still have escaping ?
    Edited by: user5893566 on Nov 27, 2008 12:06 AM
    Edited by: user5893566 on Nov 27, 2008 12:15 AM

    Would you mind explain me what the replace actually does?The idea is like this:
    Let's start with a string like some'V"al and surround it by the concat function:
      '...concat("' || some'V"al || '") ....' {code}
    replace the inner (i.e. all) double quotes with +",''","+ to obtain '...concat("' || some'V",''"'',"al || '") ...' {code}
    So this concatenates three parts of the original string where the double quotes are now enclosed by two single quotes. The resulting string should look like
    {code} '...concat("some'V",''"'',"al") ...'i.e. first argument of concat is enclosed by double quotes, the second one by two single quotes and the third one again by double quotes.  This is just a rewritten form of our original string!.
    Now incorporate the whole thing in the xpath expression  as shown in my previous example and it should work ;)
    hth
    michael                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • VARRAY bind parameter in IN clause causes Full Table Scan

    Hi
    My problem is that Oracle elects to perform a full table scan when I want it to use an index.
    The situation is this: I have a single table SQL query with an IN clause such as:
    SELECT EMPNO, ENAME, JOB FROM EMP WHERE ENAME IN (...)
    Since this is running in an application, I want to allow the user to provide a list of ENAMES to search. Because IN clauses don't accept bind parameters I've been using the Tom Kyte workaround which relies on setting a bind variable to an array-valued scalar, and then casting this array to be a table of records that the database can handle in an IN clause:
    SELECT *
    FROM EMP
    WHERE ENAME IN (
    SELECT *
    FROM TABLE(CAST( ? AS TABLE_OF_VARCHAR)))
    This resulted in very slow performance due to a full table scan. To test, I ran the SQL in SQL*Plus and provided the IN clause values in the query itself. The explain plan showed it using my index...ok good. But once I changed the IN clause to the 'select * from table...' syntax Oracle went into Full Scan mode. I added an index hint but it didn't change the plan. Has anyone had success using this technique without a full scan?
    Thanks
    John
    p.s.
    Please let me know if you think this should be posted on a different forum. Even though my context is a Java app developed with JDev this seemed like a SQL question.

    Justin and 3360 - that was great advice and certainly nothing I would have come up with. However, as posted, the performance still wasn't good...but it gave me a term to Google on. I found this Ask Tom page http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:3779680732446#15740265481549, where he included a seemingly magical 'where rownum >=0' which, when applied with your suggestions, turned my query from minutes into seconds.
    My plans are as follows:
    1 - Query with standard IN clause
    SQL> explain plan for
    2 select accession_number, protein_name, sequence_id from protein_dim
    3 where accession_number in ('33460', '33458', '33451');
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 7 | 336 | 4 |
    | 1 | INLIST ITERATOR | | | | |
    | 2 | TABLE ACCESS BY INDEX ROWID| PROTEIN_DIM | 7 | 336 | 4 |
    | 3 | INDEX RANGE SCAN | IDX_PROTEIN_ACCNUM | 7 | | 3 |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    11 rows selected.
    2 - Standard IN Clause with Index hint
    SQL> explain plan for
    2 select /*+ INDEX(protein_dim IDX_PROTEIN_ACCNUM) */
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source
    4 from pdssuser.protein_dim
    5 where accession_number in
    6 ('33460', '33458', '33451');
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 7 | 588 | 4 |
    | 1 | INLIST ITERATOR | | | | |
    | 2 | TABLE ACCESS BY INDEX ROWID| PROTEIN_DIM | 7 | 588 | 4 |
    | 3 | INDEX RANGE SCAN | IDX_PROTEIN_ACCNUM | 7 | | 3 |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    11 rows selected.
    3 - Using custom TABLE_OF_VARCHAR type
    CREATE TYPE TABLE_OF_VARCHAR AS
    TABLE OF VARCHAR2(50);
    SQL> explain plan for
    2 select
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source
    4 from pdssuser.protein_dim
    5 where accession_number in
    6 (select * from table(cast(TABLE_OF_VARCHAR('33460', '33458', '33451') as TABLE_OF_VARCHAR)) t);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 2 | 168 | 57M|
    | 1 | NESTED LOOPS SEMI | | 2 | 168 | 57M|
    | 2 | TABLE ACCESS FULL | PROTEIN_DIM | 5235K| 419M| 13729 |
    | 3 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | | | |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    11 rows selected.
    4 - Using custom TABLE_OF_VARCHAR type w/ Index hint
    SQL> explain plan for
    2 select /*+ INDEX(protein_dim IDX_PROTEIN_ACCNUM) */
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source
    4 from pdssuser.protein_dim
    5 where accession_number in
    6 (select * from table(cast(TABLE_OF_VARCHAR('33460', '33458', '33451') as TABLE_OF_VARCHAR)) t);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 2 | 168 | 57M|
    | 1 | NESTED LOOPS SEMI | | 2 | 168 | 57M|
    | 2 | TABLE ACCESS BY INDEX ROWID | PROTEIN_DIM | 5235K| 419M| 252K|
    | 3 | INDEX FULL SCAN | IDX_PROTEIN_ACCNUM | 5235K| | 17255 |
    | 4 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | | | |
    PLAN_TABLE_OUTPUT
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    12 rows selected.
    5 - Using custom TABLE_OF_VARCHAR type w/ cardinality hint
    SQL> explain plan for
    2 select
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source from protein_dim
    4 where accession_number in (select /*+ cardinality( t 10 ) */
    5 * from TABLE(CAST (TABLE_OF_VARCHAR('33460', '33458', '33451') AS TABLE_OF_VARCHAR)) t);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 2 | 168 | 57M|
    | 1 | NESTED LOOPS SEMI | | 2 | 168 | 57M|
    | 2 | TABLE ACCESS FULL | PROTEIN_DIM | 5235K| 419M| 13729 |
    | 3 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | | | |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    11 rows selected.
    6 - Using custom TABLE_OF_VARCHAR type w/ cardinality hint
    and rownum >= 0 constraint
    SQL> explain plan for
    2 select
    3 accession_number, protein_name, sequence_id, taxon_id, organism_name, data_source from protein_dim
    4 where accession_number in (select /*+ cardinality( t 10 ) */
    5 * from TABLE(CAST (TABLE_OF_VARCHAR('33460', '33458', '33451') AS TABLE_OF_VARCHAR)) t
    6 where rownum >= 0);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 25 | 2775 | 43 |
    | 1 | TABLE ACCESS BY INDEX ROWID | PROTEIN_DIM | 2 | 168 | 3 |
    | 2 | NESTED LOOPS | | 25 | 2775 | 43 |
    | 3 | VIEW | VW_NSO_1 | 10 | 270 | 11 |
    | 4 | SORT UNIQUE | | 10 | | |
    | 5 | COUNT | | | | |
    | 6 | FILTER | | | | |
    PLAN_TABLE_OUTPUT
    | 7 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | | | |
    | 8 | INDEX RANGE SCAN | IDX_PROTEIN_ACCNUM | 2 | | 2 |
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    16 rows selected.
    I don't understand why performance improved so dramatically but happy that it did.
    Thanks a ton!
    John

  • PL/SQL: how to use in parameter in select sql where clause

    Hi
    in a procedure, I need to apply 'in parameter' in 'where clause' along with other table fields. Purpose is to create dynamic select querry with multiple conditions.
    select count(*) from table xx
    where y_code=2008 and v_type in ('SI', 'TI', 'DI') ;
    my requirement is replace 'and v_type in ('SI', 'TI', 'DI')' with in parameter. pls note in paramter may contain null value.
    Regards

    ... e.g. why on earth do you want to pass in a string to be appended to the WHERE clause of an SQL.I second that and I strongly advice NOT to do it. If you really want to do it, then come back and show us, how you would prevent SQL injection. This approach is too dangerous (and too complex) IMHO.
    Do it straight forward as in the article of Tom Kyte (link in the post of BluShadow above)

  • Binding parameter with H-Grid

    I am having some problem binding parameter in H-Grid and here is the scenario.
    Here is the SQL for the H-Grid VO. I am binding the unit because I only want to displays the account for the selected "UNIT"
    SELECT account_id
    ,account_number
    ,account_name
    ,account_type
    ,account_category
    ,parent_account_id
    ,unit
    FROM cc_ia_accounts_v
    WHERE unit = :1
    I have also defined the view link where parent_account_id = account_id and in the view link sql is:
    :1 = PARENT_ACCOUNT_ID
    During run time I execute the following code:
    this.setWhereClause(null);
    this.setWhereClauseParams(null);
    this.setWhereClauseParam(0, pUnit);
    this.executeQuery();
    My H-Grid display no record with this binding. But if I replace the VO binding with a hard code value like below the H-Grid works:
    SELECT account_id
    ,account_number
    ,account_name
    ,account_type
    ,account_category
    ,parent_account_id
    ,unit
    FROM cc_ia_accounts_v
    WHERE unit = '23222'
    I think the problem is pUnit not properly binded to my VO. I have changed the VO binding parameter to ":2" to avoid the possible binding position in View Link but I get a run time error say "Not all parameter are binded"
    How can I work around this?
    Thanks in advance

    Hi,
    create a client interface method in viweobjectimpl, somewhat like this
        public void executeForBranches(int[] branch_code){
            ViewCriteria newVc = createViewCriteria();
            ViewCriteriaRow vcr = newVc.createViewCriteriaRow();
            StringBuilder sb=new StringBuilder();
            for(int bc:branch_code){
                if(sb.length()>0){
                    sb.append(",");
                sb.append(bc);
            String str="(" + sb.toString() + ")";
            //System.err.println("Param = " + str);
            vcr.setAttribute("OriginBranch", " IN " + str);
            newVc.insertRow(vcr);
            applyViewCriteria(newVc);
            //System.err.println(getQuery());
            executeQuery();
        }just dragand drop the clientmethod to your taskflow..
    for this you would need to remove the inclause from query
    SELECT DISTINCT d.dep_id, d.dep_name, e.emp_name from Department d, Employee e where
    d.dep_id = e.dep_id
    --and e.emp_type IN (:param)Regards,
    Santosh

  • Help with SQL MODEL Clause

    I have the privilege of performing a very tedious task.
    We have some home grown regular expressions in our company. I now need to expand these regular expressions.
    Samples:
    a = 0-3
    b = Null, 0, 1
    Expression: Meaning
    1:5: 1,2,3,4,5
    1a: 10, 11, 12, 13
    1b: 1, 10, 11
    1[2,3]ab: 120, 1200, 1201, ....
    It get's even more inetersting because there is a possibility of 1[2,3]a.ab
    I have created two base queries to aid me in my quest. I am using the SQL MODEL clause to solve this problem. I pretty confident that I should be able to convert evrything into a range and the use one of the MODEL clause listed below.
    My only confusion is how do I INCREMENT dynamically. The INCREMENT seems to be a constant in both a FOR and ITERATE statement. I need to figure a way to increment with .01, .1, etc.
    Any help will be greatly appreciated.
    CODE:
    Reference:          http://www.sqlsnippets.com/en/topic-11663.html
    Objective:          Expand a range with ITERATE
    WITH t AS
    (SELECT '2:4' pt
    FROM DUAL
    UNION ALL
    SELECT '6:9' pt
    FROM DUAL)
    SELECT pt AS code_expression
    -- , KEY
    -- , min_key
    -- , max_key
    , m_1 AS code
    FROM t
    MODEL
    PARTITION BY (pt)
    DIMENSION BY ( 0 AS KEY )
    MEASURES (
                        0 AS m_1,
                        TO_NUMBER(SUBSTR(pt, 1, INSTR(pt, ':') - 1)) AS min_key,
                        TO_NUMBER(SUBSTR(pt, INSTR(pt, ':') + 1)) AS max_key               
    RULES
    -- UPSERT
    ITERATE (100000) UNTIL ( ITERATION_NUMBER = max_key[0] - min_key[0] )
    m_1[ITERATION_NUMBER] = min_key[0] + ITERATION_NUMBER
    ORDER BY pt, m_1
    Explanation:
    Line numbers are based on the assupmtion that "WITH t AS" starts at line 5.
    If you need detailed information regarding the MODEL clause please refer to
    the Refrence site stated above or read some documentation.
    Partition-
    Line 18:     PARTITION BY (pt)
                   This will make sure that each "KEY" will start at 0 for each value of pt.
    Dimension-
    Line 19:     DIMENSION BY ( 0 AS KEY )     
                   This is necessary for the refrences max_key[0], and min_key[0] to work.
    Measures-
    Line 21:      0 AS m_1
                   A space holder for new values.
    Line 22:     TO_NUMBER(SUBSTR(pt, 1, INSTR(pt, ':') - 1)) AS min_key
                   The result is '1' for '1:5'.
    Line 23:     TO_NUMBER(SUBSTR(pt, INSTR(pt, ':') + 1)) AS max_key                                        
                   The result is '5' for '1:5'.
    Rules-
    Line 26:     UPSERT
                   This makes it possible for new rows to be created.
    Line 27:     ITERATE (100000) UNTIL ( ITERATION_NUMBER = max_key[0] - min_key[0] )
                   This reads ITERATE 100000 times or UNTIL the ITERATION_NUMBER = max_key[0] - min_key[0]
                   which would be 4 for '1:5', but since the ITERATION_NUMBER starts at 0, whatever follows
                   is repaeted 5 times.
    Line 29:     m_1[ITERATION_NUMBER] = min_key[0] + ITERATION_NUMBER
                   m_1[ITERATION_NUMBER] means m_1[Value of Dimension KEY].
                   Thus for each row of KEY the m_1 is min_key[0] + ITERATION_NUMBER.
    Reference:          http://www.sqlsnippets.com/en/topic-11663.html
    Objective:          Expand a range using FOR
    WITH t AS
    (SELECT '2:4' pt
    FROM DUAL
    UNION ALL
    SELECT '6:9' pt
    FROM DUAL)
    , base AS
    SELECT pt AS code_expression
    , KEY AS code
    , min_key
    , max_key
         , my_increment
    , m_1
    FROM t
    MODEL
    PARTITION BY (pt)
    DIMENSION BY ( CAST(0 AS NUMBER) AS KEY )
    MEASURES (
                        CAST(NULL AS CHAR) AS m_1,
                        TO_NUMBER(SUBSTR(pt, 1, INSTR(pt, ':') - 1)) AS min_key,
                        TO_NUMBER(SUBSTR(pt, INSTR(pt, ':') + 1)) AS max_key,     
                        .1 AS my_increment     
    RULES
    -- UPSERT
              m_1[FOR KEY FROM min_key[0] TO max_key[0] INCREMENT 1] = 'Y'
    ORDER BY pt, KEY, m_1
    SELECT code_expression, code
    FROM base
    WHERE m_1 = 'Y'
    Explanation:
    Line numbers are based on the assupmtion that "WITH t AS" starts at line 5.
    If you need detailed information regarding the MODEL clause please refer to
    the Refrence site stated above or read some documentation.
    Partition-
    Line 21:     PARTITION BY (pt)
                   This will make sure that each "KEY" will start at 0 for each value of pt.
    Dimension-
    Line 22:     DIMENSION BY ( 0 AS KEY )     
                   This is necessary for the refrences max_key[0], and min_key[0] to work.
    Measures-
    Line 24:      CAST(NULL AS CHAR) AS m_1
                   A space holder for results.
    Line 25:     TO_NUMBER(SUBSTR(pt, 1, INSTR(pt, ':') - 1)) AS min_key
                   The result is '1' for '1:5'.
    Line 26:     TO_NUMBER(SUBSTR(pt, INSTR(pt, ':') + 1)) AS max_key                                        
                   The result is '5' for '1:5'.
    Line 27:     .1 AS my_increment     
                   The INCREMENT I would like to use.
    Rules-
    Line 30:     UPSERT
                   This makes it possible for new rows to be created.
                   However seems like it is not necessary.
    Line 32:     m_1[FOR KEY FROM min_key[0] TO max_key[0] INCREMENT 1] = 'Y'
                   Where the KE value is between min_key[0] and max_key[0] set the value of m_1 to 'Y'
    */

    Of course, you can accomplish the same thing without MODEL using an Integer Series Generator like this.
    create table t ( min_val number, max_val number, increment_size number );
    insert into t values ( 2, 3, 0.1 );
    insert into t values ( 1.02, 1.08, 0.02 );
    commit;
    create table integer_table as
      select rownum - 1 as n from all_objects where rownum <= 100 ;
    select
      min_val ,
      increment_size ,
      min_val + (increment_size * n) as val
    from t, integer_table
    where
      n between 0 and ((max_val - min_val)/increment_size)
    order by 3
       MIN_VAL INCREMENT_SIZE        VAL
          1.02            .02       1.02
          1.02            .02       1.04
          1.02            .02       1.06
          1.02            .02       1.08
             2             .1          2
             2             .1        2.1
             2             .1        2.2
             2             .1        2.3
             2             .1        2.4
             2             .1        2.5
             2             .1        2.6
             2             .1        2.7
             2             .1        2.8
             2             .1        2.9
             2             .1          3
    15 rows selected.--
    Joe Fuda
    http://www.sqlsnippets.com/

Maybe you are looking for