sort a single column in the order the asc and desc

How can I write a query to sort a column in the order the asc and desc?

I tried with the following query, but it gives an error-

Select ename, (select ename from emp by ename desc) to order the CSA ename emp;

You try to do this?

SQL > ed

A written file afiedt.buf

1 with t as (select ename

2, row_number() (any order by ename): the nurse

3, count (*)-(row_number () () (any order by ename)-1) as the rn2

4 of PEM

5            )

6. Select e1.ename

7, e2.ename

8 t e1

Join 9 t e2 on (e1.rn = e2.rn2)

10 * order by e1.rn

SQL > /.

ENAME ENAME

---------- ----------

ADAMS WARD

ALLEN TURNER

BLAKE SMITH

CLARK SCOTT

FORD MILLER

JAMES MARTIN

KING JONES

KING JONES

MARTIN JAMES

MILLER FORD

SCOTT CLARK

BLAKE SMITH

ALLEN TURNER

DISTRICT ADAMS

14 selected lines.

But why you want to do this, I don't know.

Edited: to correct error in the code

Tags: Database

Similar Questions

  • Sort a hyperlink column in the classic report

    4.2.1

    THM2:

    Hi I have a classic report with a hyperlink column. And I need enable sorting on this. What I did is

    Select '< a href = "somelink" >' | party_name | "< /a > ' party_name party_name table.

    However, I just need to show the hyperlink column in the report. Couple of questions

    1. How can I create party_name-based sorting logic using the updated classic sorting standard? Given that all a hyperlink names begin with < - sorting is random. I added the second party_name column an active by default sort on it, but given that the column can not be shown, is not a good way.

    2. I was wondering if there is another way to sort this classic report hyperlink column as shown in the hyperlink and sorting is enabled on the report?

    Thank you!

    ryansun wrote:

    Hi Fac586 - Yes, the requirements are not of the same report. We have several pages with the same type of aspect, however, some of them have a different feature. In this case, Yes, I too simplified it so that easier to understand. I use the hyperlinks on query sql rather that the link of the column is because we have about 5 unions in this query from different sources and each of those interviewing him, having a hypertext link and additional formatting like "BOLD", color etc, under certain conditions. Query1 will return only the party_name, the second query United would have hypertext links, the third would fat etc. The union of the request is not made to take into account this feature, but because of the nature of the data.  While the apex feature works very well, the only question I hit is the hyperlink column sorting in a classic report. Where the simplified question. Individual responses, I've had have been very useful and have been applied successfully.

    In this case, the request for a classic report that has column link, how to sort would work it would be on a regular character column.

    Option 1 (deeply inelegant): Generate an HTML comment containing the sort at the beginning of the column value. The value must be sortable using the character comparison semantics, so dates must follow the format YYYYMMDD, numbers padded to the same length with zeros etc: Re: problem with the Date command

    Option 2A: Expand the Expression HTML technique described in your previous thread (marking dynamically of columns in a "BOLD" for the highest value report) to include the tags.

    Option 2b: Use the HTML Expression technique described in the previous thread to include custom data attributes and use these to add links to dynamic actions.

    If this is done on several pages, and then create a view all the necessary logic and the columns which you can keep it in one place.

  • In Oracle SQL, select cannot use the column in the statement and order of

    Hello

    Is there a work around for this.

    Thanks in advance
    Pablo.

    Hello

    943981 wrote:
    Hi all

    This is the error I get:

    ORA-00960: column ambiguous naming in select list
    00960 00000 - "ambiguous column naming in select list".
    * Cause: A column name in the order by list corresponds to more than a select
    columns in the list.
    * Action: Delete columns duplicated naming in the selection list.
    Error on line: column 6:17

    This error message seems pretty clear to me. What don't you understand?

    Or the other
    (a) use aliases, so each column has a unique name, or
    (b) remove the columns duplicated of the SELECT clause.

    Post your query. It is difficult to tell exactly what you're doing wrong when we do not know exactly what you are doing.
    For best results, view a complete test (including CREATE TABLE and INSERT statements) script, if necessary that people can to recreate the problem and test their ideas.
    See the FAQ forum {message identifier: = 9360002}

  • How to convert a single column in the primary key column

    Hi all

    I have a column that's unique cnstraint, this column contains the value as digital and also null.

    So how do you convert to primary key column

    Concerning
    Prashant

    Prashant wrote:
    Hi all

    I have a column that's unique cnstraint, this column contains the value as digital and also null.

    So how do you convert to primary key column

    Concerning
    Prashant

    Prashant,

    You must assign new values to null values. You can use a sequence to produce the figures in this column.

    Select max (your_unique_column) from your_table; -find the maximum value of this column, so you can start the sequence of this number.

    create sequence seq_for_your_table with XXXX - value max + 1 you have found

    Update your_table set your_unique_column = seq_for_your_table.nextval () where your_unique_column is null

    You can create a primary key on this column.

    Best regards

    Grosbois

    -------------------------------------------------------
    If you answer this question, please mark appropriate as correct/useful messages and the thread as closed. Thank you

  • Query took too much time when adding new column to the table and the index set on this

    I added a new column to the table that contains thousands of records. and created the composite index with three columns (those newly added + two existing column)

    for the specifics. TBL table there are two columns col1, col2

    I added the new column col3 to TBL and created composit index (col1, col2, col3).

    Now for all the records in col3 is NULL. When I choose on this table, it takes too long...

    Any idea what my I do bad., I have check the query plan, it is using the index

    It is solved using collection of statistics using the

    DBMS_STATS. GATHER_TABLE_STATS

    @Top.Gun thanks for your review...

  • passing two values in a guest column for the display and filtering

    Hi all

    Is there a workaround solution to use two columns in a command prompt to display and the passage of the input for a prompt value in dashboard prompt value? For example we want to display the description in the command prompt, but pass the variable value or the presentation of the filter id, just as we have in bi publisher, LOV automatically enter the value both for the display and the actual value to pass to the query. Therefore, the user clicks the description and corresponding id will be stored in the variable presentation of the guest of.

    Thank you

    Sushil

    Published by: 872073 on April 5, 2013 11:06

    Check this box
    http://www.rittmanmead.com/2010/08/Oracle-BI-EE-11g-handling-double-columns-iddescription-interoperability/

  • How can we have a column with the text and radio button in the same row?

    Hello

    I have a column that need to have data with a radio button. Has been able to achieve this by using < trh:tableLayout >. But when I select the option button it moves to the next line. You want to stop this behavior of option button to move to the next line. This column also includes a hyperlink. If the text and the hyperlink are made invisible visible based on the action of the radio button.
    Adding one more doubt. A horizontalgrid of specific columns can make invisible?
    Any help would be appreciated.

    example code:
    < trh:cellFormat id = "cf8" halign = 'Start' >
    < af:activeOutputText value = "#{rank." Actions}"id ="aot2"/ >
    < af:goLink text = ' #{rank. " Actions}"id ="gl1 ".
    clientComponent = "true" visible = "false".
    targetFrame = "_blank" destination = "http:// + #{rank." BUTTON_URL} ">"
    < / af:goLink >
    < af:selectBooleanRadio text = "" id = "sbr1" > "
    < af:clientListener method = "selectCheckBox" type = "click on" / >
    < / af:selectBooleanRadio >
    < / trh:cellFormat >

    Thank you
    Nita

    Remove the components from . Put the other components like the direct children of the PanelGroupLayout:

    
      
        
        
        
        
          
        
      
    
    

    If you need to add some space between the components horizontan, you can put (s) between components.

    Dimitar

  • How to get a column using the logical AND operator on two columns?

    All columns are the VARCHAR2 data type.

    I got out of the table in this way:
    col1 col2
    True True
    True false
    False false
    but I want an extra column in this way:
    col1 col2 result
    True True True
    True false false
    Fake fake fake
    as the clear sound output shows this column resut is logical operator AND
    col1 and col2. How to get there?
    WITH t AS
         (SELECT 'True' col1, 'True' col2 FROM DUAL
          UNION ALL
          SELECT 'True' col1, 'False' col2 FROM DUAL
          UNION ALL
          SELECT 'False' col1, 'True' col2 FROM DUAL
          UNION ALL
          SELECT 'False' col1, 'False' col2FROM DUAL)
    SELECT col1,col2,CASE
              WHEN col1 = 'True' AND col2 = 'True'
                 THEN 'True'
              WHEN col1 = 'True' AND col2 = 'False'
                 THEN 'False'
                 WHEN col1 = 'False' AND col2 = 'True'
                 THEN 'False'
              WHEN col1 = 'False' AND col2 = 'False'
                 THEN 'False'
           END AS RESULT
      FROM t
    
  • Multiplication of the columns in the table and displays the result

    Hello Experts!
    With the help of Jdeveloper 11 g Release 1:
    I have a situation where I have a two tables showing the relationship of the master / detail. Now the main table shows the available quantity and the unit price and will then multiply to show the total price.
    The Details table does the same thing but has an additional column (added manually) with another text entry that requires the 'quantity' and then I need the total price with this value as well. So overall, the user has the option to select a quantity that is less than or equal to the quantity available (from the main table) and then to calculate the new total price based on user input.
    How can I go about it?
    All of the suggestions! ?
    s =

    I apologize in advance if this does not work for you, but here's my point of view.

    (1) add QtyDesired as a transitional editable column with a set of expressions Qty.
    (2) make your transitional column TOTALCOST an expression of QtyDesired * UNITPRICE.
    (3) according to how your page is set up, your QtyDesired may need to raise a contextual event. Otherwise, it might be enough to assign partial release of your TotalCost your column QtyDesired column to allow a partial page refresh. I do something similar by editing the line of my table in a popup, and then when the dialog box closes, it refreshes the table with the new values.

    Hope that helps. Just throwing some ideas out there. AutoSubmit and partial triggers seem to trouble many of my problems of refresh.

  • How can I get the tab bar to move the bookmarks column to the bass and opening on the far left.

    I have my favorites set as a sidebar fixed. In versions 2.0 and 3.0, when I open the tabs they were starting to the right of the bookmarks bar. Now with v15.0 I see it forcing the bookmark sidebar down and place a tab right above him. I tried the subject: configuration on the tabs and bookmarks settings with no luck. All I want is to have the behavior as if it were in 2.0. In other words, the bookmark sidemark is fixed and the tabs bar starting to the right. I can see where the developers thought it would be wise to extend the bar tab all the way from the far left of the browser on the right-hand page. But I like well confined in a quadrant to set.
    Thank you.

    No, it isn't. This "control" is part of a regular toolbar now. Any element of the toolbar can be out on the tab bar, as with other toolbars.

  • Script Export single Pages with the name and file custom paragraph Style?

    I have a document called "mydocument".

    I have a several pages in the document.

    Each page has a title of"style with a stylesheet called point title.

    I need to export each page as individual .jpg with a custom file name

    myDocument-01 - title.jpg

    01 is the page number

    Seemed like a simple request... but it turns out that it's a little challenging.

    This scipt below, that I found on another thread a little work

    It gives me a

    Title1.jpg

    But I can't figure out how...

    1. Add the name of "mydocument".

    2. have a 0 on the 1-digit numbers

    Can someone please guide me, I would be eternally grateful.

    if (app.documents.length != 0) {
         var myDoc = app.activeDocument;
        MakeJPEGfile();
    }
    else{  
         alert("Please open a document and try again.");  
    } 
    
    
    function MakeJPEGfile() { 
    
    
    
    
    
    
         for(var myCounter = 0; myCounter < myDoc.pages.length; myCounter++) {
    
              if (myDoc.pages.item(myCounter).appliedSection.name != "") {
                   myDoc.pages.item(myCounter).appliedSection.name = "";
              }
                
                var myPageName = myDoc.pages.item(myCounter).name;
              var myJpegPrefix = "";
              var isStyleExist = true;
    
              //Checking the existing of the paragraph style (filename)
              try {
                  myDoc.paragraphStyles.item("title");
              }
              catch (myError) {
                  isStyleExist = false;
              }
    
              if (isStyleExist)
    
    
              myJpegPrefix = getParagraphContent(myDoc.paragraphStyles.item("title"), myDoc.pages.item(myCounter)) + myPageName;
              app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high; // low medium high maximum
              app.jpegExportPreferences.exportResolution = 72;
              app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
              app.jpegExportPreferences.pageString = myPageName;
    
    
              var myFilePath = "~/-client/JOYS - Just Organize Your Stuff/-Art/-art-book-kindle/" + myJpegPrefix + ".jpg";
              var myFile = new File(myFilePath);
              myDoc.exportFile(ExportFormat.jpg, myFile, false);
         }
    }
    
    
    // The new function, but needs to add checking the file name rules.
    
    
    function getParagraphContent (paragraphStyle, currentPage)
    {
        var paragraphContent = null;
        for (var c = 0; c < currentPage.textFrames.length; c++)
        {
            for (var i = 0; i < currentPage.textFrames.item(c).paragraphs.length; i++)
            {
                if (currentPage.textFrames.item(c).paragraphs.item(i).appliedParagraphStyle == paragraphStyle)
                {
                    paragraphContent = currentPage.textFrames.item(c).paragraphs.item(i).contents;
       // Remove spaces and returns at the end:
                    paragraphContent = paragraphContent.replace(/\s+$/, '');
       // Replace remaining spaces with hyphen:
                    paragraphContent = paragraphContent.replace(/\s+/g, '-');
       // Make lowercase:
                    paragraphContent = paragraphContent.toLowerCase();
                    return paragraphContent;
                }
            }
        }
        return paragraphContent;
    }
    
    

    Thank you Mi!

    One more step.

    I just need to remove the extension .indd.

    My file name is now

    myDocument.indd - 01 - title.jpg

    If (app.documents.length! = 0) {}

    myDoc var = app.activeDocument;

    MakeJPEGfile();

    }

    else {}

    Alert ("Please open a document and try again.");

    }

    function MakeJPEGfile() {}

    for (var myCounter = 0; myCounter< mydoc.pages.length;="" mycounter++)="">

    If (. appliedSection.name myDoc.pages.item (myCounter)! = "") {}

    myDoc.pages.item (myCounter).appliedSection.name = "";

    }

    var myPageName = myDoc.pages.item (myCounter) .name;

    var myJpegPrefix = "";

    var isStyleExist = true;

    Audit of the existing paragraph style (filename)

    try {}

    myDoc.paragraphStyles.item ("title");

    }

    {} catch (MonErreur)

    isStyleExist = false;

    }

    If (isStyleExist)

    myJpegPrefix = getParagraphContent (myDoc.paragraphStyles.item ("title"), myDoc.pages.item (myCounter)) + '-0 "+ myPageName;

    app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high; low medium high maximum

    app.jpegExportPreferences.exportResolution = 72;

    app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

    app.jpegExportPreferences.pageString = myPageName;

    var CheminMonFichier = "" ~/-client/JOYS - just organize your Stuff Art / /-art-book-kindle / "+" / "+ myDoc.name +"-"+ myJpegPrefix +".jpg";

    var myFile = new File (myFilePath);

    myDoc.exportFile (ExportFormat.jpg, myFile, false);

    }

    }

    The new feature, but it will add filename rules checking.

    function getParagraphContent (paragraphStyle, currentPage)

    {

    var paragraphContent = null;

    for (var c = 0; c)< currentpage.textframes.length;="">

    {

    for (var i = 0; i)< currentpage.textframes.item(c).paragraphs.length;="">

    {

    If (currentPage.textFrames.item (c).paragraphs.item (i) .appliedParagraphStyle is paragraphStyle)

    {

    paragraphContent = currentPage.textFrames.item (c).paragraphs.item (i) .silence;

    Remove the spaces and returns at the end:

    paragraphContent = paragraphContent.replace (/ \s+$ /, ");

    Replace the remaining spaces with hyphen:

    paragraphContent = paragraphContent.replace (/ \s + / g, '-');

    Make lowercase:

    paragraphContent = paragraphContent.toLowerCase ();

    Return paragraphContent;

    }

    }

    }

    Return paragraphContent;

    }

  • FILL A SINGLE COLUMN IN THE FORM OF A FIELD IN ANOTHER REGION.

    Hello

    I am using Oracle APEX 4.2. In one of my pages, I have two regions. One of them has a text field and a button, as well as the region, another with a tabular presentation.

    http://Apex.Oracle.com/pls/Apex/f?p=41771:2:14057730603424:

    I want to enter some data in the field of text and when I press the button called Estado, just checked lines change the value in the State column.

    Help, please!

    Thank you.

    Eve

    Dear Eve,

    I did a PL/SQL process called updatePAGObyEstado executed when you press the button with the following code

    BEGIN
       for i in 1..apex_application.g_f01.count loop
         update PAGO
         set PAGO_ESTADO = :P2_VALOR
         where PAGO_ID = apex_application.g_f01(i);
       end loop;
       COMMIT;
    END;
    

    Please, if this solves your problem, mark it as Correct.

    Best regards
    Mahmoud

  • Works with tables/columns of the lines and the parameter names... syntax help

    I am trying to create a function that returns the distinct value and counts of a user defined schema/table/column.

    The code below defines a [stats_on_column_obj] object type and creates a single table of this type [stats_on_column_tab].

    The function is supposed to take three input variables: p_schema_name, nom_table_p, p_column_name and return an array (above).

    I can hardcode a select into (the)... but once I try to convert it into settings & immediate exec I'm stuck. The red section is where the problem is (I think).

    Oracle 10g.

    Stats_on_column_obj CREATE TYPE IS OBJECT (

    COL_VAL VARCHAR2 (500),

    NUMBER OF COL_VAL_CNT (7)

    );

    CREATE TYPE Stats_on_column_tab IS TABLE OF stats_on_column_obj;


    FUNCTION to CREATE or REPLACE get_STATS_ON_COLUMN

    (

    p_schema_name IN varchar2,

    nom_table_p IN varchar2,

    p_column_name IN varchar2

    )

    RETURN STATS_ON_COLUMN_tab

    IS

    l_STATS_ON_COLUMN_tab STATS_ON_COLUMN_tab: = STATS_ON_COLUMN_tab ();

    n INTEGER: = 0;

    str_select_tbl varchar2 (5000);

    BEGIN

    str_select_tbl: = 'SELECT'. p_column_name |' as col_val, count (*) as col_val_cnt FROM ' | p_schema_name |'. ' || nom_table_p: ' group of ' | p_column_name;

    FOR r IN (str_select_tbl)

    LOOP

    l_STATS_ON_COLUMN_tab. EXTEND;

    n: = n + 1;

    l_STATS_ON_COLUMN_tab (n): = STATS_ON_COLUMN_obj (r.col_val, r.col_val_cnt);

    END LOOP;

    RETURN l_STATS_ON_COLUMN_tab;

    END;

    /

    [Error] PLS-00103 (124:4): PLS-00103: encountered the symbol "LOOP" when expecting one of the following numbers: * & - + / at rem rest mod.. < an exponent (*) > | multiset year DAY_

    [Error] PLS-00103 (126:9): PLS-00103: encountered the symbol "=" when expected in the following way: constant exception < an ID > < a between double quote delimited identifiers > double Ref table Fedya Chariot of time timestam

    [Error] PLS-00103 (127:29): PLS-00103: encountered the symbol "

    [Error] PLS-00103 (128:4): PLS-00103: encountered the symbol "END" when waiting for one of the following numbers: begin function package pragma procedure subtype type use < an ID > < a double quote delimited identifier > form

    SELECT * FROM TABLE (get_STATS_ON_COLUMN ('SCHEMAS_X', 'TABLE_X', 'COLUMN_X'));

    Scott@ORCL > CREATE OR REPLACE
    FUNCTION get_STATS_ON_COLUMN () 2
    3 p_schema_name IN varchar2,
    4 nom_table_p IN varchar2,
    5 p_column_name IN varchar2
    6                                )
    7 STATS_ON_COLUMN_tab of RETURN
    8 EAST
    9 v_STATS_ON_COLUMN_tab STATS_ON_COLUMN_tab: = STATS_ON_COLUMN_tab ();
    10 v_n INTEGER: = 0;
    11 v_str_select_tbl VARCHAR2 (5000);
    BEGIN 12
    13 v_str_select_tbl: = ' SELECT stats_on_column_obj (' | p_column_name |) ', Count OF ' |
    14 p_schema_name | '.' || nom_table_p | "Group of" | p_column_name;
    15 v_str_select_tbl EXECUTE IMMEDIATE
    COLLECTION IN BULK 16
    17 IN v_STATS_ON_COLUMN_tab;
    18 RETURN v_STATS_ON_COLUMN_tab;
    END 19;
    20.

    The function is created.

    Scott@ORCL > select *.
    2 from table)
    (3 get_STATS_ON_COLUMN)
    4                                            'SCOTT',
    5                                            'EMP',
    6                                            'JOB'
    7                                           )
    8                       )
    9.

    COL_VAL COL_VAL_CNT
    -------------------- -----------
    CLERK                          4
    SELLER 4
    PRESIDENT 1
    MANAGER 3
    ANALYST 2

    Scott@ORCL >

    Or better change function in the pipeline.

    SY.

  • Changes of data type of column between the local and remote database

    Please point me the proper documentation, so I can understand what is happening.and how to solve the problem in the short term until we can change the database character set to match the remote database.

    Details:

    Remote database: set of 12 c CARS characters AL32UTF8

    Database local 11g 11.2.0.4 as UTF8 character.

    CREATE TABLE local_table_t AS (SELECT NAME FROM reference_table_t@remotedb)

    the NAME column in reference_table_t to remotedb is varchar2 (10 byte), it creates this column in local_table_t as varchar2 (30 bytes)

    CREATE TABLE local_table2_t AS (SELECT NAME FROM reference_table2_t@remotedb)

    the NAME column in reference_table_t to remotedb is varchar2 (10 char), it creates this column in local_table_t as varchar2 (30 char)

    This same problem also happens with views materialized from the remotedb.

    Thank you

    Dave.

    Found note size double or triple column when using (materialized) views / DEC in a db AL32UTF8 and the dblink pointing to a non-AL32UTF8 db (or vice versa). (Doc ID 1592514.1)

    that answers my question.

    Dave.

  • do a select from table using order by ASC and recover only a range

    Hello
    I have a problem in my program and I want to know the line which is the cause in order to correct the code!

    -There is a line between 19500 and 19600 lines that gives me an error.
    -my program made a NLSSORT (my_field, ' nls_sort = binary "") AS "KEY1".

    so I think that if I do something like that, I get the same order:

    Select * from my_table
    order my CSA my_field
    where the rank number bettween 19500 and 19600

    My problem:
    I have no idea how to do this last part. does anyone know how to do this?
    I was just trying to sort it out and then check out lines up to 19600, but I can't do that because there is no enough space in temp score.


    Thank you.

    Best regards
    Ricardo Tomas
    select col1, col2, col3...
    from (select my_table.*, rownum rn
           from (select * from my_table
                    order by my_field asc
                 ) my_table
          )
    where rn between 19500 and 19600
    

    Note: you must order in a subselect before applying the rownum because the order is usually applied after the right column in a statement pseudo-device select rownum.

Maybe you are looking for