Using bind varaible for order by clause

Hello
Can some one suggest for the following scenario?
My order by clause will be constructed based on the selected fields in the form. And now the order by clause need to be passed as parameter to Excel report.
When I use Ref cursor and OPEN-FOR-USING clause, data is not sorted.
do we have any other alternate for this?
Please observe the example code for the same. Block below resembles the code for to select the data for excel report.
SQL> select * from t;
T
sdf
der
gdr
ghft
ytut
lkrt
rtrt
tyrt
SQL> declare
2 l_order_by VARCHAR2 (100);
3 l_test varchar2(10);
4 TYPE TEST IS REF CURSOR;
5 c_TEST test;
6 L_string VARCHAR2(2000):= 'select * from t order by :pi_order';
7 begin
8 l_order_by := ' t DEsc';
9 open c_test for l_string using l_order_By;
10 loop
11 fetch c_test into l_test;
12 exit when c_TEST%notfound;
13 dbms_output.put_line (l_test);
14 end loop;
15 close c_test;
16 end;
17 /
sdf
der
gdr
ghft
ytut
lkrt
rtrt
tyrt
PL/SQL procedure successfully completed.
Cheers
Ram Kanala

My order by clause will be constructed based on the selected fields in the formDoes this look like you need ?
SQL> var so number
SQL> exec :so := 1;
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> declare
  2   rc sys_refcursor;
  3   type emprec is table of emp%rowtype index by pls_integer;
  4   erec emprec;
  5  begin
  6 
  7   open rc for 'select * from emp order by ' ||
  8   'decode(:p,1,ename,2,deptno,3,sal,null),' ||
  9   'decode(:p,4,ename,5,deptno,6,sal,null) desc' using :so,:so;
10   fetch rc bulk collect into erec;
11   close rc;
12 
13   for i in 1..erec.count loop
14    dbms_output.put_line('Ename = ' || erec(i).ename || ', deptno = ' || erec(i).deptno || ', sal
= ' || erec(i).sal);
15   end loop;
16  end;
17  /
Ename = ADAMS, deptno = 20, sal = 1100
Ename = ALLEN, deptno = 30, sal = 1600
Ename = BLAKE, deptno = 30, sal = 2850
Ename = CLARK, deptno = 10, sal = 2450
Ename = FORD, deptno = 20, sal = 3000
Ename = JAMES, deptno = 30, sal = 950
Ename = JONES, deptno = 20, sal = 2975
Ename = KING, deptno = 10, sal = 5000
Ename = MARTIN, deptno = 30, sal = 1250
Ename = MILLER, deptno = 10, sal = 1300
Ename = SCOTT, deptno = 20, sal = 3000
Ename = SMITH, deptno = 20, sal = 800
Ename = TURNER, deptno = 30, sal = 1500
Ename = WARD, deptno = 30, sal = 1250
PL/SQL procedure successfully completed.
SQL> exec :so := 2
PL/SQL procedure successfully completed.
SQL> /
Ename = CLARK, deptno = 10, sal = 2450
Ename = KING, deptno = 10, sal = 5000
Ename = MILLER, deptno = 10, sal = 1300
Ename = JONES, deptno = 20, sal = 2975
Ename = FORD, deptno = 20, sal = 3000
Ename = ADAMS, deptno = 20, sal = 1100
Ename = SMITH, deptno = 20, sal = 800
Ename = SCOTT, deptno = 20, sal = 3000
Ename = WARD, deptno = 30, sal = 1250
Ename = TURNER, deptno = 30, sal = 1500
Ename = ALLEN, deptno = 30, sal = 1600
Ename = JAMES, deptno = 30, sal = 950
Ename = BLAKE, deptno = 30, sal = 2850
Ename = MARTIN, deptno = 30, sal = 1250
PL/SQL procedure successfully completed.
SQL> exec :so := 5;
PL/SQL procedure successfully completed.
SQL> /
Ename = BLAKE, deptno = 30, sal = 2850
Ename = TURNER, deptno = 30, sal = 1500
Ename = ALLEN, deptno = 30, sal = 1600
Ename = MARTIN, deptno = 30, sal = 1250
Ename = WARD, deptno = 30, sal = 1250
Ename = JAMES, deptno = 30, sal = 950
Ename = SCOTT, deptno = 20, sal = 3000
Ename = JONES, deptno = 20, sal = 2975
Ename = SMITH, deptno = 20, sal = 800
Ename = ADAMS, deptno = 20, sal = 1100
Ename = FORD, deptno = 20, sal = 3000
Ename = KING, deptno = 10, sal = 5000
Ename = MILLER, deptno = 10, sal = 1300
Ename = CLARK, deptno = 10, sal = 2450
PL/SQL procedure successfully completed.Rgds.

Similar Messages

  • Sorting technique used by oracle for "order by" clause.

    Hi All,
    it could be very help to me if you provide some information about sorting technique used by oracle engine for order by clause.
    Issue i am facing :
    Table : xx
    Line Date
    1 05-06-2013 00:00:00
    2 05-06-2013 00:00:00
    when we query above table using order by date, it is returning line 2 prior to line 1. we would like to know why it is returning line 2 first?
    Regards,
    Ram

    >
    it could be very help to me if you provide some information about sorting technique used by oracle engine for order by clause.
    >
    Well ok - but be warned that many people wind up being sorry they ask that question. Hopefully Hemant's answer is what you really wanted.
    See 'Linguistic Sorting and String Searching' in the Oracle® Database Globalization Support Guide
    http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch5lingsort.htm
    Sorting will be controlled by the settings of NLS_LANGUAGE, NLS_SORT and NLS_COMP.
    Here is the doc page for NLS_SORT
    http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch3globenv.htm#i1008393
    >
    NLS_SORT specifies the type of sort for character data. It overrides the default value that is derived from NLS_LANGUAGE.
    NLS_SORT contains either of the following values:
    NLS_SORT = BINARY | sort_name
    BINARY specifies a binary sort. sort_name specifies a linguistic sort sequence.
    >
    And the one for NLS_COMP
    http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch3globenv.htm#i1008458
    >
    The value of NLS_COMP affects the comparison behavior of SQL operations.
    You can use NLS_COMP to avoid the cumbersome process of using the NLSSORT function in SQL statements when you want to perform a linguistic comparison instead of a binary comparison. When NLS_COMP is set to LINGUISTIC, SQL operations perform a linguistic comparison based on the value of NLS_SORT. A setting of ANSI is for backward compatibility; in general, you should set NLS_COMP to LINGUISTIC when you want to perform a linguistic comparison.

  • Exception caused by bind variables in ORDER BY clause and VO RANGE_PAGING

    Hi,
    I'm using a ViewObject in RANGE_PAGING mode and discovered a problem when using bind variables in the ORDER BY clause of my statement:
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3 When a bind variable is used in the ORDER BY CLAUSE and the method VO.getEstimatedRowCount() is call then the DB issued an SQL error:
    java.sql.SQLException: Ungültiger Spaltenindex (eng.: invalid column index)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:137)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:174)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:239)
         at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:4612)The numbering of the bind variables indicates that the last two bind variables have the wrong numbering (??)
    When I rewrite the SQL into the following statement, the SQL error does not occur but I have not verified yet that the VO delivers the correct range of data because the numbering of the bind variables is not correct.
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT *, decode (attr2, :1, 1, null, 0, -1) as ATTR_FOR_SORTING FROM T_TABLE WHERE (attr1 = :2) ORDER BY ATTR_FOR_SORTING  desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3I'm working with JDev 10.1.2 and Oracle DB 9203.
    Any comments are welcome!
    Thanks,
    Markus

    You are using the bind variable :2 twice. Did you try
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :4) WHERE Z_R_N > :3
    setWhereClauseParm(0, "a"); // :1
    setWhereClauseParm(1, "b"); // :2
    setWhereClauseParm(2, "c"); // :3
    setWhereClauseParm(3, "b"); // :2setting the fourth parameter the same as the second one?
    I remeber reading something about using bind variables twice causing problems, but I#m not sure about it.

  • Can I use an expression in order by clause

    SELECT
    PERIOD_NUM, period_num *12,
    period_name,
    --TO_DATE(SUBSTR(PERIOD_NAME,1,3)&#0124; &#0124;SUBSTR(PERIOD_NAME,INSTR(PERIOD_NAME,'-'),3),'MON-RR'),
    TO_NUMBER(TO_CHAR(TO_DATE((SUBSTR(PERIOD_NAME,1,3)&#0124; &#0124;SUBSTR(PERIOD_NAME,INSTR(PERIOD_NAME,'-')+1,2)),'MONRR'),'RRRRMM'))
    FROM GL.GL_PERIODS
    order by 2--TO_NUMBER(TO_CHAR(TO_DATE(SUBSTR(PERIOD_NAME,1,3)&#0124; &#0124;SUBSTR(PERIOD_NAME,INSTR(PERIOD_NAME,'-')+1,2),'MONRR'),'RRRRMM'))
    desc
    gl_periods is a table, period_name consists of values like oct-01_fy-01 etc and oct01_01_fy-01
    I want to sort on this column based on period_name, so I am trying to convert into number like for oct-01_fy-01, the query gives
    200110 and so on. the recent period comes first, But my question is I can't use the same to_number(.....) in the order by clause. oracle gives an error
    ORA-01843: not a valid month.
    Let me know whether anyone come across with this kind of situation

    If you are sure the expression is correct, since you are using it in the select clause, give an alias and use the alias in the order by clause.
    null

  • Using ROWID in the ORDER BY clause

    Hi,
    I can consider myself as a PL/SQL beginner. I need to query some existing tables created for audit scope.
    These tables have more duplicate rows respect to the same audit date: the precision is at "hour and minute and second" level.
    But I need to understand which is the more recent row for the same audit date. So I think to use in the SELECT statement
    the clause ORDER BY in this manner:
    SELECT ... FROM Audit_Table ORDER BY Audit_Date desc, ROWID desc.
    I'd like to use this ORDER BY also for the ROW_NUMBER function.
    Any suggests to me about this topic? Many thanks

    I don't need to provide an example, I can do better by pointing you to the documentation:
    http://docs.oracle.com/database/121/SQLRF/pseudocolumns008.htm#SQLRF00254
    "If you delete a row, then Oracle may reassign its rowid to a new row inserted later" - for example
    I can point you to asktom: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:912210644860
    "ROWIDs are NOT sortable" - for example
    Your example just happened to work, but you are using the rowid semantically incorrect.

  • XSQL Using bind params with sql LIKE clause

    I am unable to use a bind-param with the LIKE clause in a SELECT statement.
    eg call .../temp.xsql?name=N
    XSQL query is this:
    <xsql:query max-rows="-1" bind-params="name">
    SELECT last_name
    FROM emp
    WHERE last_name LIKE '?%'
    </xsql:query>
    I have tried a few combinations so far with no success eg:
    WHERE last_name LIKE '{@name}%'
    WHERE last_name LIKE ?||%
    Any ideas?

    I highly recommend using XSQL's real bind variable feature wherever you can. You can read about it in the XSQL Online Documentation (Search for the "Using Bind Variables" section).
    Using this feature is more performant and more secure than using textual substitution variables.
    Here's what your page looks like using textual substitution:
    <page connection="UTD4" xmlns:xsql="urn:oracle-xsql">
      <xsql:query null-indicator="yes" >
        SELECT * FROM TC_HL7_SEG WHERE SEGMENT_CODE LIKE '{@code}%'
      </xsql:query>
    </page> .
    And here's what it would look like using real bind variables:
    <page connection="UTD4" xmlns:xsql="urn:oracle-xsql">
      <xsql:query null-indicator="yes" bind-params="code">
        SELECT * FROM TC_HL7_SEG WHERE SEGMENT_CODE LIKE ?||'%'
      </xsql:query>
    </page> .
    Using real bind variables allows the database to avoid reparsing the SQL statement everytime, which improves performance.
    Steve Muench
    JDeveloper/BC4J Development Team
    Author, Building Oracle XML Applications

  • Passing parameter in report for order by clause

    how can we pass the name of the column on which we want the order by clause to sort as a parameter through parameter from in a report??

    Hi Guptha,
    We can create a bind parameter in report and we can send it as a parameter or enter in the parameter form.
    The Query will be
    select * from emp
    order by :Order_Bu_Column
    I think it will help you.
    Regards,
    Siva.

  • Database Settings for order By Clause

    Hi,
    In oracle if we do a "order by" in SQL statement for field values whose values are empty, then they would be listed at the last if we dont specify any NVL() for it.
    Is there any other option by which the funcionality of Order by clause with Empty field values can be changed.
    Is there any settings that can be made in the existing database , so that the Order by clause does not list the empty field values at the bottom.
    Thanx in advance.
    Bharath

    you can do wonders with decode and nvl
    for instance:
    order by decode(nullable_field, null, 1, 2)would make all your null fields come first, whereas
    order by nvl(nullable_field, 'M')would make them appear in the middle of an alphabetical list.
    Basically NULLs are not something. You have to give the ORDER BY something to replace the null.
    null

  • How do I use bind variables for the SQL statements having IN clause

    SELECT id, name FROM t
    WHERE id in (10,20,30)
    As the IN list will have 'n' number of values, I am not able to specify fixed number of bind
    variables like
    SELECT id, name FROM t
    WHERE id in (?,?,?....)

    452051 wrote:
    I am not able to specify fixed number of bind variablesYou could use collection:
    SQL> create or replace force
      2    type NumList
      3      as
      4        table of number
      5  /
    SQL> select ename from emp where deptno member of NumList(10)
      2  /
    ENAME
    CLARK
    KING
    MILLER
    SQL> select ename from emp where deptno member of NumList(10,20,30)
      2  /
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    ENAME
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> This way you have one bind variable - collection.
    SY.

  • Using bind variable in dynamic where clause and concatenate with query

    Hi,
    In my procedure i am framing where clause dynamically with bind variable,When i am concatenate this with my sql query for REF CURSOR i got sql command not properly ended exception.
    Is it possible to pass values to the bind variable through the dynamic variable/value?
    Please advise
    Thanks in advance
    Siva
    IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
    My query is like this
    open Out_Main FOR SelectQuery USING optional_using

    Thanks for reply,
    In my procedure, i suppose to frame the where clause with bind dynamically according to the input parameters. so that i am framing the values of the bind variables also dynamically like this,
    Please advise...
    IF in_assignedAppFlag IS NOT NULL THEN
              IF in_assignedAppFlag = 'Y' THEN
                   optional_where := optional_where || ' AND b.ASSIGNED_TO = :b' ;
              optional_using := ' in_appFuncGroup'||',in_currentUserID';          
              ELSe
                   IF in_isSupervisor = 0 THEN
                        optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID';
                   END IF;
              END IF;
         ELSE
              IF in_isSupervisor = 0 THEN
                   optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
                   optional_using := ' in_appFuncGroup'||',in_currentUserID';
              END IF;
         END IF;
         IF in_appFuncGroup IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_FUNC_GROUP= :c';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup';
         END IF;
         IF in_queue_id IS NOT NULL THEN
              optional_where := optional_where || ' AND b.QUEUE_ID = :d';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id';
         END IF;
         IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
         IF in_sourceCode IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_SOURCE_CODE like '||':f%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode';
         END IF;
         IF in_logo IS NOT NULL THEN
              optional_where := optional_where || ' AND appProds.PRODUCT_TYPE like '||':g%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo';
         END IF;
         IF in_firstName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.FIRST_NAME) like upper(:h%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName';
         END IF;
         IF in_surName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.SURNAME) like upper(:i%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName';
         END IF;
         IF in_retreival_id IS NOT NULL THEN
              optional_where := optional_where || ' AND e.RETREIVAL_ID like :j%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName'||',in_retreival_id';
         END IF;

  • How to use XML Gateway for Order Import and Item Import?

    Hello XML gurus,
    I'm working in Oracle Apps area and do not have much knowledge on XML or web programming. Currently in my project there is a need to use Order Import and Item Import using interface tables and XML Gateway. The items/orders information will be in the XML format from Siebel system, there will be no custom processing...just process the data as-is.
    I've read the XML Gateway user guide but did not understand much.
    Anyone with similar implementation experience?
    I'm looking for a step-by-step guide on what needs to be done in Oracle Apps side to populate the interface tables from XML file and call the import APIs?
    Your inputs, suggestions, tips are highly appreciated. :)
    Thx,
    Jags

    I have a similar requirement to automate the order import and was looking at XML Gateway. Please update if you were able to find more information.
    - Ayyappa

  • Help for order by clause

    Hi ,
    i have a below table with data , when i run my select with order by option its gives me
    1     Card
    as a first row but i need this
    12     atm
    as a first row ,how this is possible .
    create table test
    (ID number ,
    val varchar2(20)
    insert into test values (1,'Card')
    insert into test values (2,'Card')
    insert into test values (3,'Card')
    insert into test values (4,'Cash')
    insert into test values (5,'Cash')
    insert into test values (6,'Cash')
    insert into test values (7,'Checque')
    insert into test values (8,'Checque')
    insert into test values (9,'Checque')
    insert into test values (10,'atm')
    insert into test values (11,'atm')
    insert into test values (12,'atm')
    select * from test
    order by val asc

    YOu can also use Nlssort like
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    SQL> select *
      2  from test
      3  order by nlssort(val, 'NLS_SORT = WEST_EUROPEAN_AI') asc, id desc
      4  /
            ID VAL
            12 atm
            11 atm
            10 atm
             3 Card
             2 Card
             1 Card
             6 Cash
             5 Cash
             4 Cash
             9 Checque
             8 Checque
            ID VAL
             7 Checque
    12 rows selected.

  • Using oracle function in order by clause

    Hello,
    can i use report query or report that generate query like this :
    select fname, lname from peoples order by dbms_random.value;
    dbms_random is an oracle function to generate random value.
    Thnaks

    add the following call to your query:
    query.addOrdering(query.getExpressionBuilder().getFunction("dbms_random.value"));
    --Gordon                                                                                                                                                                                                                                                                       

  • Using bind variable for ref cursors

    Hi
    I have a procedure that recieves a tablename in srcTable variable . A query is formed SELECT_Q with values from global varray.
    Table name will be dynamic and query is to be used with a ref cursor. Since table name is not known how to make the refcursor.
    tried the following.....not sure how to do it. pls help.
    PROCEDURE Process1(srcTable VARCHAR2, trgTable VARCHAR2) IS
         TYPE CURSORTYPE IS REF CURSOR RETURN :x%ROWTYPE;
         REC_CUR CURSORTYPE;
         REC_CUR_DATA :x%ROWTYPE;
         DBMS_SQL.BIND_VARIABLE(REC_CUR, ':x', SourceT);
         DBMS_SQL.BIND_VARIABLE(REC_CUR_DATA, ':x', SourceT);
         COUNTi NUMBER :=0;
         SELECT_Q VARCHAR2(1000) := 'SELECT ';
    BEGIN
    FOR COUNTi IN 1..COLUMN_NAME_ARR.COUNT-1 LOOP
              SELECT_Q := SELECT_Q || COLUMN_NAME_ARR(COUNTi) || ',';
    END LOOP;
         SELECT_Q := SELECT_Q || COLUMN_NAME_ARR(COLUMN_NAME_ARR.COUNT) || ' FROM '||SourceT;
         DBMS_OUTPUT.PUT_LINE(SELECT_Q);
    -- query to be used for making cursor.
    ---how to make the cursor
         OPEN REC_CUR FOR Select_Q;
         LOOP
         FETCH REC_CUR INTO REC_CUR_DATA;
         EXIT WHEN REC_CUR%NOTFOUND;
         END LOOP;
    END TableSnapShot_Process1;

    For online books you can start with the documentation.
    PL/SQL Packages and Types Reference
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/toc.htm
    PL/SQL User's Guide and Reference
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm
    Print books
    Oracle PL/SQL Programming By Steven Feuerstein is good book to have.
    http://www.oreilly.com/catalog/oraclep4/

  • PreparedStatement and order by clause

    Hi all,
    I'm having a strange problem, when I try to use a preparedStatement which has a parameter in the order by clause the query ignores the order by clause and returns the data in the default table order.
    I'm trying to allow the enduser the ability to sort the results in any way they like.
    a sample of code is:
    javax.sql.DataSource dataSource;
    java.sql.Connection myConnection = null;
    String sort_order = null;
    sort_order = request.getParameter("sort_order");
    if(sort_order == null) {
         sort_order = "start_date, hostname";
    String sql = (String)Tokens.getInstance().getSQLProps().get(Tokens.FIND_SCHED);
    try {
    dataSource = getDataSource(request);
    myConnection = dataSource.getConnection();
    PreparedStatement pstmt = myConnection.prepareStatement(sql);
    pstmt.setString(1, (Tokens.getInstance().getProps().getProperty(Tokens.CURRENT)));
    pstmt.setString(2, sort_order);
    ResultSet rset = pstmt.executeQuery();
    thanks for any help you can provide

    You cannot use bind variables for column names. In this case, what you are telling Oracle to do is to sort by the literal string 'start_date, hostname', which (since the literal string is the same for every row) has no effect. If you want Oracle to sort by the values in those columns, you would have to have different versions of the query depending on the ORDER BY clause. In this case, you would probably want to append the ORDER BY clause to your base SQL statement rather than trying to pass the ORDER BY clause in as a bind variable.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

Maybe you are looking for