Results 1 to 1 of 1

Thread: select statement with in clause

Threaded View

  1. #1
    Join Date
    Aug 2004
    Location
    Vosselaar, Belgium
    Posts
    4

    Default select statement with in clause

    (In reply to this topic, as I think it belongs in the Data Access forum rather than the Core Container one.)

    Henry,

    Since you're using Oracle, you could create a collection type:

    Code:
    CREATE TYPE ct_number AS TABLE OF NUMBER;
    Then you can use a sql string like this:

    Code:
    SELECT ename
      FROM emp
     WHERE empno IN (SELECT column_value
                       FROM TABLE (CAST (? AS ct_number)))
    Declare an array parameter for the query:

    Code:
    declareParameter(new SqlParameter(Types.ARRAY, "SCOTT.CT_NUMBER"));
    And use an Oracle-specific SqlTypeValue implementation:

    Code:
    final int[] value = new int[]{120,121};
    query.execute(new Object[]{new AbstractSqlTypeValue(){
        protected Object createTypeValue(Connection con, int sqlType, String typeName) throws SQLException {
            return new ARRAY(ArrayDescriptor.createDescriptor(typeName, con), con, value);
        }
    }});
    You'll probably need to configure a NativeJdbcExtractor on the JdbcTemplate used by the SqlQuery object.

    Note that I haven't tried this code, but I've done something similar before. I suppose it's also possible to use more complex object types, like you'd need for the query in your first example.

    Kind regards,
    Tom.
    Last edited by Rod Johnson; Jan 18th, 2006 at 10:40 AM.

Similar Threads

  1. Replies: 37
    Last Post: Aug 10th, 2009, 03:35 PM
  2. hibernate pagination
    By oliverchua in forum Data
    Replies: 8
    Last Post: Sep 23rd, 2005, 06:06 PM
  3. Transaction Management
    By caverns in forum Data
    Replies: 3
    Last Post: Mar 8th, 2005, 06:38 AM
  4. Replies: 1
    Last Post: Jan 27th, 2005, 06:00 PM
  5. like clause in select statement
    By manju in forum Data
    Replies: 4
    Last Post: Oct 5th, 2004, 07:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •