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

Similar Messages

  • 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());

  • How to use sql "IN" operator with named bind variable in where clause ?

    Can one bind variable be used for the "IN" list ('1','2','3') ?

    rob,
    No worries. Glad it helped. Glad to see also that you're doing things right and trying to use bind variables ;)
    May I suggest adding "SOLVED" to the title of the original post?
    Best,
    John

  • SQL Express 2014 with Advanced Tools

    I realized I should have included the version of Express I am trying to download.

    SQL Server 2012
    https://www.microsoft.com/en-us/download/details.aspx?id=29062
    Filenames for express with tools (x64 is for 64bit systems, x86 is for 32bit systems)
      ENU\x86\SQLEXPRWT_x86_ENU.exe
      ENU\x64\SQLEXPRWT_x64_ENU.exe
    Management Studio on it's own
      ENU\x64\SQLManagementStudio_x64_ENU.exe
      ENU\x86\SQLManagementStudio_x86_ENU.exe
    SQL Server 2014
    https://www.microsoft.com/en-us/download/details.aspx?id=42299
    Express with tools:
      ExpressAndTools 32BIT\SQLEXPRWT_x86_ENU.exe
      ExpressAndTools 64BIT\SQLEXPRWT_x64_ENU.exe
    Management Studio
    MgmtStudio 32BIT\SQLManagementStudio_x86_ENU.exe
    MgmtStudio 64BIT\SQLManagementStudio_x64_ENU.exe

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How can I set a variable number of values in a SQL IN clause?

    Hi,
    How can I set a variable number of values in a SQL IN clause without having to change the text of the SQL statement each time?
    I read the link http://radio.weblogs.com/0118231/2003/06/18.html. as steve wrote.
    SELECT *
    FROM EMP
    WHERE ENAME IN (?)
    But we need the steps not to create type in the system and would there be any other solution if we would like to use variable number of values in a SQL IN clause ?
    We are using JDeveloper 10.1.3.2 with Oracle Database 10.1.3.2
    Thanks
    Raj

    Hi,
    can you please explain why the solution from steve is not the right solution for you.
    regards
    Peter

  • [Solved] Named Bind Variables at Runtime - SQL WHERE clause issue

    Hey 'all,
    I've been having this issue today with a Search page using Named Bind Variables at Runtime for the search parameters for the WHERE clause in the view objects SQL.
    I've got everything working except for a clearing method which I've created so that the user can clear the current WHERE clause from the SQL statment and set it as 1=2 (so that it doesn't do a blind query on load).
    The method can clear and set the WHERE clause to 1=2 only when there is already one there.
    Below are the methods: (located in my view object class)
    public void findInvoiceById(Number invoiceId){
        setWhereClause("invoice_id = :P_INVOICE_ID");
        defineNamedWhereClauseParam("P_INVOICE_ID",null,null);
        setNamedWhereClauseParam("P_INVOICE_ID",invoiceId);
        executeQuery();
    public void clearCriteria(){
        setWhereClause("1=2");
        removeNamedWhereClauseParam("P_INVOICE_ID");
        executeQuery();
    }The error which I get is the following - this happens when the button is pressed twice in a row, or when no query has been passed previously.
    1. JBO-29000: Unexpected exception caught: oracle.jbo.NoDefException, msg=JBO-25058: Definition P_INVOICE_ID of type Variable not found in SupplierInvoicesView1
    2. JBO-25058: Definition P_INVOICE_ID of type Variable not found in SupplierInvoicesView1
    Any help with this would be greatly appreciated!
    Cheers,

    Hi Bonnie,
    we have it working ok, but still feel that there is room for improvement in the design.
    For us the key factors are:
    Pages based on the same view object that can be queried multiple ways.
    We don't want to put design time bind variables in because it limits the use of the VO
    We don't wan't multiple VO's with different where clauses.
    The page is displaying the same table columns and fields, but the where clause must be dynamic.
    We only want to query on the search field entered (some of our tables are massive)
    TopLink named queries are really what we are after, but we don't want to forgo all the other ADF BC functionality. The only examples of ViewCriteria in the developer guide had literals in the where clause and no bind variables. The View Criteria may still be an option, but it appeared quite complex compaired to directly adding and removing bind variables at runtime.
    a couple of footnotes:
    the following methods are used to clear the runtime variables prior to reusing the VO (thanks to John Stegman for the pointer on the exception handler):
        public void clearBindVariable(String bindVariableName){
            try
                removeNamedWhereClauseParam(bindVariableName);
            catch (NoDefException e)
        public void clearBindVariables(){
            clearBindVariable("P_INVOICE_ID");
            clearBindVariable("P_INVOICE_NUM");
            clearBindVariable("P_SUPPLIER_NAME");
            clearBindVariable("P_INVOICE_DATE_FROM");
            clearBindVariable("P_INVOICE_DATE_TO");
            clearBindVariable("P_SUPPLIER_NUMBER");
        }We are using 1=1 and 1=2 in the where clause to supress blind querying. 1=2 is applied when ever we are not explicitely searching for something. We had a problem with using the refresh condition ${adfFacesContext.postback == true} which I posted about here:
    executeQuery called twice using ${adfFacesContext.postback == true}
    Would still gladly hear other ideas on a better reuse design.
    regards,
    Brenden

  • 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/

  • How to Use SQL Query having IN Clause With DB Adapter

    Hi,
    I am using 11.1.1.5 want to find out how to Use SQL Query having IN Clause With DB Adapter. I want to pass the IN values dynamically. Any ideas.
    Thanks

    invoke a stored procedure, it's safer than trying to put together an arbitrary SQL statement in the JCA adapter

  • Construct a Sql block using With Clause to improve the performance

    I have got four diff parametrized cursor in my Pl/Sql Procedure. As the performance of the Procedure is very pathetic,so i have been asked to tune the Select statements used in those cursors.
    So I am trying to use the With Clause in order to club all those four Select Statements.
    I would appreciate if anybody can help me to construct the Sql Block using With Clause.
    My DB version is..
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    Four Diff cursors are defined below.
    CURSOR all_iss (
          b_batch_end_date   IN   TIMESTAMP,
       IS
          SELECT isb.*
                FROM IMPLMN_STEP_BREKPN  isb
               , ISSUE iss
          WHERE isb.issue_id = iss.issue_id
           AND iss.issue_status_id  =  50738
           AND ewo_no IN
          (SELECT TO_CHAR(wo_no)
            FROM MGO_PLANT_AUDIT
           WHERE dml_status = 'U' OR dml_status = 'I')
          UNION ALL
          SELECT isb.*
           FROM IMPLMN_STEP_BREKPN  isb
            , ISSUE iss
           WHERE isb.issue_id = iss.issue_id
           AND iss.issue_status_id  =  50738
           AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
                                                                  b_batch_end_date;
          CURSOR ewo_plant  ( p_ewo_no IN  IMPLMN_STEP_BREKPN.ewo_no%TYPE)
          IS
          SELECT DISTINCT wo_no ,
          plant_code
          FROM MGO_PLANT
          WHERE TO_CHAR(wo_no) = p_ewo_no;
          CURSOR iss_ewo_plnt (
          p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
          p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
          p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
          IS
          SELECT *
          FROM IMPLMN_STEP_BREKPN
          WHERE issue_id = p_issue_id
          AND ewo_no = p_ewo_no
          AND
          (plt_faclty_id = p_plnt_code
          OR
          plt_faclty_id IS NULL);
          CURSOR iss_ewo_plnt_count (
          p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
          p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
          p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
          IS
          SELECT COUNT(*)
          FROM IMPLMN_STEP_BREKPN
          WHERE issue_id = p_issue_id
          AND ewo_no = p_ewo_no
          AND
          (plt_faclty_id = p_plnt_code
          OR
          plt_faclty_id IS NULL);

    Not tested. Some thing like below. i just made the queries as tables and given name as a,b,c and substituted columns for the parameters used in the 2nd cursor and third cursor. Try like this.
    CURSOR all_iss (
    b_batch_end_date IN TIMESTAMP,
    IS
    select a.*,b.*,c.* from
    ( SELECT isb.*
    FROM IMPLMN_STEP_BREKPN isb
    , ISSUE iss
    WHERE isb.issue_id = iss.issue_id
    AND iss.issue_status_id = 50738
    AND ewo_no IN
    (SELECT TO_CHAR(wo_no)
    FROM MGO_PLANT_AUDIT
    WHERE dml_status = 'U' OR dml_status = 'I')
    UNION ALL
    SELECT isb.*
    FROM IMPLMN_STEP_BREKPN isb
    , ISSUE iss
    WHERE isb.issue_id = iss.issue_id
    AND iss.issue_status_id = 50738
    AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
    b_batch_end_date) a,
    ( SELECT DISTINCT wo_no ,
    plant_code
    FROM MGO_PLANT
    WHERE TO_CHAR(wo_no) = p_ewo_no) b,
    ( SELECT *
    FROM IMPLMN_STEP_BREKPN
    WHERE issue_id = p_issue_id
    AND ewo_no = p_ewo_no
    plt_faclty_id IS NULL) c
    where b.wo_no = c.ewo_no and
    c.issue_id = a.issue_id ;
    vinodh
    Edited by: Vinodh2 on Jul 11, 2010 12:03 PM

  • SQL query in SQL_REDO Logminor showing where clause with ROWID

    SQL query in SQL_REDO Logminor showing where clause with ROWID. I dont wanted to use rowid but wanted to use actual value.
    OPERATION SQL_REDO SQL_UNDO
    DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
    where "ORDER_ID" = '2413' ("ORDER_ID","ORDER_MODE",
    and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
    and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
    and "ORDER_STATUS" = '5' "PROMOTION_ID")
    and "ORDER_TOTAL" = '48552' values ('2413','direct','101',
    and "SALES_REP_ID" = '161' '5','48552','161',NULL);
    and "PROMOTION_ID" IS NULL
    and ROWID = 'AAAHTCAABAAAZAPAAN';
    DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
    where "ORDER_ID" = '2430' ("ORDER_ID","ORDER_MODE",
    and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
    and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
    and "ORDER_STATUS" = '8' "PROMOTION_ID")
    and "ORDER_TOTAL" = '29669.9' values('2430','direct','101',
    and "SALES_REP_ID" = '159' '8','29669.9','159',NULL);
    and "PROMOTION_ID" IS NULL
    and ROWID = 'AAAHTCAABAAAZAPAAe';
    Please let me know solution/document which will convert SQL redo rowid value with actual value.
    Thanks,

    Please enclose your output within tag so that people here can read it easily and help you. Also the reason that why you want to remove rowid?
    Salman
    Edited by: Salman Qureshi on Mar 20, 2013 3:53 PM                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Trying to use parameter variable as column identifier in SQL where clause

    Hey guys,
    Doing a college project... would really appreciate some help. I am trying to use a variable in the where clause of a select cursor in PL/SQL. The code is this:
    procedure results(p_search_entry varchar2, p_search_field varchar2) is
    cursor c_results is
    select * from physics_b where p_search_field = p_search_entry;
    begin
    for cv_results in c_results
    loop
    -- loop through actions
    end loop;
    The problem is that I don't know how to get the where clause to accept the variable passed into the procedure as the field name. Does anyone know the syntax for this?
    Thanks very much!

    To suit your requirement use ref cursor..
    If your database is 9i and upwards you can use sys_refcursor as I have used or else you can declare the cursor shown in the statement below
    type c_result is ref cursor;
    c_results c_result;
    Jus replace these two statement in the example if your oracle database is prior to 9i
    Eg:
    procedure results(p_search_entry varchar2, p_search_field varchar2) is
    qry_stmt VARCHAR2(1000) ;
    c_results sys_refcursor;
    begin
    qry_stmt := 'select * from physics_b where '||p_search_field|| '='|| p_search_entry
    open c_results for qry_stmt
    loop
    <fetch as like normal cursor>
    <ur normal cursor operation etc....>
    end loop;
    end results;
    Sorry I posted twice
    Message was edited by:
    Shasi

  • Can't use ";" in sql clause with Oracle 8.X

    Can't use ";" in sql clause with Oracle 8.X
    I can't use ";" at the ending of sql clause in VB program. First this program can use with Oracle 7.3.4 database. But now i need to upgrade DB to Oracle 8.1.7 ,program can't operate. It show error Runtime 40002
    and 37000:ODBC driver for oracle/invalid charactor
    Thankyou

    I've seen a lot of discussion about semicolons in SQL
    sent from 3rd party applications. A web search should
    bring up the discussions.
    Also you might get more response if you ask this question
    somewhere else. This is not a VB forum, so you may
    not reach relevant people.
    -- CJ

  • How to use in clause with variable elements with a prepared statement?

    Is there any way to use a prepared statement for a query which incorporates an in clause with unknown number of elements in the list?
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Iraj ():
    Is there any way to use a prepared statement for a query which incorporates an in clause with unknown number of elements in the list?<HR></BLOCKQUOTE>
    Sorry, can't be done. The PreparedStatement is precomplied, so you can't have variable number of params or unknown number of elements in a list.

  • SQL executing error differences with different tools, need help!!

    Hi everyone,
    I'm getting trouble with executing SQL query using SQLdevelopper.
    but it returns the error about bind value parameter in & out doesn't set.
    I also try to same SQL with other tools but only one tool could succeed
    executing which is Osqledit.
    SQL*Developper--------No
    Object Browser--------No
    Sql*Plus-------No
    Osqledit-----Yes
    does anybody know why some sql tools couldn't succeed executing
    same sql such as Osqledit?
    and also in this case often to cause or not?
    thank you for reading and helping me.

    thanks SHUBH I think so too.
    To Colin and others,
    here is my SQL query which wasn't written in English so
    it took me for a while to translate.
    and it very long SQL which my co-worker made it.
    sorry for it unable to read easily tho I need your help.
    in additon, we use bind-values on this SQL.
    select
         shopcode,
         JAN,
         h.lowestestprice,
         h.highestprice,
         h.amount,
         h.totalsales,
         h.retailprice,
         h.aprice,
         h.normalamount,
         h.normaltotalsales,
         h.normalretailprice,
         h.normalaprice,
         h.discountamount,
         h.discounttotalsales,
         h.discountretailprice,
         h.discountaprice,
         h.memberamount,
         h.memberretailprice,
         h.memberretailprice,
         h.memberaprice,
         h.normalreserveamount,
         h.discountreserveamount
    from
              select
              shopcode,
                   JANcode JAN,
                   min(lowestestprice) lowestestprice,
                   max(highestprice) highestprice,
                   sum(amount) amount,
                   sum(totalsales) totalsales,
                   sum(retailprice) retailprice,
                   sum(aprice) aprice,
                   sum(normalamount) normalamount,
                   sum(normaltotalsales) normaltotalsales,
                   sum(normalretailprice) normalretailprice,
                   sum(normalaprice) normalaprice,
                   sum(discountamount) discountamount,
                   sum(discounttotalsales) discounttotalsales,
                   sum(discountretailprice) discountretailprice,
                   sum(discountaprice) discountaprice,
                   sum(memberamount) memberamount,
                   sum(membertotalsales) membertotalsales,
                   sum(memberretailprice) memberretailprice,
                   sum(memberaprice) memberaprice,
                   sum(normalreserveamount)
    normalreserveamount,
                   sum(discountreserveamount)
    discountreserveamount
              from
                   testsalesfact
              where
                   salesdate between :begindate and :enddate
              group by
                   shopcode,
                   JANcode
         ) h
         full outer join
              select
                   shopcode,
                   JANcode,
    min(lowestestprice) lowestestprice,
                   max(highestprice) highestprice,
                   sum(amount) amount,
                   sum(totalsales) totalsales,
                   sum(retailprice) retailprice,
                   sum(aprice) aprice,
                   sum(normalamount) normalamount,
                   sum(normaltotalsales) normaltotalsales,
                   sum(normalretailprice) normalretailprice,
                   sum(normalaprice) normalaprice,
                   sum(discountamount) discountamount,
                   sum(discounttotalsales) discounttotalsales,
                   sum(discountretailprice) discountretailprice,
                   sum(discountaprice) discountaprice,
                   sum(memberamount) memberamount,
                   sum(membertotalsales) membertotalsales,
                   sum(memberretailprice) memberretailprice,
                   sum(memberaprice) memberaprice,
                   sum(normalreserveamount)
    normalreserveamount,
                   sum(discountreserveamount)
    discountreserveamount
              from
                   shopweeksaleswk
              where
                   salesdate between :begindate and :enddate
              group by shopcode, JAN
              union all
              select
                   a.shopcode,
                   a.JAN,
                   min(a.pricewiotax) lowestestprice,
              -     max(a.pricewiotax) highestprice,
                   sum(a.amount) amount,
                   sum(a.totalsales) totalsales,
                   sum(a.retailprice) retailprice,
                   sum(a.aprice) aprice,
                   sum(a.normalamount) normalamount,
                   sum(a.normaltotalsales) normaltotalsales,
                   sum(a.normalretailprice) normalretailprice,
                   sum(a.normalaprice) normalaprice,
                   sum(a.discountamount) discountamount,
                   sum(a.discounttotalsales) discounttotalsales,
                   sum(a.discountretailprice) discountretailprice,
                   sum(a.discountaprice) discountaprice,
                   sum(a.memberamount) memberamount,
                   sum(a.membertotalsales) membertotalsales,
                   sum(a.memberretailprice) memberretailprice,
                   sum(a.memberaprice) memberaprice,
                   sum(a.normalreserveamount)
    normalreserveamount,
                   sum(a.discountreserveamount)
    discountreserveamount
              from (
                   select
                        p.shopcode,
                        substr(p.makedate, 1, 8) salesdate,
                        p.JAN,
                        p.pricewiotax,
                        p.amount amount,
                        trunc(p.amount * p.pricewiotax)
    totalsales,
                        trunc(p.amount * decode
    (p.discountcode, '000000',
                        p.retailprice, p.discountretailprice))
    retailprice,
                        decode(decode
    (p.discountcode, '000000',
    p.retailprice,
                        p.discountretailprice), 0, 0,
                        trunc(p.amount * p.pricewiotax) -
                        trunc(p.amount * decode
    (p.discountcode, '000000',
                        p.retailprice, p.discountretailprice)))
    aprice,               
                        decode(p.discountcode, '000000',
    p.amount, 0) normalamount,
                        decode(p.discountcode, '000000',
                        trunc(p.amount * p.pricewiotax), 0)
    normaltotalsales,
                        decode(p.discountcode, '000000',
                        trunc(p.amount * p.totalsales), 0)
    normalretailprice,
                        decode(p.totalsales, 0, 0, decode
    (p.discountcode, '000000',
                        trunc(p.amount * p.pricewiotax) -
                        trunc(p.amount * p.retailprice), 0))
    normalaprice,
                        decode(p.discountcode, '000000', 0,
    p.amount) discountamount,
                        decode(p.discountcode, '000000', 0,
                        trunc(p.amount * p.pricewiotax))
    discounttotalsales,
                        decode(p.discountcode, '000000', 0,
                        trunc(p.amount *
    p.discountretailprice))
    discountretailprice,
                        decode(p.discountretailprice, 0, 0,
                   decode(p.discountcode, '000000', 0,
                   trunc(p.amount * p.pricewiotax)
                        trunc(p.amount *
    p.discountretailprice))) discountaprice,
                        case when substr(p.cardnumber,
    1, 7) in
    ('4986428', '4986429', '4986554')
                        then p.amount else 0 end
    memberamount,
                        case when substr(p.cardnumber,
    1, 7) in
    ('4986428', '4986429', '4986554')
                        then trunc(p.amount * p.pricewiotax)
    else 0 end membertotalsales,
                        case when substr(p.cardnumber,
    1, 7) in
    ('4986428', '4986429', '4986554') then
                        trunc(p.amount * decode
    (p.discountcode, '000000',
    p.retailprice,
                        p.discountretailprice)) else 0 end
    memberretailprice,
                        case when substr(p.cardnumber,
    1, 7) in
    ('4986428', '4986429', '4986554') then
                        decode(decode
    (p.discountcode, '000000',
    p.retailprice, p.discountretailprice),
    0, 0,
                        trunc(p.amount * p.pricewiotax) -
                        trunc(p.amount * decode
    (p.discountcode,'000000',
                        p.retailprice, p.discountretailprice)))
    else 0 end memberaprice,
                        decode(p.discountcode, '000000',
                   decode(p.discountsec, '07',
    p.amount, 0), 0)
    normalreserveamount,
                        decode(p.discountcode, '000000', 0,
                        decode(p.discountsec, '07',
    p.amount, 0)) discountreserveamount
                   from shopweeksaleswk p
                   where p.salesdate between :begindate
    and :enddate
                   and p.makedate not between
                   :begindate|| '000000 '
    and :enddate|| '000000 '
                   ) a
              group by a.shopcode, a.JAN
              union all     
              select
                   a.shopcode,
                   a.JAN,
                   min(a.pricewiotax) lowestestprice,
                   max(a.pricewiotax) highestprice,
                   sum(a.amount) amount,
                   sum(a.totalsales) totalsales,
                   sum(a.retailprice) retailprice,
                   sum(a.aprice) aprice,
                   sum(a.normalamount) normalamount,
                   sum(a.normaltotalsales) normaltotalsales,
                   sum(a.normalretailprice) normalretailprice,
                   sum(a.normalaprice) normalaprice,
                   sum(a.discountamount) discountamount,
                   sum(a.discounttotalsales) discounttotalsales,
                   sum(a.discountretailprice) discountretailprice,
                   sum(a.discountaprice) discountaprice,
                   sum(a.memberamount) memberamount,
                   sum(a.membertotalsales) membertotalsales,
                   sum(a.memberretailprice) memberretailprice,
                   sum(a.memberaprice) memberaprice,
                   sum(a.normalreserveamount)
    normalreserveamount,
                   sum(a.discountreserveamount)
    discountreserveamount
              from (
                   select
                        p.shopcode,
                        substr(p.makedate, 1, 8) salesdate,
                        p.JAN,
                        p.pricewiotax,
                        p.amount *- 1 amount,
                        trunc(p.amount * p.pricewiotax) *- 1
    totalsales,
                        trunc(p.amount * decode
    (p.discountcode, '000000',
                        p.retailprice, p.discountretailprice)) *-
    1 retailprice,
                        decode(decode
    (p.discountcode, '000000',
                        p.retailprice, p.discountretailprice),
    0, 0,
                        trunc(p.amount * p.pricewiotax) -
                        trunc(p.amount * decode
    (p.discountcode, '000000',
                        p.retailprice, p.discountretailprice))) *-
    1 aprice,
                        decode(p.discountcode, '000000',
    p.amount, 0) *- 1 normalamount,
                        decode(p.discountcode, '000000',
    trunc(p.amount * p.pricewiotax), 0) *
                        - 1 normaltotalsales,
                        decode(p.discountcode, '000000',
    trunc(p.amount * p.retailprice), 0) *
                        - 1 normalretailprice,
                        decode(p.retailprice, 0, 0, decode
    (p.discountcode, '000000',
                        trunc(p.amount * p.pricewiotax) -
                        trunc(p.amount * p.retailprice), 0)) *- 1
    normalaprice,
                        decode(p.discountcode, '000000', 0,
    p.amount) *- 1 discountamount,
                        decode(p.discountcode, '000000', 0,
    trunc(p.amount * p.pricewiotax)) *
                        - 1 discounttotalsales,
                        decode(p.discountcode, '000000', 0,
                        trunc(p.amount *
    p.discountretailprice)) *- 1
    discountretailprice,
                        decode(p.discountretailprice, 0, 0,
    decode(p.discountcode, '000000', 0,
                        trunc(p.amount * p.pricewiotax) -
                        trunc(p.amount *
    p.discountretailprice))) *- 1
    discountaprice,
                        case when substr(p.cardnumber,
    1, 7) in
    ('4986428', '4986429', '4986554')
                        then p.amount *- 1 else 0 end
    memberamount,
                        case when substr(p.cardnumber,
    1, 7) in
    ('4986428', '4986429', '4986554')
                        then trunc(p.amount * p.pricewiotax) *-                                                                1 else 0 end membertotalsales,
                        case when substr(p.cardnumber,
    1, 7) in
    ('4986428', '4986429', '4986554')
                        then trunc(p.amount * decode
    (p.discountcode, '000000',
                        p.retailprice, p.discountretailprice)) *-
    1 else 0 end memberretailprice,
                        case when substr(p.cardnumber,
    1, 7) in
    ('4986428', '4986429', '4986554')
                        then decode(decode
    (p.discountcode, '000000',
    p.retailprice,
    p.discountretailprice), 0, 0,
                        trunc(p.amount * p.pricewiotax) -
    trunc(p.amount *
                        decode(p.discountcode,'000000',
    p.retailprice, p.discountretailprice))) *
                        - 1 else 0 end memberamount,
                        decode(p.discountcode, '000000',
    decode(p.discountsec, '07',
    p.amount, 0), 0)*
                        -1 normalreserveamount,
                        decode(p.discountcode, '000000', 0,
    decode(p.discountsec, '07',
    p.amount, 0))*
                        -1 discountreserveamount
                   from shopweeksaleswk p
                   where p.salesdate not between :begindate
    and :enddate
                   and p.makedate
    between :begindate|| '000000 '
    and :enddate|| '000000 '
                   ) a
              group by a.shopcode, a.JAN
         ) m
         using (shopcode,JAN)
    where
         and h.lowestestprice != m.lowestestprice
         or h.highestprice != m.highestprice
         (h.amount != m.amount
         or h.totalsales != m.totalsales
         or h.aprice != m.aprice
         or h.normalamount != m.normalamount
         or h.normaltotalsales != m.normaltotalsales
         or h.normalretailprice != m.normalretailprice
         or h.normalaprice != m.normalaprice
         or h.discountamount != m.discountamount
         or h.discounttotalsales != m.discounttotalsales
         or h.discountretailprice != m.discountretailprice
         or h.discountaprice != m.discountaprice
         or h.memberamount != m.memberamount
         or h.membertotalsales != m.membertotalsales
         or h.memberretailprice != m.memberretailprice
         or h.memberaprice != m.memberaprice
         or h.normalreserveamount != m.normalreserveamount
         or h.discountreserveamount != m.discountreserveamount)
    order by shopcode, JAN ;

Maybe you are looking for