ORDER BY using a Non-SELECT list column

I need to SELECT DISTINCT values from a column and ORDER it by another column in the same table which is not in the SELECT list. When i got
ORA-01791: not a SELECTed expression error, I tried various things like putting ORDER BY clause in the outer query, using a DISTINCT in the ORDER BY clause,..etc but couldn't succeed.
SQL> create table sample_table (col1 number, col2 number);
Table created.
SQL> select distinct(col1)
  2  from sample_table
  3  order by col2;
order by col2
ERROR at line 3:
ORA-01791: not a SELECTed expression
SQL> select col1 from
  2  (select distinct(col1) col1 from sample_table)
  3  order by col2;
order by col2
ERROR at line 3:
ORA-00904: "COL2": invalid identifier
SQL> select distinct(col1) col1 from sample_table
  2  order by distinct(col2);
order by distinct(col2)
ERROR at line 2:
ORA-00936: missing expressionAny workarounds for this seemingly simple requirement?

Any workarounds for this seemingly simple requirement?This is not a simple requirement. It is a self contradictory requirement.
You want to order an result on a attribute that you don't have. This is not possible from a logical point of view.
Like saying,
"I want the typical/distinct family size in houses in my town, ordered by house number."

Similar Messages

  • DESFORMAT=XML puts Select list columns in wrong order

    Hey,
    ANYONE ELSE HAVING THIS PROBLEM?
    Scenario:
    1.Run RDF report in IE browser with DESFORMAT=XML
    2.Save the resulting output on Workstation Desktop
    3.Open this output file using EXCEL
    Problem:
    The Select-List columns appear in alphabetical order when viewed in EXCEL
    I TRIED DESFORMAT=XML BECAUSE DESFORMAT=SpreadSheet PRODUCED OUTPUT WITH VERY BAD FORMATING...ROWS NOT ALIGNED...COLUMN HEADINGS SKEWED...LOTS OF BLANK ROWS....LOTS OF BLANK COLUMNS...etc...etc...
    Comments/Suggestions appreciated!

      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'ZCONTRACT_REPORT'
        CHANGING
          ct_fieldcat      = tbl_alvfieldcat.
    then
      LOOP AT tbl_alvfieldcat INTO wa_alvfieldcat.
        MOVE 'GTBL_REPORT' TO wa_alvfieldcat-tabname.
        CASE wa_alvfieldcat-fieldname.
          WHEN 'DATE_ORDER'.
            wa_alvfieldcat-col_pos = 4.
            wa_alvfieldcat-just = 'L'.
            wa_alvfieldcat-reptext = 'Date Order'.
            wa_alvfieldcat-scrtext_s = 'Date Order'.
            wa_alvfieldcat-scrtext_m = 'Date Order'.
            wa_alvfieldcat-scrtext_l = 'Date Order'.
            wa_alvfieldcat-outputlen = 10.

  • Problem Ordering/Limiting LOV by non-SELECTed column

    When I try to create a dynamic LOV using the following SQL query:
    select reportname d, pageno r
    from dms_occurances
    order by occurances desc
    limit 2
    I get the following error:
    LOV query is invalid, a display and a return value are needed, the column names need to be different. If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query.
    This makes absolutely no sense to me, as the query appears valid. What am I doing wrong here? I'm trying to create a LOV for the two most popular report pages viewed in the application.

    Hi
    I am not sure that LIMIT would work with Oracle... you may need to use ROWNUM instead:
    select *
    from
    (select reportname d, pageno r
    from dms_occurances
    order by occurances desc
    where rownum <= 2
    Regarding the message... I think it is a "standard" message, which is displayed even if the problem is not related to the columns number/names. :o/
    Luis

  • How Do I Filter a Report Using a Multi Select List Box and Specifying Date Between Begin Date and End Date

    Hope someone can help.  I have tried to find the best way to do this and can't seem to make sense of anything.  I'm using an Access 2013 Database and I have a report that is based on a query.  I've created a Report Criteria Form.  I
    need the user to be able to select multiple items in a list box and also to enter a Begin Date and End Date.  I then need my report to return only the records that meet all selected criteria.  It works fine with a ComboBox and 1 selection but can't
    get it to work with a List Box so they can select multiple items.  Any help is greatly appreciated while I still have hair left. 

    The query should return all records.
    Let's say you have the following controls on your report criteria form:
    txtStart: text box, formatted as a date.
    txtEnd: text box, formatted as a date.
    lbxMulti: multi-select list box.
    cmdOpenReport: command button used to open the report.
    The text boxes are used to filter the date/time field DateField, and the list box to filter the number field SomeField.
    The report to be opened is rptReport.
    The On Click event procedure for the command button could look like this:
    Private Sub cmdOpenReport_Click()
    Dim strWhere As String
    Dim strIn As String
    Dim varItm As Variant
    On Error GoTo ErrHandler
    If Not IsNull(Me.txtStart) Then
    strWhere = strWhere & " AND [DateField]>=#" & Format(Me.txtStart, "yyyy-mm-dd") & "#"
    End If
    If Not IsNull(Me.txtEnd) Then
    strWhere = strWhere & " AND [DateField]<=#" & Format(Me.txtEnd, "yyyy-mm-dd") & "#"
    End If
    For Each varItm In Me.lbxMulti.ItemsSelected
    strIn = strIn & "," & Me.lbxMulti.ItemData(varItm)
    Next varItm
    If strIn <> "" Then
    ' Remove initial comma
    strIn = Mid(strIn, 2)
    strWhere = strWhere & " AND [SomeField] In (" & strWhere & ")"
    End If
    If strWhere <> "" Then
    ' Remove initial " AND "
    strWhere = Mid(strWhere, 6)
    End If
    DoCmd.OpenReport ReportName:="rptMyReport", View:=acViewPreview, WhereCondition:=strWhere
    Exit Sub
    ErrHandler:
    If Err = 2501 Then
    ' Report cancelled - ignore
    Else
    MsgBox Err.Description, vbExclamation
    End If
    End Sub
    If SomeField is a text field instead of a number field, change the line
            strIn = strIn & "," & Me.lbxMulti.ItemData(varItm)
    to
            strIn = strIn & "," & Chr(34) & Me.lbxMulti.ItemData(varItm) & Chr(34)
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Resolved: Use value from select list in pl/sql block

    Hello,
    I have a form with a select list: P18_BONUSTYPE, the values of which come from a LOV.
    When the user clicks a button, a page process is used to insert a row into a table.
    When I use the :P18_BONUSTYPE bind variable in my insert statement I get an error "Invalid number" I get an "Invalid number" error. I assume that APEX is using the displayed text in that bind variable, not its actual (html option) value.
    I checked the HTML of the page, and the correct values are in the select list.
    Can someone tell me how to get the value into a bind variable that can be used in a pl/sql block for a page process?
    Thanks
    Message was edited by:
    Neeko
    Issue was a value in another item.

    Did you tried changing the value using "to_number"? (i.e. to_number(:P18_BONUSTYPE)).
    Max.

  • Can a Tree be used as a Select List?

    Hi
    I'd like to use a tree structure in APEX as an interactive 'Select List Item' or a Menu component.
    When users click on a particular tree node, the selection will be highlighted and it's associated PID from the underlying query can be accessed to filter a Report.
    Is this possible?
    Thanks
    Greg

    Hi Andy
    I had hoped to use the normal APEX tree item to drive interactive user selection.
    The tree report in APEX seems a bit limited for this requirement. I'm unable to click on individual leaf elements.
    The tree list shared component, on the other hand, gives me this functionality. Unfortunately, there does not seem to be a way to populate a list from query?
    I've found Scott Spendolini's AJAX tree, which I'm trying to implement and test to see if it suits my requirements, however, I'd prefer to use internal APEX features, if it all possible.
    Please let me know APEX caters for this.
    Many thanks
    Greg

  • Inserting multiple rows into a table using a multiple-select list

    I'm trying to figure out how to take the output of a multiple-select list (":" separated list of values) and use that to update a table by inserting multiple rows based on the values. Is there a straight-forward way to do that in APEX?
    Thanks.
    Chris

    Hi Chris,
    I think this should give you what you need: Working with a Multiple Select List Item
    --Jennifer                                                                                                                                                                                                                                                                                                                                                                                                   

  • Trying to use Spry with Select List

    I have a dataset that is static xml. .In the xml file I have
    a node called categoreis and then repeating node of store name,
    phone and address in that category. There are around 15 categories
    and a total of 100 stores with address and phone. I can create the
    select list and add the onchange event to tell Spry which row of
    data was selected in the drop down. I do not understand how to
    generate the detail region that shows the stores for that
    particular category. Any help would be appreciated.

    Always include the following information when asking a question:
    <ul>
    <li>Full APEX version</li>
    <li>Full DB/version/edition/host OS</li>
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)</li>
    <li>Browser(s) and version(s) used</li>
    <li>Theme</li>
    <li>Template(s)</li>
    <li>Region/item type(s)</li>
    </ul>
    taepodong wrote:
    Hi All,
    Bit at loss what i am doing wrong here. Trying to change a field (previously in textfield) to a drop down select list. All works except one. It looks like Multi-selector even though I set the type as Select List
    http://i.imgur.com/Hz7tP.png
    Got no idea what I have to do to change it to drop down. Many Thanks.If you are on apex 4.x, you might have set the Allow Multiple Selection to Yes
    Edit the select list item > Settings > set Allow Multi Selection to No
    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21674/item_types001.htm#HTMDB28627

  • Order BY with ROWNUM in Select List

    Hi,
    I have query like bellow for Oracle 11g:
    create table em_c (vl_s_ec int,id_em_em int,id_empcre_ecr int, id_em_ec int);
    create table em (id_em_em int)
    Select e.id_em_em
    , NVL(
    (SELECT * FROM(SELECT a.vl_s_ec FROM em_c a WHERE a.id_em_em = ec.id_em_em
    AND a.id_empcre_ecr < ec.id_em_ec order by a.id_em_ec DESC) WHERE ROWNUM <= 1) ,0) AS col2
    FROM em_c ec
    INNER JOIN em e on ec.id_em_em = e.id_em_em
    WHERE 1 = 1;
    But inner subselect doesn't see table "em_c ec" from outer FROM clause. That's why following error occurs:
    SQL Error: ORA-00904: "EC"."ID_EM_EC": invalid identifier
    Please help me to make it work.
    Edited by: user11290901 on Dec 17, 2010 2:11 AM

    Correlation names only go one level deep. It's a bit tough to decipher your query so if you want a better response please post the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Using multiple select lists in ADF

    Hi,
    I am trying to use a multiple select list in my JSP page, and have a method in the ApplicationModule be called when the Struts action is called. I am following the example ADF tutorials, where the method is added to the ApplicationModule class, then dragged onto the Stuts Flow diagram (to associate it with an action).
    I am able to create a dyna form bean for the page that contains the multi select as a type "java.lang.String[]" (string array). I am able get that values that were selected in a normal action's "execute" method. For example:
    msf = (DynaActionForm) form;
    String[] statusSelection = (String[]) msf.get("multSelectList");
    However, I cannot seem to get the "multSelectList" values into a method in my Application Module class. The "multSelectList" is defined in my dynaFormBean as a String[] type. I am passing it in as an argument like the following....
    public void setParams(String multSelectList[]) {
    This results in the method not being called at all. I am not sure why. Does this have something to do with a String[] not being serializable??
    However, if I just attempt to pass other types form items to the method, it works. For example:
    public void setParams(String simpleCheckbox) {
    Does anyone know how to use multiple select lists in conjunction with ADF?
    P.S.
    my multSelectList looks something like this:
    <select name="multSelectList" multiple size="5">
    <option value="ALL">Select All</option>
    <option value="preferred">Preferred</option>
    <option value="standard">Standard</option>
    <option value="approved">Approved</option>
    <option value="interim">Interim</option>
    </select>

    I got this working by changing the signature of the Application Module method to use ArrayList rather than String[], then you can marshal the Struts FormBean contents into an ArrayList to pass up.
    To do this, subclass the DataAction by using "Go To Code" off of the context menu and then override the initializeMethodParameters() method:
      protected void initializeMethodParameters(DataActionContext actionContext, JUCtrlActionBinding actionBinding)
        //Get the String Array from the Form Bean
        String[] selection = (String[])((DynaActionForm)actionContext.getActionForm()).get("multiSelect");
        //convert that to an ArrayList
        ArrayList selectionArr = new ArrayList( Arrays.asList(selection));
        //Add that object to the Arg List for the AM method
        ArrayList params = new ArrayList();
        params.add(selectionArr);
        actionBinding.setParams(params);
      }

  • Using Multi Select List in SQL Query

    Hi all,
    I am trying to using a Multi Select list for filtering of a report. I have :P2_RISK_SEVERITY which has has the possibility of values Very Low:Low:Medium:High:Very High. How do I use this Multi Select in the where section of a SQL query?
    I need to say something along the lines of:
    Select RISK_SEVERITY from TBL_RMD_RISKS where RISK_SEVERITY = (one of the options selected in the multi select)
    Thanks for the help.

    Hi there,
    The above suggestion will work perfectly as long as the table you're querying is relatively small, but keep in mind that applying the INSTR to the left side of the WHERE clause will always result in a full table scan. This means that if your table is large and RISK_SEVERITY is indexed, the index will never be used. Here is another approach (credit to AskTom) that converts your colon-delimited string of selected values to a list that can be used in an "IN(...)" clause, which will use an index on RISK_SEVERITY as long as the optimizer otherwise deems it appropriate:
    -- creates a type to hold a list of varchars
    CREATE OR REPLACE TYPE vc2_list_type as table of varchar2(4000);
    -- converts a colon-delimited string of values to a list of varchars
    CREATE OR REPLACE FUNCTION vc2_list(p_string in varchar2)
       return vc2_list_type is
       l_string       long default p_string || ':';
       l_data         vc2_list_type := vc2_list_type();
       n              pls_integer;
    begin
       loop
          exit when l_string is null;
          n := instr(l_string, ':');
          l_data.extend;
          l_data(l_data.count) := ltrim(rtrim(substr(l_string, 1, n - 1)));
          l_string := substr(l_string, n + 1);
       end loop;
       return l_data;
    end vc2_list;
    -- your WHERE clause
    where risk_severity in(
             select *
               from the(select cast(vc2_list(:P2_RISK_SEVERITY) as vc2_list_type)
                          from dual))
    ...Hope this helps,
    John

  • How to write a javascript function on a report column with type select list

    I have a report with a select list column:
    HTMLDB_ITEM.SELECT_LIST_FROM_LOV(22, "tablename"."PRIMARY", 'PRIMARY').
    The value of primary can be null, yes, no. I want to write a javascript to achieve this: once the user changes one primary value to be yes, others with 'yes' will be changed to 'no' automatically.
    Could somebody help me on this.
    Thanks.
    Jen

    Thanks Patrick for your quick reply.
    I created a dynamic action with the following steps, but the dynamic action is not taking place.
    Event: After Refresh
    Selection Type: Region
    Region: Report 1 (my report name)
    Then in the true action
    Action: Execute Javascript SCode
    Code: showHighlight();
    I even tried to get an alert, but the dynamic action is not done at all. It seems the After refresh dynamic action is not working for a region.

  • "Headers" or disabled items in select list.

    This used to work...
    SELECT d, r
    FROM (SELECT tr.description d, TO_CHAR (tr.ID) r,
    tgr.description grouporder, tr.description toolorder
    FROM hr.bi_tools_reg tr JOIN hr.bi_tools_group_reg tgr
    ON tr.GROUP_ID = tgr.ID
    WHERE tr.ID NOT IN (
    SELECT brc.comp_id
    FROM hr.bi_register_competence brc
    WHERE brc.user_name = :app_user
    AND brc.comp_type_id = 2
    AND brc.comp_id IS NOT NULL)
    UNION
    SELECT '   ---' || tgr.description || '---' d, ID || '" disabled="disabled' r,
    tgr.description grouporder, 'a' toolorder
    FROM hr.bi_tools_group_reg tgr)
    ORDER BY grouporder, toolorder
    Creating a list of greyed-out ---Description--- in the second select and the selectable items in the first select and then merging them into one list in the proper order. Resulting in a list with headers that are non-selectable and a number of selectable items below each of them...
    Suddenly It doesn't work anymore (with ie 8.0.7600 and APEX 4 as opposed to working in 8.0.6001 and APEX 3.2.1)
    the workin header rows look like this in the html source
    <option value="3" disabled="disabled">   ---Microsoft---</option>
    and in the newer ie they look like this:
    <option value="3&quot; disabled=&quot;disabled">&amp;nbsp;&amp;nbsp;&amp;nbsp;---Microsoft---</option>
    Any ideas on how to get around this?

    This is due to select list <tt>option</tt>s now being HTML-escaped in APEX 4.0. See +{thread:id=2126522}+
    Use the -capable select list plug-in<tt>optgroup</tt>-capable select list plug-in instead.
    (When posting code, please \...\wrap it in <tt>\...\</tt> tags.)

  • Select List in a Tabular Form

    Hello all,
    Using APEX 4.1 on Oracle 11.2 SE (Oracle Linux Server release 6).
    I have a Page with a region based on a Tabular Form.
    The Region Source query has various columns, including an ID. I have also added a DATE column and a "Button" column which appear on every row.
    The extra DATE field is displayed as a Select List on a Named LOV.
    The extra Button field is displayed as a standard report column, and has Column Link attributes which cause it to branch to another page when pressed.
    What I want to happen is that when the user presses the button on one of the rows, APEX sets two application items before going to the new page:
    1. the ID column for the row in which the button was pressed
    2. the value currently highlighted in the Select List, for the row in which the button was pressed
    Using a Column Link item value of #ID# I can successfully get hold of the ID column for the correct row.
    But doing the same for the Select List column invariably returns the default value of the Select List (i.e. the initially-selected value). It doesn't pick up the change if the user has gone into the Select List and chosen a different value.
    Can anybody advise the easiest way to acquire the selected value in a Select List in a Tabular Form?

    Thanks for the reply!
    To get this working I did the following:
    1. Used APEX_ITEM.SELECT_LIST_FROM_LOV(... p_item_id=>'LOVI_'||TO_CHAR(id) ...) in the base query, to generate the LOV. (Note: the ID column is the primary key, so no need to use a ROWNUM column)
    2. Added a Standard Report Column with the following settings:
    Link Text = <img ... >
    Link Attributes = Empty
    Target = URL
    URL = javascript:window.location.href = 'f?p=&APP_ID.:123:&SESSION.::::ID,SELECTED_STRING:#ID#,'+$v('LOVI_'+'#ID#');
    So when the link is pressed, the JavaScript is invoked and it evaluates to the value currently present in the uniquely-named <select> item.
    Ian

  • Not Allowing a Value to be Selected in a Select List

    Version 4.1.1.00.23
    Hello,
    I've created a Select List to display Projects within a Department (we call them Groups).
    A Group will have Projects, however, more than one Group can have a Project with the same name.
    So my query for the Select List displays the data in a Hierarchical format like this:
    Group 1
        Proj Grp 1
        Proj Grp 1
        Proj Grp 1
        Proj Grp 1
        Proj Grp 3
    Group 2
        Proj Grp 1
        Proj Grp 1
        Proj Grp 2
        Proj Grp 2
    Group 3
        Proj Grp 1
        Proj Grp 2
        Proj Grp 3
    What I'm looking for is to NOT allow the 'Group' level to be selected within the list. Only allow the Project level values to be selected.
    The query is:
    WITH t
         AS (SELECT 'Group: ' || vg.group_name name
                   ,vg.group_id
                   ,NULL id
                   ,1 AS weight
             FROM   vertical_group vg
             WHERE (vg.group_id = :P100_GROUP OR :P100_GROUP = 0)
             UNION ALL
             SELECT '....' || project_name
                   ,group_id
                   ,project_id
                   ,2 AS weight
             FROM   tbs_projects
             WHERE  status IN ('Pipeline'
                              ,'Planned - Partially Funded'
                              ,'Planned'
                              ,'Execution') AND
                    ( :P100_RYG_PROJECT = 0 OR :P100_RYG_PROJECT = ryg_proj_id ) AND
                    ( group_id = :P100_GROUP OR :P100_GROUP = 0 ))
    SELECT name
          ,id
    FROM   t
    ORDER BY group_id
            ,weight
            ,name
    Can someone help me with this?
    Is there additional information I can provide?
    Thanks,
    Joe

    The HTML optgroup element is used to structure select lists in this way. Standard APEX Select Lists and LOVs do not have support for generating optgroup elements in option lists, but item plug-ins with this feature are available.
    See the documentation for more on using plug-ins.

Maybe you are looking for

  • How to find out the Area Menu for a Report/ Table/Function Module

    Hi, Is there any procedure to find out the <b>"AREA MEANU"</b> for a Report/Table/Function Module... Or is there any Transaction code / Report is available to find out all the report for a particular "AREA MENU". Thank you for your quick response...

  • SSRS reports are not fitting properly in Report Viewer Control

    Hi All, We are using Report Viewer Control to render SSRS reports & show it on SharePoint web page. In .aspx page we are putting Report Viewer Control as follows: The zoom percent of Report we are getting from Report Server is 100%. We are making it

  • F110 - Pmnt adv - can specify bespoke SAPscript but not bespoke print prog

    Folks, As developer I have a requirement to develop bespoke SAPscript to print off payment advices via F110. I have taken a copy of standard sapscript F110_IN_AVIS to create the Z version, and know how to specify this bespoke form via transaction FBZ

  • Block Categorys

    Still cannot Block Pornography/Adult/Illegal drugs etc.  Any Ideas will be helpful. Ironport S160>Web Security Manager>Access Policy>block categorys but still nothing. Non-profit sites getting blocked as malware??...I thought S160 would block these s

  • Smart Guides Not Showing

    Hi, Smart Guides are not showing when I use Adobe Illustrator CC. There were several posts in this forum that suggest turning of "snap to grid" and double checking the preferences that smart guides are on. I've done both and provided screenshots. Sma