REGEXP_REPLACE works --- sometimes

Hello,
I try to write a procedure to spool a clob.
since SQL*PLUS does not print leading spaces I have an option to replace the first space by another character. I do so by using REGEXP_REPLACE, see the line marked with 2).
CREATE OR REPLACE PROCEDURE pl
     p_text                 IN CLOB
    ,p_max_length           IN PLS_INTEGER := 255
    ,p_delimiter            IN VARCHAR2 := CHR(10)
    ,p_replace_space        IN VARCHAR2 := '.'
IS
    v_pos_Bis               PLS_INTEGER;
    v_text                  CLOB;
    v_delimiter_found       BOOLEAN;
    v_tmp_text              VARCHAR2(2000);
BEGIN
    IF LENGTH(p_replace_space) != 1
      OR p_replace_space IS NULL
    THEN
        RAISE_APPLICATION_ERROR(-20001,'Parameter p_replace_space must have exactly one character');
    END IF;
    dbms_lob.createTemporary(v_text, TRUE);
    dbms_lob.copy(v_text,p_text,dbms_lob.getLength(p_text));
    IF dbms_lob.getLength(v_text) <= p_max_length THEN
        dbms_output.put_line(v_text);
    ELSE
        WHILE TRUE LOOP
            IF SUBSTR(v_text,1,1) = ' '
              AND p_replace_space != ' '
            THEN
--              v_tmp_text := REGEXP_REPLACE(v_text,'^ ',p_replace_space); --1)
                v_text := REGEXP_REPLACE(v_text,'^ ',p_replace_space); --2)
--              SELECT REGEXP_REPLACE(v_text,'^ ',p_replace_space) x INTO v_text FROM dual; --3)
            END IF;
            v_delimiter_found := FALSE;
            v_pos_Bis := INSTR(v_text,p_delimiter);
            IF v_pos_Bis = 0 THEN
                v_pos_Bis := INSTR(SUBSTR(v_text,1,p_max_length),' ',-1,1);
                IF v_pos_Bis = 0 THEN
                    v_pos_Bis := p_max_length;
                END IF;
            ELSE
                v_delimiter_found := TRUE;
            END IF;
            IF v_pos_Bis < dbms_lob.getLength(v_text) THEN
                IF v_delimiter_found THEN
                    dbms_output.put_line(SUBSTR(v_text,1,v_pos_Bis - LENGTH(p_delimiter) + 1)||'#');
                    v_text := SUBSTR( v_text, v_pos_Bis + LENGTH(p_delimiter));
                ELSE
                    dbms_output.put_line(SUBSTR(v_text,1,v_pos_Bis)||'#');
                    v_text := SUBSTR( v_text, v_pos_Bis + 1);
                END IF;
            ELSE
                dbms_output.put_line(v_text);
                EXIT;
            END IF;
        END LOOP;
    END IF;
    dbms_lob.freetemporary(v_text);
END pl;
/Now when I call my procedure with
EXEC pl('dflkjthcv  nkejrg  fcvnkuer  gfnckuhkjnchfkurbguzk',10);I expect the output
dflkjthcv #
.nkejrg  #
fcvnkuer  #
gfnckuhkjn#
chfkurbguz#
kBut I only get
dflkjthcv #If I uncomment the code line marked with 1) I get the correct output, though the result of this line is never used.
It also works when I use line 3) instead of 2) while 1) is commented out.
Any ideas why?
Regards
Marcus
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi
PL/SQL Release 10.2.0.2.0 - Production
CORE    10.2.0.2.0      Production
TNS for HPUX: Version 10.2.0.2.0 - Production
NLSRTL Version 10.2.0.2.0 - ProductionEdited by: Marwim on 08.01.2010 15:19 Replaced lt gt with !=

Works as you expect on 10.2.0.4
SQL >select * from v$version;
BANNER
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 Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL >CREATE OR REPLACE PROCEDURE pl
  2      (
  3       p_text                 IN CLOB
  4      ,p_max_length           IN PLS_INTEGER := 255
  5      ,p_delimiter            IN VARCHAR2 := CHR(10)
  6      ,p_replace_space        IN VARCHAR2 := '.'
  7      )
  8  IS
  9      v_pos_Bis               PLS_INTEGER;
10      v_text                  CLOB;
11      v_delimiter_found       BOOLEAN;
12      v_tmp_text              VARCHAR2(2000);
13  BEGIN
14      IF LENGTH(p_replace_space) != 1
15        OR p_replace_space IS NULL
16      THEN
17          RAISE_APPLICATION_ERROR(-20001,
18          'Parameter p_replace_space must have exactly one character');
19      END IF;
20  
21      dbms_lob.createTemporary(v_text, TRUE);
22      dbms_lob.copy(v_text,p_text,dbms_lob.getLength(p_text));
23  
24      IF dbms_lob.getLength(v_text) <= p_max_length THEN
25          dbms_output.put_line(v_text);
26      ELSE
27          WHILE TRUE LOOP
28  
29             IF SUBSTR(v_text,1,1) = ' '
30               AND p_replace_space != ' '
31             THEN
32  --          v_tmp_text := REGEXP_REPLACE(v_text,'^ ',p_replace_space); --1)
33              v_text := REGEXP_REPLACE(v_text,'^ ',p_replace_space); --2)
34  --          SELECT REGEXP_REPLACE(v_text,'^ ',p_replace_space) x INTO v_text FROM dual; --3)
35             END IF;
36  
37              v_delimiter_found := FALSE;
38              v_pos_Bis := INSTR(v_text,p_delimiter);
39  
40              IF v_pos_Bis = 0 THEN
41  
42                  v_pos_Bis := INSTR(SUBSTR(v_text,1,p_max_length),' ',-1,1);
43  
44                  IF v_pos_Bis = 0 THEN
45                      v_pos_Bis := p_max_length;
46                  END IF;
47  
48              ELSE
49                  v_delimiter_found := TRUE;
50              END IF;
51  
52              IF v_pos_Bis < dbms_lob.getLength(v_text) THEN
53  
54                  IF v_delimiter_found THEN
55                      dbms_output.put_line(SUBSTR(v_text,1,v_pos_Bis - LENGTH(p_delimiter) + 1)||'#');
56                      v_text := SUBSTR( v_text, v_pos_Bis + LENGTH(p_delimiter));
57                  ELSE
58                      dbms_output.put_line(SUBSTR(v_text,1,v_pos_Bis)||'#');
59                      v_text := SUBSTR( v_text, v_pos_Bis + 1);
60                  END IF;
61  
62              ELSE
63                  dbms_output.put_line(v_text);
64                  EXIT;
65              END IF;
66  
67          END LOOP;
68      END IF;
69      dbms_lob.freetemporary(v_text);
70  END pl;
71  /
Procedura creata.
SQL >EXEC pl('dflkjthcv  nkejrg  fcvnkuer  gfnckuhkjnchfkurbguzk',10);
dflkjthcv #
.nkejrg  #
fcvnkuer  #
gfnckuhkjn#
chfkurbguz#
k
Procedura PL/SQL completata correttamente.Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/01/07/creare-documenti-office-da-plsql/]

Similar Messages

  • Firefox will not open on my computer the majority of the time. If I shut down and restart it will work sometimes, but not always. This started recently in the last two weeks. Today is June 12th 2011.

    Firefox will not open on my computer the majority of the time. If I shut down and restart it will work sometimes, but not always. This started recently in the last two weeks. Today is June 12th 2011.

    See:
    * http://kb.mozillazine.org/Browser_will_not_start_up

  • My safari doesn't work sometimes, but I connect with the internet.

    my safari doesn't work sometimes, but I connect with the internet. Some of the videos I can't see with the Safari browser, but I can see it with other brower. But my friend can see these videos with her safari. And I can not connect with the app store sometimes.

    Before you try to configure the settings on your Router, first thing which you need to do is, Press and hold the reset button for 60 seconds...Release the reset button...Unplug the power cable from your router, wait for 60 seconds and re-connect the power cable...
    Connect the Modem to the Linksys Router on the Internet Port and then connect your computer to the Linksys router on the LAN Port 1. On your Computer click on Start - Run - CMD and click Ok... Now in the Command Prompt window type "ipconfig" and hit enter and note down the "IP address, Subnet Mask and Default Gateway" , Now again in the Command Prompt window type "ping default gateway IP" and hit enter and check if you are getting any replies, If yes then you can login to the setup page of the configure all the settings on it from scratch. 
    If your Internet Service Provider is Cable follow this link

  • Ichat 4.0 Sometimes works, sometimes doesn't

    Hello,
    I have asked many firewall questions on this forum before. At this stage, what seems to work are the appletest servers, both video and voice. But...I have many friends that have accounts that sometimes work, sometimes don't. With no changes whatsoever to the firewall or computers. These users that I try to contact run the gamut from aim on windows, to ichat on tiger, to ichat on leopard. And again, sometimes will work, sometimes not.
    I found an article on the web that states that multiple computers on your home network with the same user id's could cause this issue....Is that true? I have a 5 mac household, and the user id's are all the same. Now I'm only logged into ichat as me on my computer, so I'm not sure how that could happen.
    I have read the docs about ports to open, and I have opened them all, and then some, because I have found that sometimes ichat demands a port to be open that has nothing to do with those listed.
    Any clues?

    I have comcast as a service provider. They provide the modem. I have my own computer based router, running freebsd. I have full control over the firewall. I am running NAT inside the firewall. I have seen this behavior with both the firewall disabled, and with the ports I have opened. What is crazy is that while watching the security logs, when I test an account that doesn't work, I'll get a UDP deny on some arbitrary port that isn't supposed to be used by ichat.

  • I have an iphone 5 that i trade with a family member they have coverage on it. now the iphones sleep wake button doesnt work sometimes can apple replace my iphone even if i dont have the box or recipit to the product or can they just repair it?

    i have an iphone 5 that i traded with from a family member. its has coverage but now the sleep/wake button doesnt work sometimes. can apple replace my iphone and give me a new one or is it just something they can repair? i dont have the box or recipit to apple care or the iphone

    Apple can fix it without your receipt or box. They pull the serial number from the device and determine warranty status from that.  Hopefully ApplCare was registered to the product before you lost the receipt though.  If not, you can go back to the point of purchase and obtain your AppleCare receipt and Apple can help attach it to the iPhone.

  • My iTunes v.10.6.3.25 is intermittently refusing to open. Sometimes re-booting my laptop works, sometimes not. I just put the computer to sleep, and when I woke it up, iTunes started automatically. Any thoughts?

    My iTunes v.10.6.3.25 is intermittently refusing to open. Sometimes re-booting my laptop works, sometimes not. I just put the computer to sleep, and when I woke it up, iTunes started automatically (I had been trying to open it just before by clicking on a song file in my Documents window, and that's the song that started playing when the pc woke up). I went to my iTunes Help and clicked Updates/download iTunes 10.7 twice, but got nothing. Now, Im wondering if I should downloacd the entire 10.7, or whether that would overwrite all my files, erasing my songs. Anybody know? Thanks.

    Hey thanks for replying.
    Here's what I did:
    First I tried the Winsock reset in the Command prompt. Nothing changed.
    Next, I tried the instructions on http://http://support.apple.com/kb/TS4123. The only other program that came up on the 'Winsock Providers' tab on the program was 2 Windows Live applications, which I can do without. So I deleted all Windows Live Applications.
    I did the Winsock reset in the Command Prompt again and rebooted my comp.
    Unfortunately, nothing has changed. iTunes keeps freezing at various stages of the sync, then shows the candy cane-striped bar with either the words 'Finishing sync' or 'Cancelling sync', before showing the Apple logo.
    Sometimes, iTunes gets to the syncing stage - "Copying # of ####" - where it will trudge through the first, second and third tracks before flashing "Copying 4 of ####" for a split second and I catch "Cancelling sync" briefly before the Apple logo appears.
    Again, I've repeated the steps I mentioned in my previous post. Does ANYONE know when the new version of iTunes is set to be released?! This one is driving me INSANE, to say the least!!

  • I have the converter to change pdf to word. Works sometime, other time says conversion is taking too long. Can I get what it has translated so I can use the parts?

    I have the converter to change pdf to word. Works sometime, other time says conversion is taking too long. Can I get what it has translated so I can use the parts?

    I would ask in the ExportPDF forum, Adobe ExportPDF (read only) (assuming that's the service to which you have subscribed). This is the Reader one.

  • My iPhone 5 is experiencing problems with the Wifi at home. It shows that it is connected to the wifi but anything that uses wifi doesn't load. The wifi works sometimes however but this is rare. How do I fix this?

    My iPhone 5 is experiencing problems with the Wifi at home. It shows that it is connected to the wifi but anything that uses wifi (apps etc) doesn't load content and just looks like it's loading forever but nothing ever comes. However the wifi and wifi/internet dependant apps work sometimes but it's rare. How do I fix this?

    Back up all data.
    Unlock the Network preference pane, if necessary, by clicking the lock icon in the lower left corner and entering your password. Cllck Advanced, open the DNS tab, and change the server addresses to the following:
              8.8.8.8
              8.8.4.4
    That's Google DNS. Click OK, then Apply.
    In Safari, select
              Safari ▹ Preferences... ▹ Privacy ▹ Remove All Website Data
    and confirm. If you’re using another browser, empty the cache. Test. Any difference?
    Notes:
    1. If you lose Internet access after making the above change to your network settings, delete the Google servers in the  Network preference pane, then select the TCP/IP tab and click Renew DHCP Lease. That should restore the original DNS settings; otherwise restore them yourself. Remember that you must click Apply in order for any changes to take effect.
    2. I don't use Google DNS myself, though I have tested it, and I'm not recommending it or any other DNS provider; the server addresses are offered merely for testing purposes. There may be privacy and technical issues involved in using that service, which you should investigate personally before you decide whether to keep the settings. Other public DNS services exist.

  • Occasionally Firefox 3.6.12 won't display photos on certain sites. Reloading works sometime but not alwasys.

    At times on auction some sites such as ebay, (and others), photos won't display. If I press the reload button there's a chance the photo will display. If reload doesn't work the first time, pressing it 3 or 4 times may work but not always. Closing the site then re-opening works sometimes but not always. Annoying.

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • In Flex application functionality is working sometimes and not working sometimes..

    Hi,
    Please help me on this..
    In my flex application some functionality is working some times and not working sometimes..
    In my project i have 5 sections with 5 separate screens..Each screen is of one diffeent module.
    After logining into the application:
      I will go to one screen..First time every functionality is working in that screen..
    Ex:: I have a screen with datagrid.From that user will select one job name from datagrid click on next button..
    Based the job name the user selected i have to display some information in next screen and customer names.customer names is a combo box..
    below is the code:::
                   public function populateAllOEMCustomers(event:ResultEvent):void
              1)     var object_CustomerList:CustomerList = event.result as CustomerList; //Assigining result object values to Object reference variable.
              2)    var allOEMCustomersCollection:ArrayCollection = new ArrayCollection(); //Declaration ArrayColliction referance variable.
             3)       var i:int=0;
             4)      var customerComboLabel:Label = new Label();
              5)      for (i = 0;i < object_CustomerList.arryCollCustName.length; i++)
                        var strCustName:String = object_CustomerList.arryCollCustName.getItemAt(i).toString();
                        var strCustId:String = object_CustomerList.arryCollCustId.getItemAt(i).toString();
                        customerComboLabel = new Label(); //Dynamic declaration of label.
                        customerComboLabel.name = strCustName; //Assinging the customer name to the Label name field.
                        customerComboLabel.text = strCustId; //Assingning the customer id to the Label text field.
                        allOEMCustomersCollection.addItem(customerComboLabel); //Adding Lable into the ArrayCollection referace variable.                                       
                    //customerComboID.selectedItem = "--";   
                    OEMCustomersComboID.dataProvider = allOEMCustomersCollection;
                    OEMCustomersComboID.selectedItem = -1;
    This functionality is working fine when i visit to this screen first time..If you go back to another screen and come back to this same screen and click on next button this time customer names combo box has no customer details..I am getting Nullpointer Exception and it is showing the line number 5( i have given the number for code given above..)
    If i change the first line of the code to below code:: every time the above functionality is working fine.Not getting any error msg..
      var object_CustomerList:Object= event.result ;
    If i  type cast it to specific class(CustomerList) ,functionality is not working ..getting null pointer exception..If i type cast it to Object everything is working fine..In my code wherever i have typecasted it to specific class functionality is not working(gettingNullpointerExcepion).
    Please help me on this..I am not getting what could be the reason..
    I am using::Flex 3,Flash player 10.1
    Thanks in advance..
    Regards,
    Satya

    Hi Satya,
    This sometimes as in your case might not work as the way you have specified the RemoteClass attribute in your AS class. As somtimes there may be a case as before it is mapped to a server side you are returned the data and so that you may not get the data as your Custom class but as normal Object type.
    So in order to avoid this you can map the server side class to AS classes in the PreInitialize handler itself as shown below:
    Specify the preinitializeHandler in your main application and write the below function.This way also you can map AS classes with the server side. So that you will not have any problem referring your application as AS class types.
    You can use the same line for registering all the classes. By using this you can remove all the  [RemoteClass] attributes on all AS classes and include it at single place.
    preinitialize="onPreinitialize()"
    private function onPreinitialize():void
      registerClassAlias("com.expeditor.ScriptAdmin.Objects.CustomerList", CustomerList);
    Here in the above line of code the string in quotes refer to the namespace of the Server side class and the latter is your AS class. Also dont forget to import the namespace of the corresponding AS class in the file.
    Try this and let me know..
    Thanks,
    Bhasker

  • [kde]Gamin doesn't work sometimes.

    Hi all!
    I've read arch wiki and found, that gamin is lighter and better than fam.
    But after installing gamin dolphin do not show actual file system content. If I  move a folder it doesn't show it until manually refreshing (or by F5).  Sometimes it is working, sometimes no.
    I'm using KDE4.6. Do not remember about 4.5.
    Could anyone suggest the solution?
    Last edited by vit (2011-02-03 07:42:11)

    KDE should not need neither fam nor gamin. It directly uses kernel's inotify to monitor filesystem changes.

  • KYPE Account its not work sometimes

     me have really problem with my SKYPE Account  its not work sometimes. what about it?
    [Topic title updated by moderator to be more descriptive. Original topic title was: "Re: Не отображаются контакты."]

    It's a one year limited warranty, not a guarantee. You have 14 calendar days  from the time your items are delivered to initiate a return as noted here.
    Not all new Mac's have issues with Wi-Fi including mine running v10.9.4.
    Unless you state exactly which troubleshooting steps you have taken that didn't work, we have no way of knowing.
    Network preferences may be corrupted.
    Open the Finder. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following:
    /Library/Preferences/SystemConfiguration
    Click Go then move all the files in the SystemConfiguration folder to the Trash.
    See if that makes a difference.
    Your Mac will generate a new SystemConfiguration folder for you.
    If that doesn’t help, try here >  Wi-Fi: How to troubleshoot Wi-Fi connectivity

  • The cap lock key doesnt work sometimes, why? 13 pro(2013, late)

    The cap lock key doesnt work sometimes, why? 13 pro(2013, late)

    Hi, BOSCO_LIN. 
    Here is a helpful article that will walk you through troubleshooting the issue with your caps lock not responding.
    One or more keys on the keyboard do not respond
    http://support.apple.com/kb/ts1381
    Regards,
    Jason H.

  • Why does the plug in stop working sometimes

    Why does the plug in stop working sometimes?

    Is your pc. laptop, whatever Windows -ana what version, like Windows Vista, or Windows 10.
    What bit is it? 32 or 64?
    You can get that info by right clicking on "My Computer" Uusually on the desktop) and selecting Properties in the drop down menu.
    And what version of Fire Fox are you using?
    And which plugin are you using, and is it for Flash Player?
    This info will help someone to answer your question.

  • My Ringer only works sometimes with I message only

    My Ringer only works sometimes when using I message. The ringer works for all phone calls and emails.  I have tried everything, I even had the unit switched by my carrier and it's happening with the latest unit as well. I did not do the I tunes back and restore. I did a manual set up thinking the problem might carry over from the previous unit. Help!

    Had this happen today and 2X past as you discribed. A reboot (turn phone off and on) restored all sounds for me. The first time I can't associate w/ a cause but the second and third were just after listening to a podcast using the apple podcast app - the only app available for that. That's my story and for now I'm sticking to it.

Maybe you are looking for

  • Set Parameter ID F02...?

    Gurus, What does the parameter ID F02 signifies...? I had written a BDC program for parking and there were some user options settings that i took into consideration.one of the parameter id was F02... Can any of u educate me in this please... Thanks S

  • How to config. to schedule and email reports

    Hi, Please help me on these questions: 1. How to configure the reports server (or 9iAS or something else) to schedule reports, I also need to email the reports to customers in pdf and excel format, what should I do to achieve this? 2. I have to re_st

  • Retrieve the most recent history records from a history table

    I have a table which stores movement of applications or files. There could be any number of history records for any file in this table. I can know who has a given file right now by using max(date) and the unique id field using the query below: SELECT

  • Illustrator 17.0.2 Update for Mac not showing up in CC or AUM

    I have 17.0.0 and have not been presented with the update yet. Is this normal? Did Adobe pull it? Do they roll out updates only to specific configurations?

  • URGENT:Cash journal document could not reverse due to print already taken.

    Hi friends, its URGENT.... My client is facing a problem regarding Cash Journal Document Reversal The problem is: End user posted a transaction by FBCJ, Cash payments, in which an expense account is debited. He took the print also. Now he want to rev