Sort by or find the longest word in a varchar2 field

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE     10.2.0.4.0     Production
TNS for HPUX: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
drop table event;
create table event  (event_title_nm varchar2(1000));
SET DEFINE OFF;
Insert into EVENT
   (EVENT_TITLE_NM)
Values
   ('CREATING A NEW CLASS WORD FOR INDICATOR, - _IN');
Insert into EVENT
   (EVENT_TITLE_NM)
Values
   ('Unknown Title');
Insert into EVENT
   (EVENT_TITLE_NM)
Values
   ('MASAL REASON TEXT');
Insert into EVENT
   (EVENT_TITLE_NM)
Values
   ('Note/Attachment Modifications and Amendments');
Insert into EVENT
   (EVENT_TITLE_NM)
Values
   ('Installation (replaces change request  66)');
Insert into EVENT
   (EVENT_TITLE_NM)
Values
   ('Unknown Title');
Insert into EVENT
   (EVENT_TITLE_NM)
Values
   ('Installation (replaces change request  66)');
Insert into EVENT
   (EVENT_TITLE_NM)
Values
   ('List Item Identifier Change');
Insert into EVENT
   (EVENT_TITLE_NM)
Values
   ('USER_ID in WORKFLOW_TASK_ASSIGNMENT');
COMMIT;I would like to select or order by the length of the longest word in the field
word defined as continous characters.
so my output would be for the first two returned
event_title_nm
USER_ID in WORKFLOW_TASK_ASSIGNMENT
Note/Attachment Modifications and Amendmentsbecause WORKFLOW_TASK_ASSIGNMENT is the largest word
and Note/Attachment is the second largest.
the reason I was trying to find thiis is that I'm displaying this value on a web page and I need to figure out the longest
continuous word because the css will not wrap a the text in the middle of a word. so it ends up pushing my entire div below where I would like it to go.
Edited by: pollywog on Oct 25, 2011 8:43 AM

pollywog wrote:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE     10.2.0.4.0     Production
TNS for HPUX: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
drop table event;
create table event  (event_title_nm varchar2(1000));
SET DEFINE OFF;
Insert into EVENT
(EVENT_TITLE_NM)
Values
('CREATING A NEW CLASS WORD FOR INDICATOR, - _IN');
Insert into EVENT
(EVENT_TITLE_NM)
Values
('Unknown Title');
Insert into EVENT
(EVENT_TITLE_NM)
Values
('MASAL REASON TEXT');
Insert into EVENT
(EVENT_TITLE_NM)
Values
('Note/Attachment Modifications and Amendments');
Insert into EVENT
(EVENT_TITLE_NM)
Values
('Installation (replaces change request  66)');
Insert into EVENT
(EVENT_TITLE_NM)
Values
('Unknown Title');
Insert into EVENT
(EVENT_TITLE_NM)
Values
('Installation (replaces change request  66)');
Insert into EVENT
(EVENT_TITLE_NM)
Values
('List Item Identifier Change');
Insert into EVENT
(EVENT_TITLE_NM)
Values
('USER_ID in WORKFLOW_TASK_ASSIGNMENT');
COMMIT;I would like to select or order by the length of the longest word in the field
word defined as continous characters.
so my output would be for the first two returned
event_title_nm
USER_ID in WORKFLOW_TASK_ASSIGNMENT
Note/Attachment Modifications and Amendmentsbecause WORKFLOW_TASK_ASSIGNMENT is the largest word
and Note/Attachment is the second largest.
the reason I was trying to find thiis is that I'm displaying this value on a web page and I need to figure out the longest
continuous word because the css will not wrap a the text in the middle of a word. so it ends up pushing my entire div below where I would like it to go.
Edited by: pollywog on Oct 25, 2011 8:43 AMORDER BY LENGTH(EVENT_TITLE_NM)

Similar Messages

  • How to find the original lengh of a VARCHAR2 field

    Hi all...
    How to find the original lengh of a VARCHAR2 field. If i use, length function, it is
    giving the length of the feild, not the orginal length of field value.
    How to find the actual length of the field.
    Thanks in advance
    pal

    > How to find the original lengh of a VARCHAR2 field.
    Why?
    And where? A varchar2 in SQL or a varchar2 in PL/SQL? Varchar2 arguments have no explicit size in parameter signature for a procedure or a function.

  • How to find the longest record in a table?

    Hello,
    Is there a function to find the longest record in a table? Or is there a data dictionary that would tell you which record contains the longest data?
    I have a table with five columns and one million records. I want to find the record (5 columns combined) with the longest data. Thank you.

    Dear watson2000!
    The function "VSIZE" tells you the number of bytes in the internal representation of a column which means the size of a value within a column. An example of vsize can be found here:
    [http://www.adp-gmbh.ch/ora/sql/vsize.html]
    So I think you should try it with this query to get the size of the longest record:
    SELECT MAX(VSIZE(column1)) +
           MAX(VSIZE(column2))  +
           MAX(VSIZE(column3))  +
           MAX(VSIZE(column4))  +
           MAX(VSIZE(column5)) AS "Maximum Row"
    FROM your_table;To identify the longest record try like this:
    SELECT rowid
    FROM   your_table
    GROUP BY rowid
    HAVING  (MAX(VSIZE(column1)) +
             MAX(VSIZE(column2)) +
             MAX(VSIZE(column3)) +
             MAX(VSIZE(column4)) +
             MAX(VSIZE(column5))) = (SELECT MAX(VSIZE(column1)) +
                                          MAX(VSIZE(column2))  +
                                          MAX(VSIZE(column3))  +
                                          MAX(VSIZE(column4))  +
                                          MAX(VSIZE(column5))
                                   FROM your_table;)I hope that these two queries could be of help to you.
    yours sincerely
    Florian W.
    Edited by: Florian W. on 23.04.2009 20:53

  • Here's how to find the right word in a string

    I needed to find the rightmost word in a string. I didn't find a simple formula in these forums, but I now have one, so I wanted to share it. Hope you find it useful.
    Assuming that the string is in cell A1, the following will return the rightmost word in the string:
    RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1," ","*",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

    I found the problem. Whatever character was being used in the substitution was parsed out by the forum parser. I replaced it with "œ" (option q on my keyboard).
    =RIGHT(A1,LEN(A1)-FIND("œ",SUBSTITUTE(A1," ","œ",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))
    Still needs an error check for a single-word "sentence" and to remove the trailing period but it does seem to work. Pretty slick.
    Message was edited by: Badunit
    I see below that the problem was fixed by the OP.
    Message was edited by: Badunit

  • How to find the exact word in a long text?

    Hi,
    Scenario:
    I have long text containing the system status of the equipment.
    Issue:
    I need to find the exact word from the list of the statuses. I have tried to use the FIND keyword but it does not work for all the cases.
    Example:
              FIND 'REL' IN <status_list> IGNORING CASE.
              if sy-subrc = 0.
              " do something
              endif.
    If the status list contains the word 'RELR', the sy-subrc is set to 0 (which may be because it searches the list based on a pattern) but I want to get the exact match.
    Can anybody suggest me on this.
    Regards
    s@k

    >
    siemens.a.k wrote:
    > Dear Kiran, Vasuki,
    >
    > The data type of status list is char with length 40.
    > The status list:
    >
    > Case 1: list -  REL  MANC NMAT PRC  SETC
    > FIND 'REL ' IN <status_list> IGNORING CASE
    > the sy-subrc is set to 0
    >
    > Case2: list - CRTD MSCP NMAT PRC  RELR SETC
    > FIND 'REL ' IN <status_list> IGNORING CASE
    > the sy-subrc is still set to 0 even though the list does not contain the word 'REL'
    >
    > I have also tried using
    > if <status_list> CS 'REL'
    > and
    > if <status_list> CS 'REL '
    >
    >
    > Please do let me know if I am anyway unclear about issue...:)
    >
    > Regards
    > s@k
    This is becacuse when you check
    > Case2: list - CRTD MSCP NMAT PRC  RELR SETC
    It is having RELR so that is the reason you are getting subrc = 0.
    >Ok try CS it should work perfectly.
    It seems... CS also not the correct answer
    (It will count RELR)  below thread sachin is correct ...Do that way ....
    Regards
    sas
    Regards
    Sas
    Edited by: saslove sap on Jan 25, 2010 6:58 AM

  • I have my download content code for the new Mountain Lion, and the printed instructions tell me to open the App Store select 'Redeem" in the quick links, enter my code. The problem is I cannot find the "Redeem" word in the quick links?  Where and why does

    How do I find the REDEEM word in the quick links section of the Mac App Store?  In fact I cannot find the quick Links either?

    Click the Featured tab, and look on the right hand side...

  • [JS] [CS3] Finding the longest instance of a paragraph style

    I'm pretty new to JS but I'm trying to write a script that will return the longest instance of each paragraph style in a manuscript (which has been imported into InDesign). Currently, my script lists all the paragraph styles found in the document and puts them in a new document. My next thought was to loop through the style names array and find the longest instance.
    Could anyone point me in the right direction on how to do this?
    Any help is much appreciated. I'm learning a lot reading this forum.

    Your question is slightly ambiguous. Do you mean you are looking for the longest instance of a paragraph in that paragraph style? That's the most likely meaning. Or are you looking for the longest run of text in that style? Because that's what you'll find if you're not careful in your script.
    The essence of the script would be:
    1. Setup a FindText for the paragraph style in question (or each style if you're looping through them all).
    setupFindText(); // use function to setup the find -- search this forum on setupFindText to find it
    app.findTextPreferences.appliedParagraphStyle = myStyle; // where myStyle is the style in question
    2. Issue the find getting all the references into a variable.
    var myFinds = app.documents[0].findText();
    3. Loop through all the finds to locate the longest paragraph.
    var longestLength = 0;
    var longestPara = null;
    for (var j = myFinds.length - 1; j >= 0; j--) {
         myParas = myFinds[j].paragraphs;
         for (var k = myParas.length - 1; k >= 0; k--) {
              myPara = myParas[k];
              if (myPara.length > longestLength) {
                   longestLength = myPara.length;
                   longestPara = myPara;
    4. Make sure that longestPara is not null (no instances found); If not, then longestPara is a reference to the longest instance
    Dave

  • After restoration of files via time capsule my status changed to "Guest" and I can't find the pass word for changing it back to Registered user. Any Help?

    after restoration of files via time capsule my status changed to "Guest" and I can't find the pass word for changing it back to Registered user. Any Help?

    Hey mate I had this same problem exept instead of my recording disappearing my Chorus that went for 8 bars extended out to 20 bars lol and I used auto tune on it and it sounds like t-pain on a very bad day so it sounds like it does a few things when it comes up that error

  • How to find the Datasource,ODS,InfoCube by a field of a R3 table

    Hey Folks!
    I'm trying to find the Datasource,ODS,InfoCube by a field of a R3 table.
    It means I want to get the Datasource,ODS,InfoCube which contain the field I wanted.
    I did the following steps, Please correct me if I'm wrong.
    1. I use table RSOSFIELDMAP to get the related Datasource and infoobject by field I wanted.
    2. Then I use the infoobject of filed which I get from step1 to get the related ODS in the table RSDODSOIOBJ.
    3. I also use the infoobject filed which I get from step1 to get the related InfoCube in the table RSDCUBEIOBJ.
    But I have concern about the way I search the ODS and InfoCube.
    Could somebody help me on it?
    Thanks.

    Hi Ihdai,
    1) In step1  what you are doing is good...that table gives the mapping of the source fields in DataSources.
    2) One if you know the InfoObject Name....Open the InfoObject definition...
        and click on the  "Multiple Arrow" button which gives "Where used list"...
        That is a better way to get the list..
    3) You can use the tables also.
    Regards, BB

  • How can I find the total word count in my entire Indesign CS3 document?

    I have a book that consists of 10 different files and many many different text boxes. I need to find out what the total word count is for the entire book. Is there a simple way to do this, or do I have to copy and paste all the text from InD into a word file to get the number? Your help is much appreciated.

    This AppleScript will get the total word counts of a folder of ID files—it shouldn't be too hard to convert to JavaScript if you are not using OSX:
    tell application "Finder"
    activate
    set myFolder to choose folder with prompt "Select the folder containing the files to count"
    set myFiles to every file of folder myFolder whose file type is "IDd5"
    end tell
    tell application "Adobe InDesign CS3"
    set wordcounts to {}
    set total to 0
    repeat with j from 1 to (number of items in myFiles)
    open item j of myFiles
    tell active document
    tell every story
    set wordcounts to wordcounts & (count every word)
    end tell
    set totalstories to count every item of wordcounts
    repeat with i from 1 to totalstories
    set total to total + (item i of wordcounts)
    end repeat
    close
    end tell
    end repeat
    display dialog "The documents in the selected folder have a total of " & totalstories & " stories, and " & total & " words"
    end tell
    ========================================
    If you just want the active document's count it would be:
    tell application "Adobe InDesign CS3"
    tell active document
    set wordcounts to {}
    tell every story
    set wordcounts to wordcounts & (count every word)
    end tell
    set total to 0
    set totalstories to count every item of wordcounts
    repeat with i from 1 to totalstories
    set total to total + (item i of wordcounts)
    end repeat
    display dialog "Total words in all " & totalstories & " stories: " & total
    end tell
    end tell

  • Sql query to find the last word in a sentence (column)

    Hi,
    I have to retrieve the last word in a column containing varchar2(text) values.
    If anyone knows the query for this kindly share with me.

    There's also the option of regular expressions in 10g onwards...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'oracle forums is the best resource for oracle intelligence' as l from dual)
      2  select regexp_replace(l, '[[:print:]]* ([^ ]*)$','\1') as l
      3* from t
    SQL> /
    L
    intelligence
    SQL>

  • How to find the database table for this screen field

    hi in XD02
    There is a scrren field customer
    name1 (firt line under name)
    and email id fields
    i wnat to know where the data stores goes w hen user eners in this screen i mean in which table and how to find it
    for kunnr name1 i suppose it goes to kna1 but how to find it?
    and f or email id whre it gots which table
    regards
    Arora

    Hi,
    when you press F1 it will give the necessary information
    but some times it may give the structure names also
    those structures are being used by the back end module pool
    programm
    so every time we can get the exact information about the
    data type or length
    but not sure that every time we get the exact database table name
    and field name
    according to me, if i dont know where some field are getting stored in
    database ( if the field name and table is structure )
    then i will ask my functional consultant ...
    thanks & regards,
    Venkatesh

  • How to find the user who has changed a field in a table

    Hello
        Someone has changed a field  cost center in my table so i need to find the user who hav changed it.Can anyone tel me how to find it.
    Regards

    HI ,
    Create a Z test program using the particular table and filed .
    Now goto SE38 and execute the program " RSDEPEND "
    give the ur test program and then execute . u will get the list of the last  change of ur program
    ( table and fields used inthis program)
    Another way :
    for data element :
    refer table 
      DD04L and get the user name
    for domain
    DD01L
    Edited by: shambhu sharan pandey on Nov 13, 2009 5:49 AM

  • How can we find the original XML Name of a Field

    Hi All,
    Just like the Reports To Field has XML Name as *[<ManagerFullName>]*
    Can anyone tell me how I can find the Original XML Name for the "Reports To (Alias)" User field?.
    Thanks in advance,
    Royston

    My scenario is that,
    When a user saves a new campaign I want to change the owner of this campaign to the user he reports to i.e(Manager Alias) Since the Owner field takes the Alias Name.
    To achieve this I have created a workflow to assign that Campaign to the Manager.
    Here is the Code snippet
    The triggering event is : Before modified record is saved.
    action is Update Field Owner with UserValue('<ManagerAlias>')
    Unfortunately its not accepting the ManagerAlias field....I have tried a similar scenario with the <ManagerFullName> field and its working fine.
    Thanks,
    -Royston
    Edited by: Royston Goveia on May 12, 2009 9:59 PM

  • How to retrieve only the text from a multiline Varchar2 field?

    Dear Friends,
    I have a text in a varchar2 field having text only in line2.
    I want to retrieve the text only skipping the blank line.
    The syntax REPLACE(FIELD_NAME,CHR(10),'') is not working.
    Please help me.
    Thanking you,
    With Regards
    Franklin

    there must be other characters in your text field that are not chr(10) (line feeds etc).
    use a regular expression to replace all the non-printable characters:
    select regexp_replace(field_name,'[^[:print:]]') from table

Maybe you are looking for