Order by clause -dyamically in Forms

I am using Forms 6i. I want to do Forms to Excel stuff and I am doing this by opening a cursor and then start Excel routine using OLE2.
The user will select the 'order by' columns from a list-field in the form.
Problem is I have given Order by clause as given below sample, but it just don't work..
How to accomplish this ??
declare
Cursor emp_cursor is
SELECT code,name,dept,desig,salary
FROM emp
order by :s1,:s2;
begin
-- excel routine
end;

Hi vdsk,
Here is link to create_group_from_query built_in:
http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/builta_c/creategp.html&vtTopicId=
you can prepare your select statement and then concatenate with order by clause. I think that is the best soultion for you.
Regards
Jakub

Similar Messages

  • Can i assign an 'order by' clause dynamically in forms ??

    I know it's possible to assign an 'order by' clause in reports with lexical parameter.
    for example..
    select A
    from TABLE
    where A is not null
    &V_ORDERBY
    In this, v_orderby might be 'order by name' like that,,,
    can i assign an 'order by' clause dynamically IN FORMS ??
    If you understan my question, please answer to me,,,ㅜㅜ

    Have you tried this build-in function?
    SET_BLOCK_PROPERTY('[BLOCK_NAME]', ORDER_BY, 'SORTCOL1, SORTCOL2...');
    Where 'SORTCOL1, SORTCOL2...' are the table columns name.

  • How to use "Order by" clause dynamically on LOV values in 10g r2 forms

    Hi ,
    I have following requirement,please guide me.
    1 Create a List Of Values with 2 fields, Code and Description
    2. Do not use order by clause in record Group Query
    3. Attach this LOV to a field in Form
    4. When user invokes the LOV user will see two fields in LOV with header as Code and Description
    5. Now when user clicks on Column Header “Code” then LOV should be sorted on Code
    6. And if User clicks on Column Header “Description” then LOV should be sorted on Description
    Thanks in Advance.

    Kindly post this problem in this forum ->
    [Forms Forum|http://forums.oracle.com/forums/forum.jspa?forumID=82]
    And, close this thread by marked it as answered. ;)
    Regards.
    Satyaki De.

  • Order By Clause on Non-Database Column using Forms

    How to Sort by using Order by Clause on Non-Database Column using Forms6i

    Eugene,
    What is the error message/ number you are seeing? If you run "select name from tblperson order by name" do you still get an error?

  • ORDER BY clause in runtime

    Hi All,
    I want to order my SELECT using "dynamic ORDER BY". I have a CURSOR (in my PL/SQL procedure) contains a select with ORDER BY clause. I have implemented two combobox in my form (the first contains the column name, the second contains ASC and DESC).I tried with the next:
    1) Dynamic ORDER BY in CURSOR with combobox results. IT DOESN'T WORK.
    2) Using a block property named "ORDER BY CLAUSE". Here I put, for example, :myBlock.comboColumnOrder. IT DOESN'T WORK.
    3) Using a function: set_block_property(myBlock,order_by,:myBlock.comboColumnOrder) or set_block_property(myBlock,default_where,:myBlock.comboColumnOrder). IT DOESN'T WORK.
    4) Using dynamic CURSOR: ORACLE FORMS give me an error that said: "...it can't to the CLIENT-SIDE".
    I have thought my last solution, but it maybe cumbersome. I do a TEMPORARY TABLE, and my CURSOR insert in this TABLE, and then I'll fetch to my BLOCK.
    Thanks a lot.
    PS: My ORACLE Version is 10g.

    PROCEDURE CHEQUEAR_V0 IS
         V_ORDEN VARCHAR2(50) := '' || :BLOCK_CHECK.ORDER_BY_NAME || ' ' || :BLOCK_CHECK.ORDER_BY_ASC_DES ;
    CURSOR FILA_RESULTADO_TABLA IS
         SELECT Last_name,First_name,App_user, App_role, UserDB
         FROM adm_users
         WHERE
         ((Last_name IS NULL OR Last_name LIKE '%'||:BLOCK_CHECK.Last_name||'%') AND
         (First_name IS NULL OR First_name LIKE '%'||:BLOCK_CHECK.First_name||'%') AND
         (App_user IS NULL OR App_user LIKE '%'||:BLOCK_CHECK.App_user||'%') AND
         (App_role IS NULL OR App_role LIKE '%'||:BLOCK_CHECK.App_role||'%') AND
         (UserDB IS NULL OR UserDB LIKE '%'||:BLOCK_CHECK.User_DB||'%'))
    ORDER BY V_ORDEN;
         V_Last_name VARCHAR2(50);
         V_First_name VARCHAR2(50);
         V_App_user VARCHAR2(50);
         V_App_role VARCHAR2(50) ;
         V_User_DB VARCHAR2(50);
         CONT NUMBER ;
    BEGIN
         CONT := 1 ;
              GO_BLOCK('BLOCK_APPS_GRANTS');     
              CLEAR_BLOCK;
         SYNCHRONIZE;     
              OPEN FILA_RESULTADO_TABLA;
              LOOP
                   FETCH FILA_RESULTADO_TABLA INTO V_Last_name,V_First_name,V_App_user,V_App_role,V_User_DB ;
              EXIT WHEN FILA_RESULTADO_TABLA%NOTFOUND;
                        :BLOCK_APPS_GRANTS.Last_name := V_Last_name ;           
                        :BLOCK_APPS_GRANTS.First_name := V_First_name ;                               
                        :BLOCK_APPS_GRANTS.App_user := V_App_user ;
                        :BLOCK_APPS_GRANTS.App_role := V_App_role ;
                        :BLOCK_APPS_GRANTS.User_DB := V_User_DB ;                                         
                   NEXT_RECORD;
                   CONT := CONT+1;          
              END LOOP;
              IF FILA_RESULTADO_TABLA%ISOPEN THEN
                   CLOSE FILA_RESULTADO_TABLA;
              END IF;
              SET_BLOCK_PROPERTY('BLOCK_APPS_GRANTS', ORDER_BY, :BLOCK_CHECK.ORDER_BY_NAME || ' ' || :BLOCK_CHECK.ORDER_BY_ASC_DES);
              GO_BLOCK('BLOCK_APPS_GRANTS');
              EXECUTE_QUERY;
    synchronize;
              exception when others then
                   raise;
    END;
    Thanks a lot.
    Edited by: user11285646 on 22-jul-2009 2:30

  • Order by clause  based on parameter value

    hi,
    i am using reports 6i with 10 g db
    I have to create a report sorted in order of four fields. there is a parameter for selecting which field should come first in order by clause.
    ie the user has provision to view the report in selected sorted order
    suppose the four fields are emp_id, name, dept_id, desig .
    if the user select dept_id , then the order by clause should be in order of dept_id,emp_id,name,desig
    Please help to solve this scenario.
    Thanks

    Hi Rinz,
    Use the query as follows :
    select column_name1, column_name1, ....
    from  table_name
    &order_by_clauseNow in the AFTER-PARAMETER-FORM trigger set the order by clause as below depending upon requirements :
    if :sort_column = dept_id then
      :order_by_clause := 'order by dept_id,emp_id,name,desig';
    else
      :order_by_clause := 'order by emp_id, dept_id, name,desig';
    end if;
    Here sort_column is User parameter which will be selected by user, provide list of Values for it.
    Hope this helps
    Best Regards
    Arif Khadas

  • ORDER SIBLINGS not working in Forms

    This code run fine in Toad BUT giving me error in forms.
    SELECT
           LEVEL                           LOC_NAME,
           LOCATION_NAME                   LOC_ID,
           LOCATION_ID                     HLOC_ID,
           HEAD_LOC_ID MUDRA
      FROM AS_LOCATION_HDR
    CONNECT BY PRIOR LOCATION_ID = HEAD_LOC_ID
    START WITH HEAD_LOC_ID is null
    ORDER SIBLINGS BY LOC_IDThe error is:
    "Encountered sysbol "SIBLINGS" when expecting one of the following:
    by
    The symbol "by inserted before the "SIBLINGS" to continue.Is the SIBLINGS keyword not acepted in forms? What would be the alternative?
    I am using oracle forms 10G (10.1.2.0.2)

    hi
    Oracle's START WITH and CONNECT BY clauses in the
    SELECT statement automatically traverse a hierarchy.
    Without this feature, a complex self-join would be required to identify
    which rows are logically related to others.
    The START WITH clause identifies the row or rows to be considered
    the starting points, or "roots," of the hierarchy.
    The CONNECT BY PRIOR clause
    then indicates how to identify which rows are related to each other.
    example, the query in Listing A produces a "Reports To" listing from the EMPLOYEES table in the HR sample schema provided by Oracle.
    The LEVEL pseudocolumn indicates how deeply the report is currently nested; here,
    I use it to LPAD the employee names to indent them.
    The START WITH condition states that only employees 101 and 102 are to be considered as starting points.
    The CONNECT BY PRIOR clause then links the employee_id
    column in one row to the manager_id column in the next, to indicate who reports to whom.
    If you run this query in the HR schema,
    you'll notice that the last names are not sorted within the listing for a specific manager;
    they are listed in the order Oracle encountered them in processing the hierarchy.
    If you want the subordinates in alphabetical order,
    you might try to ORDER BY the original last_name column.
    However, this would break up the hierarchy, and turn it back into a flat list of names.
    You might also try to ORDER BY the pseudocolumn LEVEL first,
    which tells how deep a specific row is in the hierarchy. This, too,
    breaks up the hierarchy—all the managers will be listed first, followed by people who report to any of them.
    In Oracle 10g (both releases),
    it's now easy to do this: You can use the new SIBLINGS keyword to create the correct ordering. The syntax is:
    ORDER SIBLINGS BY <expression>So adding the clause:
    ORDER SIBLINGS BY last_nameto the end of the query will preserve
    the hierarchy and also alphabetize the last names within each level.
    Note that the original last_name was used not the alias "Reports To."
    The extra space padding in "Reports To" would affect the sort, so the original must be used.
    Listing B shows the output, both before and after adding ORDER SIBLINGS BY.
    The ORDER SIBLINGS BY clause is valid only in a hierarchical query. The optional SIBLINGS keyword specifies an order that first sorts the parent rows, and then sorts the child rows of each parent for every level within the hierarchy.
    Rows that have duplicate lists of values in the columns specified after the SIBLINGS BY keywords are arbitrarily ordered among the rows with the same list of values and the same parent. If a hierarchical query includes the ORDER BY clause without the SIBLINGS keyword, rows are ordered according to the sort specifications that follow the ORDER BY keywords. Neither the ORDER BY clause nor the ORDER SIBLINGS BY option to the ORDER BY clause is required in hierarchical queries.
    The hierarchical query in the following example returns the subset of rows in the hierarchical data set whose root is Goyal, as listed in the topic Hierarchical Clause. This query includes the ORDER SIBLINGS BY clause to sort by name the employees who report to the same manager:
    SELECT empid, name, mgrid, LEVEL
       FROM employee
          START WITH name = 'Goyal'
          CONNECT BY PRIOR empid = mgrid
       ORDER SIBLINGS BY name;The rows returned by this query are sorted in the following order:
             empid name             mgrid       level
             16 Goyal               17           1
             12 Henry               16           2
              7 O'Neil              12           3
              9 Shoeman             12           3
              8 Smith               12           3
             14 Scott               16           2
             11 Zander              16           2
              6 Barnes              11           3
              5 McKeough            11           3
    9 row(s) retrieved.Here the START WITH clause returned the Goyal row at the root of this hierarchy. Two subsequent CONNECT BY steps (marked as 2 and 3 in the level pseudocolumn) returned three sets of sibling rows:
    Henry, Scott, and Zander are siblings whose parent is Goyal;
    O'Neil, Shoeman, and Smith are siblings whose parent is Henry;
    Barnes and McKeough are siblings whose parent is Zander.
    The next CONNECT BY step returned no rows, because the rows for which level = 3 are leaf nodes within this hierarchy. At this point in the execution of the query, the ORDER SIBLINGS BY clause was applied to the result set, sorting the rows in the order shown above.
    Because the sort key, name, is a VARCHAR column, the returned rows within each set of siblings are in the ASCII order of their employee.name values. Only the sets of siblings that are leaf nodes in the hierarchy of returned rows appear consecutively in the sorted result set, because the managers are immediately followed by the employees who report to them, rather than by their siblings. An exception in this example is Scott, whose child nodes form an empty set.
    The SIBLINGS keyword in the ORDER BY clause is an extension to the ISO standard syntax for the SQL language. The SELECT statement fails with an error if you include the SIBLINGS keyword in the ORDER BY clause of a query or subquery that does not include a valid CONNECT BY clause. hope this helps u.
    sarah

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

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

  • Popup lov with order by clause

    I created a form manually using the document from the url:
    http://otn.oracle.com/products/database/htmldb/howtos/tabular_form.html#MANUAL
    I used the following query from that document.
    select htmldb_item.hidden(1,empno) empno,
    ename,
    htmldb_item.select_list_from_query(3,job,'select distinct job, job from emp') job,
    htmldb_item.popupkey_from_query(4,mgr,'select ename, empno from emp',10) mgr,
    wwv_flow_item.date_popup(6,null,hiredate) hiredate,
    htmldb_item.text(7,sal,10) sal,
    htmldb_item.text(8,comm,10) comm,
    htmldb_item.select_list_from_query(9,deptno,'select dname, deptno from dept') deptno
    from emp
    This works fine.
    But if I add an order by clause to the query the popup key for mgr column doesn't work.
    select htmldb_item.hidden(1,empno) empno,
    ename,
    htmldb_item.select_list_from_query(3,job,'select distinct job, job from emp') job,
    htmldb_item.popupkey_from_query(4,mgr,'select ename, empno from emp',10) mgr,
    wwv_flow_item.date_popup(6,null,hiredate) hiredate,
    htmldb_item.text(7,sal,10) sal,
    htmldb_item.text(8,comm,10) comm,
    htmldb_item.select_list_from_query(9,deptno,'select dname, deptno from dept') deptno
    from emp
    order by ename
    Thanks
    Chandra.

    Duplicate post, see:
    popup lov in a report is not working if I have an order by caluse
    Sergio

  • Default where with order by clause

    Hi all
    How to use Default where with order by clause
    for example i want to use Default_where clause with order by clause
    Regards
    Shahzaib ismail

    Hi,
    I have a similar query for where clause.
    my query-find form is a multi record form like below:
    Criteria - Condition - Value
    Item/Category/Planner (List_Item) - Equals/Among (List_Item) - text_FIELD
    Item - Equals - ITEM_1
    Category - Among - ('CAT1', 'CAT2')
    Planner - Equals - PL1
    Find_BUTTON Clear_BUTTON
    User can select any criteria and condition combination and then enter the value in "Value" text field.
    My query is: how can I prepare a where clause based on user input since the user can enter any number of values/combinations? I guess I would have to use some looping to generate where clause.
    Thanks
    Imran

  • Order by Clause is slow

    Guys,
    I have a table of 80,000 records.If i select * from this table need 0.04 seconds.If I add order by clause it become very slow 30 sec.
    Order by clause is on the primary key.Also i increased the size of temp tablespace.
    Kindly assist

    In Forms, LOV's are meant for a small set of values.
    For a table containing 80,000 records you need to develop a small selection form, i.e. a separate form in which you can search for values and select one value. Details for this can be acquired in the Oracle*Forms Forum. A form will typically fetch only a few rows and is therefore more suited in this case. Be sure to check the block properties "Query Array Size", "Number of Records Buffered" and "Query All Records".
    At my shop we use a standard of approximately 20 values. Below this number a LOV can be used and above a select form is recommended.
    Regards,
    Rob.

  • Order by clause not working

    Hi, everyone,
    I am trying to use the following insert statement to insert records in asc order. if i use the select statement alone the order by clause works fine, but when i use the same sql and add a insert into table statment the order by clause does not work. I am not getting the records in ascending order. could anybody help me in this regard?
    INSERT INTO cat_sales_stg
    select      b.SSC,                
         ltrim(rtrim(a.CAT_DESC)) cat_desc,                
         SUM(a.AMOUNT) AMOUNT               
    FROM Trans a, SSC b                     
    WHERE a.ACCOUNT_NUMBER = TO_CHAR(b.ACCOUNT_NUMBER)                    
         AND a.TMONTH >= 200905 AND a.TMONTH <= 200910                
         AND a.FORMAT_NAME = 'ABC'                
         AND b.BMONTH = 200910                
         AND b.SAMPLE = 3                
         AND b.BANNER_NAME = 'ABC'               
         AND b.MODEL_NAME = 'XYZ'               
    group by b.SSC, ltrim(rtrim(a.CAT_DESC))
    order by ssc,cat_desc
    Thanks in advance

    user10636796 wrote:
    Hi, everyone,
    I am trying to use the following insert statement to insert records in asc orderWhat Toon, William, and others have said is that you DON'T insert rows in a specific order. That is completely outside the way relational databases are designed. You insert rows as unordered and use an ORDER BY clause in a SELECT when reading them. ORDER BY is for SELECT statements, not INSERT.
    In particular Toon poined out that we can't control where individual rows get stored.
    There is a databas object called a varray that can store data in sorted order. I have never seen them used because selecting the data back out again is more work; using an ordinary table and an ORDER BY clause is much easier.

  • Suppress "Order By" clause in Answers Query

    Hello,
    Is it possible to Suppress "Order By" clause in Answers Query.
    I'm using a database view as data source. In the view definition, "order by" clause is already specified. Is it possible to get the same order in the OBIEE report??
    I do not want to use Sort Order column in the repository.
    Thanks,
    Girish

    You add a rownumber to your DB view and use that to 'sort' your report.
    regards
    John
    http://obiee101.blogspot.com/

  • How to make an ORDER BY clause dynamic

    is there anyway to make the ORDER BY clause in an SQL query within a DB control
    dynamic? I have tried to pass a String of the column name and place it in the
    statement within {}, but it doesn't work

    "Mark" <[email protected]> wrote:
    >
    is there anyway to make the ORDER BY clause in an SQL query within a
    DB control
    dynamic? I have tried to pass a String of the column name and place
    it in the
    statement within {}, but it doesn't workDid you find how ? please let me know, I also need to have a dynamic order by
    clause.

Maybe you are looking for

  • Div display issue

    I am having an issue with the index page at  http://http://www.pixelsandpaper.com/stANNES/St%20annes/index.html  which islocated in a temporary location.  I have set the container div to 960 px wide and have set the left and right margins to 20%, how

  • The file "iTunes Library.itl" cannotn be read

    Issue: The file "iTunes Library.itl" cannotn be read because it was created by a newer version of iTunes. Tried the following: 1) Moved iTunes Library.itl out of iTunes folder and restarted iTunes. 2) Plugged in ipod, canceled sync and 2a) Transferre

  • I have a problem in text field

    Hi All   I have a problem in text field.    First time  Text field is displaying correctly and looking good. When i will go to otherscreen and coming back to same screen text field is displaying as a normal text field and it is not appling and jquery

  • My music player is complaining about error

    I've tried to play some songs, but my music player is complaining about an unexpected error, and i just upgraded my software. I don't know if anyone has any solution to this

  • How does one attach an image to a domain in mail?

    I understand how to attach a picture, or image, to a specific person in Apple's mail.  For example, I can attach a picture of, say, the Apple logo to the email addressed [email protected] However, it would be really useful if I could add a Apple logo