Count number of Characters in CLOB field

Hi all,
I posted this on another database, but I think it really belongs here. I have a CLOB field that stores reports in HTML markup languate. Here's an example of a report.
<br><br></title> </head> <body contenteditable="true" text="#000000" bgcolor="#ffffff"> this is a test for a bilateral modifier </body> </html><br><br>
I'm trying to provide a query that counts the number of characters that is not a HTML tag nor whitespace. I've attempted to use a combination of the length and replace function which first replace all HTML tags and whitespaces with nothing and then uses length to calculate the number of characters. Here's what the function looks like.
<br><br>length(trim (both ' ' from replace (replace (replace(replace (replace(replace(replace(replace (replace(replace(replace (replace(replace (replace(reports.report_text ,'</head>',''),'</title>',''),'<body contenteditable="true" text="#000000" bgcolor="#ffffff">',''),'</body>',''),'</html>',''),'',''),'',''),'',''),'',''),'',''),'',''),'',''),'',''),'>','')))
<br><br>
For the example above, the number of characters counted in the outputs is 66, which is clearly incorrect. I need to only count these characters for the example above "thisisatestforabilateralmodifier", but there is still white space that remains after I do the sequence of replaces. If someone can help, it's be greatly appreciated. Thanks.
Message was edited by:
user577468

If you can convert your html string to valid xml you can do the following:
michaels>  SELECT str, LENGTH(REPLACE(REPLACE(XMLTYPE (str).EXTRACT ('//text()').getclobval(),CHR(10)),' ')) length
  FROM (SELECT
'<html>
<head>
  <title></title>
</head>
<body contenteditable="true" text="#000000" bgcolor="#ffffff">
   this is a test for a bilateral modifier
</body>
</html>' str FROM DUAL)
STR                                                                        LENGTH
<html>                                                                         32
<head>                                                                         
  <title></title>                                                               
</head>                                                                        
<body contenteditable="true" text="#000000" bgcolor="#ffffff">                 
   this is a test for a bilateral modifier                                      
</body>                                                                        
</html>                                                                          Otherwise regex_replace would be an alternative (on 10g).

Similar Messages

  • How to set number of characters in input field ?

    I am creating an input field dynamically (via CL_WD_INPUT_FIELD).
    I am binding the value (via BIND_VALUE) to an attribute with type CHAR30.
    I want to give the possibility to enter a number with 4 digits (0 - 9999).
    Is it possible to restrict the number of characters that can be entered to 4 (although the BIND_VALUE attribute has a type CHAR30, that allows 30)?
    I have tried it via set_length, bind_length but it seems that the length of the BIND_VALUE attribute overrules the length information...

    Hi Moritz,
    AFAIk you have no other option as using a NUM4 here.
    Set Length just sets the lengths of the inputfield according to the current character set ... count of charcters but does not limit the value you may enter
    Cheers
    Sascha

  • Method to count number of characters in a string?

    hi.
    i'm trying to write some script that will count the number of characters in a string passed into a constructor and then compare it against another value to check whether the string passed in is valid.
    something like this
    public class Stringcheck
    public static int maxStringLength;
    public static double minSize;
    public static boolean testStringLength(String x)
    // Insert method for counting number of chars in String x and name as 'int numberOfChars
    if(number of Chars <= maxStringLength )
    return true;
    else
    return false;
    can someone help me with writing this script.
    Thanks
    Richard.

    ummm, you dont need anything fancy. try:
    String test = "this is the test string";
    int length = test.length();

  • Looping assistance (counting number of characters in a variable)

    Good morning, all! I was wondering if anybody could take a look at this small, easy project I was working on today. I've searched the net for an answer and while it was useful and I learned a few things, nothing is really working. The code is pretty self explanatory, infact, I'm embarrassed I do not know how to do this, because I'm sure I know. Basically, counting the length of the variable is not working. The output is supposed to be as many times as the input is long in characters (I hope that makes sense!) Anyways, if you could take a look and tell me if you see anyway I could fix this, I would appreciate it.
    import java.util.*;
    import javax.swing.JOptionPane;/**
    * @author Willaim
    public class Loop {
         * @param args
         public static void main(String[] args) {
              String loopInput;
              int count;
              loopInput = JOptionPane.showInputDialog("Please enter a word for the loop demo: ");
              while(count < loopInput.length){
                   System.out.println("" +loopInput);
                   count = count + 1;
              for (count = -1; count < loopInput.length; ++count){
                        System.out.println(loopInput);
              do {System.out.println("loopInput");
                   count++;
                   }while (count < loopInput.length);
         }

    1) to get length from a String, you must use a method and all methods end in parenthesis (arrays are different in that you are getting the length field, and this doesn't require parenthesis.
    2) You probably don't want to use this "count" variable. You will probably be better with a for loop here since the number of iterations through the loop is defined in advance.
    Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, either use the "code" button at the top of the forum Message editor or place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]or
    {&#99;ode}
      // your code block goes here.
      // note here that the tags are the same.
    {&#99;ode}

  • How to count number  of records for a field based on condition?

    Hi guys,
    I want to know how to find count of records coming from the database for a particular field based on some condition.
    I need to use this count to suppress some headers. Because of this i am not able to use running totals. Is there any other way?
    Ex scenario:
    I have account number and currency fields, those are coming from database. And i need to count the number of accounts whose currency is not Euro.
    Thanks in advance,
    Vijay.

    A simple formula can do that:
    //Formula begin
    if {your account field}<>"Euro" then 1
    //Formula end
    This formula can be summarized. (by group or report)
    Bryan Tsou@Taiwan

  • How to count number of characters in a string?

    Hi
    I need to display values in a script. but the alignment getting distrubed if it is less than 20 charaters, for exmple material descirption is only displaying 20 characters in script. if it is less than 20 charcters the alignment getting changed.
    please help me ...urgent..
    thanks in advance...

    solution to this problem in script is not to count the characters but to align them based on positions .
    1.
    Use the tab positions  for that paragraph format to display the values in a finite format .
    In this u need to give the position start and position end length and use the same in the script as
    p ,,&itab-f1&
    say my value has to print from position 125mm to 155 mm
    i take one tab position for this paragraph format P and maintain the same in the output.
    here ,, is the tab position .
    See whether it is one character or 20 character it has to behave the same way it should not be misaligned .
    check the tab position for that paragraph format in Tabs ..
    regards,
    vijay.

  • Determine the Number of Characters in a field

    Hello All,
    I have a program where a character field of length 200 becomes populated with Purchase Order Text.  Is it possible through a function module or another option to determine the length of the field when populated?  For instance, if only 125 characters are populated in the 200 character field, then the function module would return the 125 value.  Thanks.
    John

    Sample code for ya.
    report zrich_0002.
    data: s type string.
    data: i type i.
    s = 'The string that we want to fing the length of'.
    i = strlen( s ).
    write:/ 'This length of "', s, '" is', i.
    Regards,
    Rich Heilman

  • Count number of characters in a string

    Another one for you experts:
    Is there a way to count the number of "-" in the strings below:
    For instance:
    1133500-1-RTN-629-RHR
    1133541-10-SRTN-F-630-LR
    Should return:
    4
    5
    respectively.
    Any ideas?
    Thanks in advance,
    Zack H.

    stringvar x := '1133541-10-SRTN-F-630-LR';
    stringvar array z := split(x,'-');
    ubound(z)-1;

  • Counting number of characters in a textbox

    I am keen to no, what is the best way to specify a number below a textarea, which countsdown each character entered till it reaches 0 then the user cannot enter any more characters?
    Thanks,
    Steve

    Look at some of these
    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2B%22public+void+insertstring%22+%2B%22extends+jtextfield%22+%2Bmaximum&col=javaforums

  • Restrict number of characters in table field for select statement.

    SELECT * FROM table
                    WHERE  column1  = z-column.
    The field column1 is of  type char and size 20
    The field z-column is of type char size 10.
    how do we perform this select?
    Anyone can guide me?
    Edited by: Hadesfx on Sep 11, 2009 3:56 PM
    Edited by: Hadesfx on Sep 11, 2009 3:59 PM

    Hello,
    In your OP did you mention this? Please be specific when you post the next time.
    Can you please post your code?
    I think you have to try a work around:
    DATA:
    RS_STOCKID TYPE SELOPT,
    RT_STOCKID TYPE STANDARD TABLE OF SELOPT.
    LOOP AT GT_ZB1PUT_STOCKTMP.
    RS_STOCKID-SIGN = 'I'.
    RS_STOCKID-OPTION = 'EQ'.
    RS_STOCKID-LOW = GT_ZB1PUT_STOCKTMP-STOCKID.
    APPEND RS_STOCKID TO RT_STOCKID.
    CLEAR RS_STOCKID.
    ENDLOOP.
    You can use this RANGE table to SELECT data from the table.
    SELECT * FROM zb1xxt_param
                FOR ALL ENTRIES IN gt_zb1put_stocktmp[]
                WHERE zzcode    = 'DEV036'
                AND   zzdomain  = 'SD'
                AND   zzdata    = 'INBOUND'
                AND   zzinput1  = 'STOCKID'
                AND   zzinput2  IN RT_STOCKID. "Use RT_STOCKID for SELECT'ing data
    BR,
    Suhas

  • Number of characters in long text functionality

    Can anyone please help me as to how many characters are there in long text functionality in Standard SAP. If we create a document under FB01 , there is a long text field how many characters we can enter in that text field.
    Also can we have any number of characters in custom field or is there any restriction to it.

    Hi Isha,
    Please refer the solution for your problem on this link :
    Here i have explained in detail how you can go about with providing Custom Controls on the screen.
    [Re: long text in custom screen]
    Hope this helps.
    Regards,
    Samreen.

  • How do I set a maximum length (in characters) of a CLOB field

    Hi,
    I've seen some questions like this around, but I did not find a clear answer.
    This is my problem: I want to make my CLOB field to accept a maximum of 32768 characters. This is because I need other data manipulation tools to receive an ORA error when they try to insert or update text larger than 32768.
    I tried with an Insert/Update trigger, but I received ORA error that actually means that LOB fields can not be used in update trigger(or something).
    Please, help!

    Maybe, Not a neat way to do things, but seems to work.
    Others may be able to suggest better solutions.
    SQL> create table test_lob(lob clob) ;
    Table created.
    SQL> CREATE OR REPLACE FUNCTION getlength(p_lob CLOB) RETURN NUMBER DETERMINISTIC IS
      2  BEGIN
      3      IF (dbms_lob.getlength(p_lob) > 32768)
      4      THEN
      5          raise_application_error(-20100,
      6                                  'Text may not be greater than 32768 characters!');
      7      ELSE
      8          RETURN NULL;
      9      END IF;
    10  END;
    11  /
    Function created.
    SQL> create index idx_test_lob on test_lob(getlength(lob)) ;
    Index created.
    SQL>
    SQL> declare
      2    l_lob CLOB ;
      3  begin
      4    insert into test_lob values (empty_clob()) returning lob into l_lob ;
      5    dbms_lob.writeappend(l_lob, 32767, rpad('*', 32767, '*')) ;
      6  end ;
      7  /
    PL/SQL procedure successfully completed.
    SQL> declare
      2    l_lob CLOB ;
      3  begin
      4    insert into test_lob values (empty_clob()) returning lob into l_lob ;
      5    dbms_lob.writeappend(l_lob, 32760, rpad('*', 32760, '*')) ;
      6    dbms_lob.writeappend(l_lob, 8, rpad('*', 8, '*')) ;
      7  end ;
      8  /
    PL/SQL procedure successfully completed.
    SQL> declare
      2    l_lob CLOB ;
      3  begin
      4    insert into test_lob values (empty_clob()) returning lob into l_lob ;
      5    dbms_lob.writeappend(l_lob, 32760, rpad('*', 32760, '*')) ;
      6    dbms_lob.writeappend(l_lob, 9, rpad('*', 9, '*')) ;
      7  end ;
      8  /
    declare
    ERROR at line 1:
    ORA-20100:
    ORA-06512: at "SYS.DBMS_LOB", line 789
    ORA-06512: at line 6
    SQL> select count(*) from test_lob ;
      COUNT(*)
             2
    1 row selected.
    SQL>

  • Counting the number of characters entered into a page item

    Is there a way to count the number of characters that are entered into a page item. I've got a field that can contain up to 20 characters. If 20 are entered I can do a = on my search, if less than that, then I have to do a wildcard search. I currently do a substr on the field to see if position 21 is null and position 20 is not null, then I have a 20 character field. Is there a more efficient way to do this and also is there a way to actually show the character count as the page item is being populated

    Hello user8014695 (name please),
    Try coding the select for your search as
    select ...
    from some_table
    where some_field like case when length(trim(:YOUR_ITEM)) = 20 then :YOUR_ITEM else :YOUR_ITEM || '%' end
    Note - I included the trim() assuming blank characters before or after shouldn't count.
    To show the character count as the item is being keyed-in, Google "javascript character count" for lots of ways to do this. To work these solutions into ApEx, check the ApEx help/documentation for incorporating JavaScript into your application - specifically the references on accessing page items using JavaScript.
    Hope this helps,
    John

  • How to restrict number of characters for an input field

    Hi All,
    I have an input field.
    The max number of characters for this input field is 10.
    when a user enter more then 10 characters. it should prompt for an error or the input field should not allow to accpet the 11 character.
    how we do this in VC.
    need your helpful answers
    Rgds
    Srinivas

    Hi Srinu
    You could achieve this by configuring error messages under the formula:-
    Select the control properties and in the Input field at the Display tab write the formula
    "IF((@<LEN(text)>10),'appropriate message','Records available')"
    Note :- there is a LEN(text) under text functions in formula tab.
    Regards
    Navneet
    Message was edited by:
            Navneet Giria

  • Parsing xml in clob field remove non utf-8 characters

    hi all,
    i have an issue where a stored procedure runs during a nightly process and parses xml contained in a clob field. There are some records that contain non-utf8(they paste characters from word)characters and therefore the parse fails when using performing an xquery select against the clob field as xmltype. I was wondering if anyone knew of a handy way to handle such a situation? I have looked around a bit and not found anything that seemed tailored to my situation, and I would like something a bit more generic than doing a replace on individual characters that i have found causing issues...thx in advance! -- jp

    Hi,
    Like BluShadow I'm curious to see a test case...
    Depending on the way it's been created, the encoding declared in the XML prolog doesn't necessarily reflects the actual encoding of the content.
    What's your database character set, and version?
    Please also post the error message you get (LPX-00200 probably?).

Maybe you are looking for

  • Error message when installing microsoft office

    Error 1935. An error occurred during the installation of assembly component. {837BF1EB-D770-94EB-A01F-C88389A1E118E}.HRESULT:0x800073683 That is the error message I receive each time I try to install Microsoft office. How can i resolve this issue ? I

  • Finding original filename from exported renamed jpeg

    Typically I import over 1,000 images from a job into a project. I edit and export around 500 final images as jpegs renamed sequentially for my client. My client asks for say a colour version of a particular black & white image but the file info on my

  • 1.4.2_05 NPTL not working

    I have a RedHat 9, 2.4.20-8smp kernel box. the latest 1.4.2_05 jdk bails with errors with NPTL enabled. According to the docs on bea's website, 1.4.2_04 and up should handle NPTL without a problem. Any ideas? /usr/jrockit/jrockit-j2sdk1.4.2_05/jre/li

  • Live Upgrade not working from Solaris 10 05/09 - 10/09

    I have a Blade 1000 that used to run SXCE, and I used to LU all of the time. I recently rejumpstarted it back to Solaris 10 05/09 to match production. Now that 10/09 is out, I went to do a normal LU, however it completely bombs out. I'm assuming it's

  • Writting in MS Excel which containing no sheet

    I am developing application for the taxation purpose . I have an excel workbook which is macro enabled , but there is not any worksheet . This is provided by Government of India for vat return etc . How can i write data in excel workbook without cont