How to Sort by the length of the returned value from a query.

Hi,
I was wondering if it is possible to sort by the length of the returned value from a query?
For example if I want to get a list of people with the name 'Samuel', I would like to short by how short the length of the whole name is.
Sort by length of the name in SQL
Samuel Syda
Samuel Indranaka
Samuel Johnsons
Samuel Longhenderson
Thank you.

Hi,
Sorting is done by an ORDER BY clause at the end of the main query.
In most cases, you can ORDER BY any expression, even f it is not in the SELECT clause.  In this case, it sounds like you just need:
ORDER BY  LENGTH (name_column)
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Post your query, using an ORDER BY clause like the one above, and point out where that query is producing the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002

Similar Messages

  • How to get both, the ResultSet and Output (return value) from Oracle Stored Procedure

    Hi! I am doing a conversion from MSSQL to Oracle with C++ and MFC ODBC. Any comment is appreciated!! I have Oracle 8i and Oracle ODBC 8.1.6 installed.
    My question is how to retrieve the return value AND ALSO the resultSet at the same time by using Oracle function without modifying my souce codes (except puttting mypackage. string infron of my procedure name, see below).
    -- My source code in C++ with MSSQL ....
    sqlStr.Format("{? = call ListOfCustomers(%i)}", nNameID);
    RcOpen = CustomerList.Open(CRecordset::forwardOnly, sqlStr, CRecordset::readOnly );
    Where CustoemrList is a Crecordset object...
    IN DoFieldExchange(CFieldExchange* pFX) I have ...
    //{{AFX_FIELD_MAP(CQOSDB_Group)
    pFX->SetFieldType(CFieldExchange::outputColumn);
    RFX_Long(pFX, T("Name"), mCustoemrName);
    //}}AFX_FIELD_MAP
    // output parameter
    pFX->SetFieldType( CFieldExchange::outputParam );
    RFX_Int( pFX, T("IndexCount"), mCustomerNumber);
    -- m_CustomerNumber is where i store the return value!!!
    -- In Oracle Version, i have similar codes with ...
    sqlStr.Format("{? = call mypackage.ListOfCustomers(%i)}", nNameID);
    RcOpen = CustomerList.Open(CRecordset::forwardOnly, sqlStr, CRecordset::readOnly );
    -- I have oracle package/Body codes as following...
    create or replace package mypackage
    as
    type group_rct is ref cursor;
    Function listgroups(
    nameID NUMBER ,
    RC1 IN OUT Mypackage.group_rct ) return int;
    end;
    Create or replace package body mypackage
    as
    Function listgroups(
    NameID NUMBER ,
    RC1 IN OUT Mypackage.group_rct )return int
    IS
    BEGIN
    OPEN RC1 FOR SELECT Name
    from Customer
    WHERE ID = NameIDEND ListGroups;
    END
    return 7;
    END listgroups;
    END MyPackage;
    Ive simplified my codes a bit....
    null

    yes, it is exactly what i want to do and I am using Oracle ODBC driver.
    I tried using procedure with 1 OUT var fo numeric value and the other IN OUT ref cursor var instead of function, but error occurs when I called it from the application. It give me a memory ecxception error!!
    sqlStr.Format("{? = call ListOfCustomers(%i)}", nNameID);
    RcOpen = CustomerList.Open(CRecordset::forwardOnly, sqlStr, CRecordset::readOnly );
    it seems to me that the ? marker var is making all the trouble... can you please give me any more comment on this?? thanks!
    null

  • How do I get (in c) a method return value from the java side?

    I have a class in the Java side, that I pass as object to the c side.
    in the Java class I have the following method:
    public String getPgmId()
    return pgmId;
    where pgmId is a private string.
    I nees to get the value of pgmId, hopefully by using the getPgmId method.
    what I have until now is:
    JNIEXPORT jint JNICALL Java_JavaAPI_StartProgram (JNIEnv *env, jobject obj, jobject obj2)
    jmethodID methID;
    jstring jstr;
    const char *str;
    /* Get a reference to obj2 class */
    jclass cls = (*env)->GetObjectClass (env, obj2);
    if (cls == NULL){
    return;
    methID = (*env)->GetMethodID (env, cls, "getPgmId", "()Ljava/lang/String;");
    }//StartProgram
    my question is how from this point, can I get the return value of the method getPgmId().
    tnx

    jString CallStringMethod(env, obj2, methID);

  • How do i make a still image (photo) fit the length of the music? I record music and want to put the tracks to a video file with a still image of my business logo in the background. Any help?

    How do I make a still image (photo) fit the length of the music? I record music and want to convert the tracks to a video file with a still image of my business logo in the background. On windows movie maker you could just select "fit to music" but this program isnt as easy to figure out! Any help?

    Double-click on the still image in the project timeline to open the Inspector. In the Inspector, adjust the duration by typing in a new duration to match the length of your music. I think the limit for a still image is 10 minutes. If you need more than this, simply drag the image into the timeline again then adjust its duration. The two images will play seamlessly (no gap will be visible).
    See this iMovie Help topic:
    http://help.apple.com/imovie/#mov3a883915
    You can achieve more precision when entering durations by changing a preference in the menu item iMovie Preferences. Check (tick) the preference for Show Time As HH:MM:SS:frames. This will enable you to enter the duration of stills down to the frame level, rather than full seconds (NTSC is 30 frames per second; PAL is 25 fps). When entering times, type a colon between each time segment, such as 2:50:15, which represents 2 minutes 50 seconds and 15 frames. For 5 seconds 20 frames you would enter 5:20 and so forth.
    Note that the music will only run to the length of the video in the timeline (in your case, the still images). So, after increasing the stills duration you will need to drag the end of the music track as far as required. The stills can be dragged inwards to reduce the duration if necessary.
    John
    Message was edited by: John Cogdell - added Note

  • How to increase the length of the subject line in email using FM

    Hi
    we have maintained 50 characters for the subject line initially, but some subjects are having more than 50 characters. how can we increase the length of the subject line in email.
    urgent.
    points will be rewarded generousely.

    Hi Rana,
    In this case, you have to create a user defined field of required length under Journal Transactions Header to fill the data.
    Regards,
    Vijay Kumar
    SAP Business One Forums Team

  • How to increase the length of the identifier?

    I want to create a table with a column name as:
    "domainnameregistrationassistance"
    oracle 9i does not allow me to do this.
    as the identifier length is fixed to 30 characters.
    how do i increase the length of the identifier?
    any help on this will be great!

    Don't forget that there is a comment space for each table
    and column, so calling the column DNR_ASSIST doesnt
    revent you from doing ...
    COMMENT ON TABLE M_SCHEMA.DNR_ASSIST IS '
    Domain Name Registration Assistance';

  • How to restrict the length of the input?

    Hi all, could any one tell me how to restrict the length of the input string? My SOA Suite is 10.1.3.1
    I tried the following; getting an error.
    <element name="RestrictLengthProcessRequest">
    <simpleType name="SSN">
    <restriction base="string">
    <length value="10"/>
    </restriction>
    </simpleType>
    where RestrictLengthProcessRequest is the message name of the corresponding .wsdl and SSN is the input whose length is to be restricted.
    The error is : 'Attribute name not defined on element simpleType'
    Thanks in advance.
    Edited by: user11275112 on Aug 27, 2009 11:44 PM

    Hi swathi,
    For this you have to create a simple data type. No need of writing a code.
    Go to Dictionaries -> Local Dictionary -> Data Type - > Simple Type - > Right click and "Create Simple Type".
    Here you should create a Simple type with String as built-in Type. Here you will also see the Length Constraints option.
    Set the value of maximum length and minimum length. In your case set the value of maximum length to 10. At runtime this will not allow the user to enter more than 10 characters.
    Now create an attribute and bind it to this newly created simple type. Bind the value of the input field with this particular attribute.
    Regards
    Manohar

  • How to find the length of the resultset

    how to find the length of the resultset

    (Doing a select count as somebody suggested is nota
    good solution, as the count can change betweenyour
    count query and your real query.)And the number of rows can't change between getting
    the last one and doing the actual work?I don't think so. Once you've got the ResultSet, I don't think it will change under you, unless you explicitly set it to SCROLL_SENSITIVE.
    I could be mistaken though.

  • How to fix the length of the output file

    hi,
    I have 1000 records in my source table which need to be inserted into file. But the length of the rows in my file should be only 500 i.e there should be two files getting created for this 1000 records i.e my each output file should contain only 500 rows not more than that.
    Depending on the number of records present in the source, the file getting created will be varying as my file should contain only 500 rows each. for ex: if 5000 rows are present then 10 files need to be created.
    How this can be achieved in ODI.
    Thanks in advance

    I believe this can achieved using jython easily .
    Here is a sample output code
    Command on Source - Select database Technology and required logical schema
    Command on Target - Jython
    import java.sql as sql
    import java.io as io
    import string,re
    import java.lang as lang
    import java.text as text
    myCon = odiRef.getJDBCConnection("SRC")
    myStmt = myCon.createStatement()
    my_query="SELECT * FROM  SCHEMA.TABLE_NAME "
    file_count=1
    i=1
    myRs = myStmt.executeQuery(my_query)
    writer=io.BufferedWriter(io.OutputStreamWriter(io.FileOutputStream('c:\\FILE_'+str(file_count)+'.csv')))
    md=myRs.getMetaData()
    collect=[]
    while (i<= md.getColumnCount()):
        collect.append(md.getColumnName(i))
        i+=1
    header=','.join(map(string.strip,collect))
    #writer.write(header+'\n')
    myRs = myStmt.executeQuery(my_query)
    md=myRs.getMetaData()
    myRs.setFetchSize(5000)
    i=0
    while (myRs.next()):
        j=1
        col=[]
        while (j<= md.getColumnCount()):
            col_type=md.getColumnTypeName(j)
            col_name = myRs.getString(md.getColumnName(j))
            if col_name is None:
                col_name= ''
            col.append(col_name)
            j+= 1
        data=','.join(map(string.strip,col))
        writer.write(data+'\n')
        #print data+ '\n'
        i +=1
        if (i == 500):
            writer.flush()
            writer.close()
            file_count +=1
            writer=io.BufferedWriter(io.OutputStreamWriter(io.FileOutputStream('c:\\FILE_'+str(file_count)+'.csv')))
            i=0
    writer.flush()
    writer.close()
    myCon.close()Please run this code and let me know if you need any other help or modification to get your desired results.

  • How can I know the length of the image data section of a PSD file

    I'm a C++ programmer developing a project to parse PSD files, and it's necessary to know whether there is a length field indicating the length of the image data in image data section of a PSD file, if not, how can I know the length?
    Thank you.

    Sorry I can't help, maybe there is some information in the SDK?
    http://www.adobe.com/devnet/photoshop/sdk.html
    Or someone might be able to help in this forum?
    http://forums.adobe.com/community/photoshop/photoshop_sdk

  • How to increase the length of the Info object

    Hi All
         Any one have idea about how to increse the length of the Info object Char(beyond 60). Can you please explain me in detail we are using BI7.0.
    Thanks
    Vani

    Hello Vani,
    You cannot increase the length of an info-object beyond 60 chars.However if you want to store a characteristics data with more than length 60, then you may create separate info-objects
    for example: if you need to store 'notes' which might have length more  than 60,
    then you may create info-objects like notes 1/3 ---store first 60 chars.
    notes 2/3 --- store next 60 characters and so on.
    Thanx
    Priyanka

  • How to reduce the length of the info object that's being used?

    Hi All,
    I have created info objects and used them in a DSO. Now I want to reduce the length of the info objects but i'm unable to do it. When I reduced the length and tried activating the Info object, it's giving me error and the info object is not getting activated. Please guide me how I can reduce the length and activate the Info Object.
    Thanks
    Hima Bindu

    Reducing the length of an infoobject is not that easy
    Cleanest way -
    Drop all transaction data for that infoobject
    Drop all data in the DSO and cubes.
    Reduce the length and then activate and transport all the infoobject and there dependence objects.

  • How to get the length of a field value, not the length of DB's CHAR(20)

    Hello.
    I'm trying to handle a String from my DataBase and get its length:
    String myName;
    int i;
    PreparedStatement sql = Conn.prepareStatement("SELECT NAME FROM MY_TABLE");
    ResultSet results = sql.executeQuery();
    results.next();
    myName = results.getString("NAME");
    i = myName.length();
    out.println("The value is " + myName + " and the length is " + String.valueOf(i) );
    I get:
    " The value is Tom and the lengh is 20 "
    20 is the length of the field (it's a CHAR (20) ), but I would like to get the length
    of 'Tom'.
    On other hand, I would like to detect if this value is 'Tom' or not, but trying with:
    if (myName.equals("Tom")) {...}
    or
    if (myName == "Tom") {...}
    There is no response.
    Any experience?

    myName = results.getString("NAME");
    if(myName!=null) myName = myName.trim(); //Take out trailing spaces
    i = myName.length();Sudha

  • How to increase the length of the clock signals on NI8451

    I'm using NI8451 to read data from a linear technology ADC chip.
    Using a scope, I found the clock signal only lasts for one byte (8-bit) during the read/write process,
    ie. the clock signal is turned on for one byte period (8 clocks) and then is off for about 10-20us,
    after that, the clock is on again for next byte.
    Is there a way to change the length of the clock signal? In my case, I need about 96 clocks to flush out the ADC data.
    But it looks like NI8451 only can generate 8 clocks one time.
    Any suggestion will be appreciated.

    Hi JHXU, 
    Are you using SPI or I2C? 
    With SPI, essentially the clock stops toggling when there is no more data transmitted. You could try implementing a delay in your data transmission to ensure that the clock runs for time you require. However, to add a delay, you need to use the Advanced 845x SPI functions. In CVI, the command for adding a delay is 
    int32 ni845xSpiScriptDelay ( uInt32 ScriptHandle, uInt8 Delay );
    More information on the SPI Advanced API can be found in the NI-845x Help or in this tutorial. 
    With I2C, I think you would just need to toggle the clock line (SCL) high. There is also a delay function in the Advanced I2C functions that may allow you to do this. 
    Julianne K
    Systems Engineer, Embedded Systems
    Certified LabVIEW Architect, Certified LabVIEW Embedded Systems Developer
    National Instruments

  • How to increase the length of the char which has master data!

    Hi,
    I am uploading hierarchy from flat file!
    i am using basic char texts as hierarchy texts  and my basic char has length  15 )
    Because the first 15 characters of the hierarchy short text are same, and it s total length being 15, while uploading it is giving me error saying same record values cannot be used more than once!
    ( i am using nodename as hierarchy texts  and my basic char has length  15 )
    when i try to increase the length of the char by deleting entries in it, the delete option is grayed out!
    Any suggestions?
    Thanks,
    Ravi

    Hi,
    Check it out that object where-used list, whether that object is used in any other cubes or ODS or any target......
    If it is used then delete all the data from all the targets and also object data itself.
    Then it is possible to increase the length.
    One more thing is if you want to change in Production system directly ,may be you have the display authorization only.
    You have to change it in to development system and trasport it to production system.
    Regards,
    Venkat

Maybe you are looking for

  • Why can i not view my rental movie in the ipad video app

    hello everyone Hopefully someone can help as I'm getting a tad frustrated I have been for the last 2.5hrs trying to get a rental movie I have downloaded on to my computer to sync with my Ipad2 and its simply wont do it what could be wrong? I have so

  • Issue in opening an URL from UI

    Hi Experts, When clicking  button in an assignment block of campaign screen, it should open an URL (SRM screen) in new window. I have written the following code in htm page inside script tag. window.open("lv_url").focus(); lv_url is obtained from the

  • 11gR2 installation on Solaris failed with prereuisite 124861-15

    The 11gR2 installation on Solaris 10 sparc failed with prereuisite 124861-15. When I tried to install the patch 124861-20, it failed with the following(see below): I have Sun Studio 12-2 installed on the system. It was complaining that some packages

  • How do I configure my Windows clients to talk to Mac OS X Server 10.6

    We had a MacAuthority technician install the server software for us, but he did not configure the Windows clients to talk to the server. I have tried several approaches, all evidently wrong.  Everything I have read says the Windows clients need "open

  • [Solved] Bootup Freezes

    Hi all, been using Gentoo for a very long time and now I'm starting to transition to Arch. Loving it quite a lot. I have a problem on a new install I'm doing on my ancient Macbook Pro. I got everything setup with rEFInd and grub seems to be working o