Order by a single value, then the rest as ascendants

Hello

I'm creating a list of values that lists a particular value first, then the remaining values in ascending order.

That's what I have:

Select d, name_id r name_desc
of name_table
order of decode (d, 'Charlie', d)


Desired results:

Charlie
Alfa
Bravo
Delta
ECHO


Actual results:

Charlie
Alfa
Bravo
ECHO
Delta


Any suggestions are greatly appreciated!

Thank you
Matt

Hi, Matt,

A DECODING, as you have used, can affect each line to one of the 2 groups
' (1) ' Charlie '.
(2) all other
and sort according to these groups. 'Delta' and 'Echo' are both in Group (2), so if you want to 'Delta' in front of 'Echo', then you must add an additional element, a tiebreaker, to the ORDER BY cluase, as Blushadow does.

If you know of some early impossiblly value, then you can get the right order with just a DRIVE BY post.
For example, if all the name_desc values begin with a letter, you can use DECODE to map 'Charlie' somehting that precedes the first letter in alphabetical order, for example a space:

ORDER BY  DECODE ( d
                 , 'Charlie'  , ' '
                              , d
                 )

Tags: Database

Similar Questions

  • Conditional compilation: "If the $$id cannot be set to a value, then the PLW-6003 warning message is reported.

    Hello

    So according to the documentation:

    Conditional Directives of Compilation using survey

    The directive of inquiry is used to check the compilation environment. The directive of inquiry is of the form:

    inquiry_directive ::= $$id

    A directive of inquiry can be preset as described in 'predefined help investigation with Conditional Compilation Directives' or be defined by the user. The following describes the order of the processing flow during conditional compilation is trying to solve a directive of inquiry:

    1. The id is used as a guideline for investigation in the form $$ id for the search key.
    2. Re-encoding algorithm is as follows: the string in the PLSQL_CCFLAGS initialization parameter is scanned from right to left, the search with id for a matching name (case sensitive); if it's recognized. The predefined survey guidelines are sought after; Done if found.
    3. Si le $$ id cannot be resolved to a value, then the PLW-6003 warning message is sent if the original text is not wrapped. The literal NULL is substituted as the value for undefined investigation guidelines. Note that if the PL/SQL code is wrapped, then the warning message is disabled so that the directive of inquiry not defined is not revealed.

    I take this means, if you $IF $$xxx.00 = $5 THEN... $END but have not set a $$xxx.00 with "alter session set plsql_ccflags" then you should expect an error.

    But I am unable to make this trigger, a warning, or an error, either by

    ALTER session set plsql_warnings = ' error: 06003. "

    or

    ALTER session set plsql_warnings = ' enable: all ';

    test configuration:

    SCOTT@ORCL> alter session set plsql_ccflags = '';
    Session altered.
    SCOTT@ORCL> alter session set plsql_warnings = 'enable:all', 'error:06003';
    Session altered.
    BEGIN
        $IF $$DEBUGON $THEN
            dbms_output.put_line('debug is on');
        $ELSIF NOT $$DEBUGON $THEN
            dbms_output.put_line('debug is NOT on');
        $ELSE
            dbms_output.put_line('debug is neither on nor off - DEBUGON IS NOT SET!');
        $END
       
    END;
    /
    show errors
    
    debug is neither on nor off - DEBUGON IS NOT SET!
    
    
    PL/SQL procedure successfully completed.
    
    
    No errors.
    SCOTT@ORCL>
    
    

    Miss me something; It is late after all; Thank you

    Jason

    The compiler warnings do not seem to work for anonymous blocks, only for named objects:

    dev1 > alter session set plsql_ccflags = ";

    Modified session.

    dev1 > alter session set plsql_warnings = ' enable: all ';

    dev1 > create or replace procedure p as
    2 start
    $3 $IF $DEBUGON $THEN
    4 dbms_output.put_line ('debug is on ');
    5 $ELSIF $ $DEBUGON $THEN NO
    6 dbms_output.put_line ("' debugging is NOT on");
    7 $END
    8 dbms_output.put_line (' ' in the procedure ');
    9 end;
    10.

    SP2-0804: Procedure created with compilation warnings

    dev1 > view the error
    P: PROCEDURAL errors

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    3/8 PLW-06003: directive of unknown inquiry ' $$DEBUGON '
    5/15 PLW-06003: directive of unknown inquiry ' $$DEBUGON '

    John

  • How to make objects of value to "the rest of the project" persists on the last page?

    In Captivate 5, we have set the calendar for the footer graphic and logo for 'Show for': "the rest of the project."

    These two items appear on each page until the user advances or close the window. However, on the last page of the course, these elements fade. It seems that if the blade is set for 3 seconds, the objects disappear after 3 seconds.

    Is there a way to get these items "rest of project" to continue to display on the last page of the course, the learner will close the window?

    Or does do the last slide time longer, for example, 20 seconds?

    Or should we use slide masters for the footer rather than the option 'rest of slide '?

    Thanks in advance for any ideas or suggestions!

    I don't have CP5. But in CP5.5, to make this work, I would be:

    1. Put these objects on the slide.
    2. Set transition Fade In only. (Transition in the properties panel accordion)
    3. Switch to Filmstrip mode.
    4. Configure each slide to use the master slide.

    I guess that's the way it works in CP5. Give it a try.

  • AppleScript find and pass variables with a single value for the new string

    Hello again,

    I need a solution to do this:

    We have the string

    {0, 0, '62 21 37', 1, 0, ' 62 21 37 ", 2, 0," 108 50 56 ", 3, 0," 167 102 95 ", 4, 0, ' 108 50 56", 5, 0, "145 84 83", 6, 0, "109 50 58", 7, 0, "109 50 58", 8, 0, "129 62 66", 9, 0, "120 56 62", 10, 0, "104 47 57" "" "" "" "" "} (a few example of result window)

    This is a Pixel data - x, y and RGB as a text

    How can we separate it into different channels organized by RGB, to create something like

    {'109 50 58', 6.0 7.0}

    {'62 21 37', 0,0,1,0}

    {"108 50 56", 2,0,4,0}

    and etc.

    Thank you

    Try using:

    the_string value {0, 0, '62 21 37', 1, 0, ' 62 21 37 ", 2, 0," 108 50 56 ", 3, 0," 167 102 95 ", 4, 0, ' 108 50 56", 5, 0, "145 84 83", 6, 0, "109 50 58", 7, 0, "109 50 58", 8, 0, "129 62 66", 9, 0, "120 56 62", 10, 0, "104 47 57" "" "" "" "" "}

    Set new_strings to {}

    Repeat with 3 to (count elements of the_string) by 3 this_item

    Set temp_list to {}

    If the element the the_string this_item is not in temp_list then temp_list temp_list this_item & point of the_string

    Repeat with this_list_item points of temp_list

    the value new_strings new_strings & (this_list_item as a list)

    end repeat

    Repeat with this_list from 1 to (account new_strings)

    If (this_list point new_strings as String) is point of the_string this_item then

    point Set this_list to {this_list point of new_strings} new_strings & elements (this_item - 1) at (this_item - 2) of the_string

    end if

    end repeat

    end repeat

    Repeat with 1 to (count elements of new_strings) this_list_1

    Repeat with this_list_2 (this_list_1 + 1) (count new_strings elements)

    If this_list_1 point new_strings is not {} and this_list_2 point new_strings is not {}, then

    If the item 1 of article this_list_1 of the new_strings is point 1 of article this_list_2 of the new_strings then

    point Set this_list_1 of new_strings to the point of new_strings this_list_1 & (items 2-3 (point get new_strings this_list_2))

    this_list_2 point new_strings value {}

    output of repetition

    end if

    end if

    end repeat

    end repeat

    Set result_string to {}

    Repeat with this_string in new_strings

    If this_string is not {}, and then assign result_string result_string & this_string

    end repeat

    (143290)

  • Best practices for retrieving a single value from the Oracle Table

    I'm using Oracle Database 11 g Release 11.2.0.3.0.

    I would like to know the best practice to do something like that in a PL/SQL block:

    DECLARE
        v_student_id    student.student_id%TYPE;
    BEGIN
        SELECT  student_id
        INTO    v_student_id
        FROM    student
        WHERE   last_name = 'Smith'
        AND     ROWNUM = 1;
    END;

    Of course, the problem here is that when there is no success, the NO_DATA_FOUND exception is thrown, which interrupts the execution.  So, what happens if I want to continue despite the exception?

    Yes, I could create a block nested with EXCEPTION section, etc, but it seems awkward for what seems to be a very simple task.

    I've also seen this handled like this:

    DECLARE
        v_student_id    student.student_id%TYPE;
        CURSOR c_student_id IS
            SELECT  student_id
            FROM    student
            WHERE   last_name = 'Smith'
            AND     ROWNUM = 1;
    BEGIN
        OPEN c_student_id;
        FETCH c_student_id INTO v_student_id;
        IF c_student_id%NOTFOUND THEN
            DBMS_OUTPUT.PUT_LINE('not found');
        ELSE
            (do stuff)
        END IF;
        CLOSE c_student_id;   
    END;

    But it still seems to kill an Ant with a hammer.

    What is the best way?

    Thanks for any help you can give.

    Wayne

    201cbc0d-57b2-483a-89f5-cd8043d0c04b wrote:

    What happens if I want to continue despite the exception?

    It depends on what you want to do.

    You expect only 0 or 1 rank. SELECT INTO waiting for exactly 1 row. In this case, SELECT INTO may not be the best solution.

    What exactly do you do if you return 0 rows?

    If you want to set a variable with a NULL value and continue the treatment, Frank's response looks good, or else use the modular Billy approach.

    If you want to "do things" when you get a line and 'status quo' when you don't get a line, then you can consider a loop FOR:

    declare
      l_empno scott.emp.empno%type := 7789;
      l_ename scott.emp.ename%type;
    begin
      for rec in (
        select ename from scott.emp
        where empno = l_empno
        and rownum = 1
      ) loop
    l_ename := rec.ename;
        dbms_output.put_line('<' || l_ename || '>');
      end loop;
    end;
    /
    

    Note that when no line is found, there is no output at all.

    Post edited by: StewAshton - Oops! I forgot to put the result in l_ename...

  • 4500 envy: Envy 4500 a different ip address then the rest of the network

    Group on the computer of a friend, they have xfinity internet, desktop running win 8.1 that prints and a laptop under earn 10 that doesn't work. The ip address of the printer is 10.288.136.14, the gateway is 10.0.0.1 and that two computers use this subnet when I try to connect to the printer without going through the software it tells me unable to connect on the desktop and the laptop sees him not at all. Any help would be appreciated

    THX in advance

    Scott Loddesol

    Hi @sloddesol,

    Thanks for getting back to me with this information.

    I restore the default settings for the network, restart the printer and restart the router, then run the Wireless Setup Wizard to reconnect to the network.

    Once the new connection is established, try again the wireless installation.

    If the same problem still exists, this support document may contain something useful - printer does not maintain the wireless connection.

    Please let me know how it goes.

    Thank you!

  • using Windows8 and when you perform a search I get about 6 selectable sites and then the following seems to be as written in the program data!

    When I use the search engine some sites appear on the screen OK, but then the rest appear as programming information. That is to say, it is not possible to read what the sites are.

    I tried to take a screenshot, and although this seems to have been succesfull it will not download. Download images show that it is to continue to load "screenshot. PNG', but it will not download.

    I hope someone can help my description above problem!

    Thanks FredMaD
    That seems to have done the trick

  • How to replace the value of a column in a table based on the value in the second column?

    Hi, I would like to find in a table 2D for values that meet certain criteria (for example, a column< 0.98).=""  based="" on="" which="" rows="" meet="" this="" criteria,="" i="" want="" to="" replace="" the="" values="" in="" a="" different="" column="" of="" the="" array="" (change="" to="" 'nan'="" so="" that="" the="" values="" will="" not="" be="" included="" in="" any="" calculations="" on="" that="" column,="" for="" example="" the="" finding="" the="" mean).=""  i've="" attached="" a="" sample="" .csv="" file.=""  if="" the="" values="" in="" column="" 3="" (index="" 2)="" are="" less="" than="" 0.980="" (or="" some="" other="" user="" defined="" value),="" then="" the="" value="" in="" column="" 2="" (index="" 1)="" should="" be="" replaced="" with="" nan.=""  can="" someone="" help="" out="" with="" this="" search="" and="" replace="">

    Thank you

    Keith

    (using LV 2009 SP1)

    A few quick hits.

    You can merge the two for loops

    You have not need one of the constants 1 and 2 in the index table.  They will solve automatically when you expand on the index picture, once you have wired to 0 in the column index.

    It seems a lot of handling additional table spent unnecessarily.

    See below.  I did not try to duplicate your code to see how it actually works, but I believe that I have attached will give the same result with less steps.

  • null value for the parameter in quesry

    Please help on this problem:

    I have a query like

    Select colA, colB
    from tableA
    where cola =: parameter;

    If: parameter has a value, then the request is ok for my pupposes,
    but when: parameter is null, then I have to choose only 3 values of colA. (ColA has more than 3 distinct values)

    I can't use nvl because there are 3 arguments and no 1.

    I tried:

    Select colA, colB
    from tableA
    where (: parameter is not null and colA =: parameter) or (: parameter is null and colA (1,2,3))

    but this isn't the solution.

    Can someone help me on this simple query?

    Your version must have worked as long as you have no other filter criteria in the where condition.
    Need you some parentheses around the OR condition. So I don't know what was the problem with your solution.
    BTW: There is a ') ' missing at the end, but I guess that it's just a typo while copying the code on the forum.

    The following alternative works:

    select colA, colB
    from tableA
    where colA in (nvl(:parameter,1) ,
                 nvl(:parameter,2) ,
                 nvl(:parameter,3)
                 ) ;
    

    Advantage: Can be faster in the case of null, because it can always use an index on the column of cola.

    Published by: Sven w. on April 13, 2010 15:26

  • Not able to see the value of the item description-&gt; main classification

    Hello group,

    I configured the responsibility of China. From now on, I'm not able to see the lov primary classification in the item Description screen.

    China HRMS Manager-> Total Compensation-> Description-> primary Classification (column) element the only value that is gathering is "initialization of balance."

    Where we, the responsibility, I am able to see more options. Can someone suggest me the reason for the same.

    Thank you

    It's 11.5.10 version

    Hi please refer to the below metalink note...
    566421.1 setting form element has a single value in the primary Classification balance initialization
    See you soon
    Ganesh

  • In the first 12 items, how to rotate a single clip without affecting the rest of the film

    In the first 12 items, how to rotate a single clip without affecting the rest of the film

    [Left non-technical Forum Lounge for forum specific program...] MOD]

    Select the clip, right-click then select rotate.

  • Input values default settings for a workflow run through the REST interface

    Can someone give me an overview here, I have a workflow configuration that takes a series of input parameters, most of the time the default values (defined through the presentation tab) are correct, so I hope not not to be specified in each request only on exception

    How can I call the workflow to execute with other api provides only the settings I have and leave the value default those to do their job?

    There is a REST API for presentation and execution of workflow.

    So, you can use presentation REST API to create/update presentation running, providing only the necessary parameters. As a result of these API calls, you will get the values for all time settings (those you passed to the call) and those calculated by your presentation logic. Then, you can call the REST API by passing all values returned by presentation REST API for the execution of workflow.

  • I just bought the rest of photography, then a message popped up on the screen saying that my computer will not support the program. Will I have to pay?

    I just bought the rest of photography, then a message popped up on the screen saying that my computer will not support the program. Will I have to pay?

    Please check the terms of System. Photoshopand unresponsive to your material, please update your computer or cancel the order, for this you can contact customer service

    [Note: make sure that you are connected to the Web site with the valid Adobe ID under which the product is]

    For more information on cancellation: cancel your creative cloud membership

  • ERROR: The specified parameter 'Rental' expects a single value, but your name criteria "PROD" corresponds to multiple values.

    Hello

    I am writing a script to create the new VM (base clone of a virtual machine) in a specific folder.

    When you run the script, I get an error:

    The specified parameter 'Rental' expects a single value, but your name criteria "PROD" corresponds to multiple values.

    Some research led me to a post of 2011, which describes the same error. The only thing is, I can find no trace of open connection and then a more...

    What I tried:

    I run the script on the server for vSphere, so I closed the open vSphere client.

    closing ('disconnect-viserver") all existing connections in the first line of the script-> an error because no connection is open.

    In several places in the script, add the following lines:

    ECHO ' - '.

    $DefaultVIServers <-as noted in the post of 2011

    ECHO ' - '.

    This shows that no connection is open until I do the "connect-viserver", subsequently, apparently, that a connection is established.

    the results and the (current) script are found in the files to attach.

    I also found an error on the "set-PowerCLIConfiguration that I can't explain.

    One last question... Is there a possibility to have the new virtual machine created through 3 hosts? the first on the first host, the second on the second, the third on the third, the fourth back on the first host,... and so on?

    Any help would be appreciated.

    Thank you.

    Johan

    Of course, you can provide the full path, for example see my post of folder by Path .

  • Values in the list by the order of table in SELECT Union

    Version: 11.2

    Apparently a very basic thing. But I couldn't do it :)

    In the UNION example below automatic sorting in is based on alphabetical order. I want to get rid of this sort and list the values according to the order of the table in the SELECT.

    Test data
    create table test1 (name1 varchar2(10));
    
    create table test2 (name2 varchar2(10));
    
    create table test3 (name3 varchar2(10));
    
    
    insert into test1 values ('EARTH');
    insert into test1 values ('TAURUS');
    insert into test2 values ('YELLOW');
    
    insert into test2 values ('ALPHA');
    insert into test2 values ('TANGO');
    
    
    insert into test3 values ('BRAVO');
    
    
    select name1 from test1
    union
    select name2 from test2
    union
    select name3 from test3;
    
    NAME1
    ----------
    ALPHA
    BRAVO
    EARTH
    TANGO
    TAURUS
    YELLOW
    
    6 rows selected.
    In the above example, I want the values in the first array SELECT listed first, then all the values of the second table in SELECT it and so on.

    Basically my requirement will be
    Return all values from test1 (alphabetically sorted)
    then
    Return all values from test2 (alphabetically sorted)
    then
    Return all values from test3 (alphabetically sorted)
    Expected results:
    NAME1
    ----------
    EARTH  ------------> from the first table in the SELECT
    TAURUS ------------> from the first table in the SELECT
    ALPHA  ----------------------> from the second table in the SELECT
    TANGO  ----------------------> from the second table in the SELECT
    YELLOW ----------------------> from the second table in the SELECT
    BRAVO  ------------------------------> from the third table in the SELECT

    Hello

    Union made a distinct in terms of the line. From the line "ALPHA", 2 and the line 'ALPHA', 3 are different, they both show in the result set.

    Further, you are all just lucky, that you get the results you want with the order clause:

    order by 2
    

    This performs a sort on the second column (1,2,3)
    Also, you want to sort on the first column (name1, name2 and Name3). The order clause should be (as already shown correctly abbove):

    order by
      2, 1
    

    Kind regards

    Peter

Maybe you are looking for