Add a different character to the last line of a loop

Hi,
I'm attempting to use some pl/sql to generate an RMAN copy script. After each line there needs to be comma, but the last line of the loop should have a semi-colon to terminate the statement. How can I do that?
In the example below, the copy for controlfile 3 needs to be a semi-colon, not a comma:
run
SHUTDOWN IMMEDIATE
STARTUP MOUNT
COPY
DATAFILE 1 TO '/u20/oraflash/ORCL1/dbcopy/system01.dbf',
DATAFILE 2 TO '/u20/oraflash/ORCL1/dbcopy/undotbs01.dbf',
DATAFILE 3 TO '/u20/oraflash/ORCL1/dbcopy/drsys01.dbf',
DATAFILE 4 TO '/u20/oraflash/ORCL1/dbcopy/example01.dbf',
DATAFILE 5 TO '/u20/oraflash/ORCL1/dbcopy/indx01.dbf',
DATAFILE 6 TO '/u20/oraflash/ORCL1/dbcopy/tools01.dbf',
DATAFILE 7 TO '/u20/oraflash/ORCL1/dbcopy/users01.dbf',
DATAFILE 8 TO '/u20/oraflash/ORCL1/dbcopy/xdb01.dbf',
CURRENT CONTROLFILE TO '/u20/oraflash/ORCL1/dbcopy/control01.ctl',
CURRENT CONTROLFILE TO '/u20/oraflash/ORCL1/dbcopy/control02.ctl',
CURRENT CONTROLFILE TO '/u20/oraflash/ORCL1/dbcopy/control03.ctl',
ALTER DATABASE OPEN
My script is:
set serveroutput on format wrapped
set feedback off
spool db_copy.rcv
declare
cursor df is
select
file#,
substr(name,29,50) name
from
v$datafile;
cursor cf is
select
substr(name,27,50) name
from
v$controlfile;
BEGIN
DBMS_OUTPUT.ENABLE(2000);
DBMS_OUTPUT.PUT_LINE('run');
DBMS_OUTPUT.PUT_LINE('{');
DBMS_OUTPUT.PUT_LINE('SHUTDOWN IMMEDIATE');
DBMS_OUTPUT.PUT_LINE('STARTUP MOUNT');
DBMS_OUTPUT.PUT_LINE('COPY');
for dfbkup in df loop
dbms_output.put_line(' DATAFILE '||dfbkup.file#||
' TO ''' || '/u20/oraflash/ORCL1/dbcopy/' || dfbkup.name ||''',');
end loop;
for cfbkup in cf loop
dbms_output.put_line(' CURRENT CONTROLFILE' ||
' TO ''' || '/u20/oraflash/ORCL1/dbcopy/' || cfbkup.name ||''',');
end loop;
DBMS_OUTPUT.PUT_LINE(' ;');
DBMS_OUTPUT.PUT_LINE('ALTER DATABASE OPEN');
DBMS_OUTPUT.PUT_LINE('}');
end;
spool off

Hi
Try this then and remove any returns that I've put in as appropriate
DECLARE
l_string VARCHAR2(32767);
l_num NUMBER := 1;
CURSOR df IS
SELECT  file#, SUBSTR (name, 29, 50) name
FROM v$datafile;
CURSOR cf IS
SELECT   SUBSTR (name, 27, 50) name
FROM v$controlfile;
BEGIN
   l_string := ('run
   l_string := l_string||('{
   l_string := l_string||('SHUTDOWN IMMEDIATE
   l_string := l_string||('STARTUP MOUNT
   l_string := l_string||('COPY
   FOR dfbkup IN df
   LOOP
      l_string := l_string||(   ' DATAFILE '
                           || dfbkup.file#
                           || ' TO '''
                           || '/u20/oraflash/ORCL1/dbcopy/'
                           || dfbkup.name
                           || ''',
   END LOOP;
   FOR cfbkup IN cf
   LOOP
      l_string := l_string||(   ' CURRENT CONTROLFILE'
                           || ' TO '''
                           || '/u20/oraflash/ORCL1/dbcopy/'
                           || cfbkup.name
                           || ''',
   END LOOP;
   l_string := RTRIM(l_string,'
   l_string := l_string||(' ;
   l_string := l_string||('ALTER DATABASE OPEN
   l_string := l_string||('}');
WHILE l_num <= LENGTH(l_string) LOOP
DBMS_OUTPUT.PUT_LINE(SUBSTR(l_string, l_num, 200));
l_num := l_num + 200;
END LOOP;
END;Cheers
Ben

Similar Messages

  • Please add exit to the last line of the sql script

    Hi,
    I am executing a sql script from UNIX shell. When I execute it at the command prompt the script executes successfully, but when I schedule the script on cron, the script is throwing an error with the above message
    "Please add exit to the last line of the sql script"
    Any idea what is happening? Thanks in advance for any help
    thedba

    It works check this out..
    << script a.sh >>
    logfile=/home/oracle/sri/x.log
    sqlplus -s /nolog <<DOC >> ${logfile}
    whenever sqlerror exit sql.sqlcode
    connect scott/tiger
    @a.sql a.log
    DOC
    <<  script a.sql >>
    set feedback off
    set echo off
    spool &1
    select * from tab where tname like 'A%';
    spool off
    exit;
    << a.log >>
    TNAME                          TABTYPE  CLUSTERID                              
    AQ$DEF$_AQCALL                 VIEW                                            
    AQ$DEF$_AQERROR                VIEW                                            
    AQ$_DEF$_AQCALL_F              VIEW                                            
    AQ$_DEF$_AQERROR_F             VIEW                                            
    AQ$_INTERNET_AGENTS            TABLE                                           
    AQ$_INTERNET_AGENT_PRIVS       TABLE                                           
    AQ$_QUEUES                     TABLE                                           
    AQ$_QUEUE_TABLES               TABLE                                           
    AQ$_SCHEDULES                  TABLE                                           
    << x.log >>
    TNAME                          TABTYPE  CLUSTERID
    AQ$DEF$_AQCALL                 VIEW
    AQ$DEF$_AQERROR                VIEW
    AQ$_DEF$_AQCALL_F              VIEW
    AQ$_DEF$_AQERROR_F             VIEW
    AQ$_INTERNET_AGENTS            TABLE
    AQ$_INTERNET_AGENT_PRIVS       TABLE
    AQ$_QUEUES                     TABLE
    AQ$_QUEUE_TABLES               TABLE
    AQ$_SCHEDULES                  TABLE-Sri

  • JSP for Vcard cannot strip carriage return in the last line of the file.

    I am using JSP to output a Vcard (http://en.wikipedia.org/wiki/VCard)
    The following code works great in Windows but fails on the mac:
    <%@ page contentType="text/x-vcard" %><%--
    --%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%--
    --%><%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %><%--
    --%>BEGIN:VCARD
    VERSION:2.1
    <c:choose><%--
    --%><c:when test="${not ((empty param.lan) and (empty param.fin)) }"><%--
    --%>N:${param.lan};${param.fin}
    FN:${param.fin} ${param.lan}
    </c:when><%--
    --%><c:otherwise><%--
    --%>FN:${param.org}
    </c:otherwise><%--
    --%></c:choose><%--
    --%>ORG:${param.org}
    TITLE:${param.title}
    TEL;WORK;VOICE:${param.phwork}
    ADR;WORK:;;${param.st};${param.city};${param.state};${param.zip};
    EMAIL;PREF;INTERNET:${param.email}
    REV:20080424T195243Z
    <c:out value="${fn:replace('END:VCARD','\\\r','')}" escapeXml="false"/>After some tests, I discovered that Mac (I used Tiger, latest update, not Leopard) needs extra white space and carriage returns stripped off. Once this is achieved, the vcard will automatically import into Address Book. I have followed other forums which advice on using JSP comments as in the code above. But for some strange reason the last line of the JSP outputs an extra carraige return. How do I get rid of the carriage return at the end of the file? the replace function from JSTL is not working.
    Edited by: shogo2040 on Dec 18, 2008 7:11 PM : I added more detail to the Subject

    I originally had that END:VCARD without any carriage return.
    But I still get an extra carriage return at the end when the JSP renders to VCF
    I'm using Tomcat running on Linux.
    I found this, article which implies (but does not explicitly say) JSP in general adds a newline to the last line:
    http://www.caucho.com/resin-3.0/jsp/faq.xtp (But its not tomcat either, so maybe this info is irrelevant).
    Edited by: shogo2040 on Dec 22, 2008 3:31 PM - changed rendered to VCF from rendered to JSP

  • How can I get the size of all lines or the last line number in a DB?

    I want to display a certain number of lines from a DB.
    But before I fetch them out, I must know how many lines of this DB has.
    I donnot know if there is some methods have this function. I know the last() method can move the cursor to the last line, but some DB cannot support this function.
    Could someone know the answer or some examples about displaying data in a jsp?
    Thanks a lot.

    To get the number of rows in a ResultSet, loop over the result set with while(res.next()). Read each row into an object. Add each object into a, say, LinkedList. At the end, you will have the rows nicely converted to objects (which you probably should do anyway), and list.size() will give the number of objects.
    There are other ways to get the number of objects, but list.size() is the easy and reliable way. If you don't need the rows converted to objects ...why did you select them in the first place?
    Tricks with last() and whatnot sort of work. They read the entire result set into memory. But you'll need to write the while(res.next()) loop anyway. No point in having the computer do the same thing twice.

  • To delete the last line of the internal table

    How to delete the last line of the internal table.???????
    The list which gets displayed from the internal table adds a dummy line at the last which shows zeros and zeros.all the otheer selections are perfect.i just want to delete the last line which comes as zero zero.is there any way to do it...

    Quite Easy......Use Describe command to Count the Total Number of Table Lines, and then Delete the Last Line using Index.
    Data L like sy-tabix.
    Describe Table Itab Lines L.
    Delete itab index L.

  • How to set a JScrollPane always display the last line?

    I have put a JTextArea in a JScrollPane.
    Whenever I append a new line of sentence to the JTextArea, the JScrollPane only shorten the vertical scroll bar.
    Is there any command that can scroll down to the last line whenever I append a new sentence to the JTextArea?

    I have tried to add the line you shown, but it can just show the second last line. It cannot scroll down to the last line.
    e.g. I have these message:
    AAA
    BBB
    CCC
    If the message board can only show 3 lines and I enter one more line "DDD", then the last line will be shown is CCC. I need to scroll down a bit more myself to see DDD. If I scroll to the top and enter another line"EEE", it will scroll down to show "DDD" but not "EEE".

  • How to keep unaltered the last line?

    Hi I am doing some last corrections in a book which is going to be in the next days published and I am not allowed to change the form of the pages. (The indexes at the end of book are already done). Thus by correcting some footnotes (making them shorter) the main text above also changes (the first line of the next page appears in the page I corrected the footnotes) and I cannot keep the previous form of the pages. How can I keep the last line of the main text unaltered so that the pages turn exactly at the same point like before?

    If I am understanding your issue correctly, it seems that you are trying to keep the length of each page's main content  unaltered so that the index could refer back to the correct page.  It sounds like the content in each page's frames are linked, so that they flow continuously.  Adding a page break (or a frame break) may be what you're looking for.  You'll find it under Type > Insert Break Character.
    I hope this helps.  And good luck with your book!

  • [svn:bz-trunk] 18060: tomcat-users. xml had an invalid Unicode character in the last commit

    Revision: 18060
    Revision: 18060
    Author:   [email protected]
    Date:     2010-10-07 06:40:08 -0700 (Thu, 07 Oct 2010)
    Log Message:
    tomcat-users.xml had an invalid Unicode character in the last commit
    Modified Paths:
        blazeds/trunk/servers/apache-tomcat-6.0.29/conf/tomcat-users.xml

    Mugunthan
    Yes we have applied 11i.AZ.H.2. I am getting several errors still that we trying to resolve
    One of them is
    ===========>>>
    Uploading snapshot to central instance failed, with 3 different messages
    Error: An invalid status '-1' was passed to fnd_concurrent.set_completion_status. The valid statuses are: 'NORMAL', 'WARNING', 'ERROR'FND     at oracle.apps.az.r12.util.XmlTransmorpher.<init>(XmlTransmorpher.java:301)
         at oracle.apps.az.r12.extractor.cpserver.APIExtractor.insertGenericSelectionSet(APIExtractor.java:231)
    please assist.
    regards
    girish

  • Read to get the last line from a File

    Hi
    I am sending in a clarification , hoping that I get an efficient solution from the group, should somebody have come across this scenario and implemented.
    How to read or get the last line from a text file , which usually have a no of records, without actually reading or looping through all the lines
    I know there is some solution with the RandomAccessFile, but given there can be some encoding issues or so.
    Please let me know if somebody have implemented the same.
    Thanks n advance

    The character encoding could, indeed, be an issue especially with UTF-8. I think what I'd do is to create a byte array with the encoded, expected end of line sequence in it and work on the file in bytes. For example, seek to the last 100 bytes of the file, read those bytes and look for an EOL sequence backwards. If not found read the previous 100, 200, 400 bytes etc. until you do find an end of line. Then seek to after the EOL and read normally. Remember an EOL sequence might cross a boundary.
    UTF-8 would be a problem, especially with a unix format file because you might mistake part of a multi-byte sequence for '\n'. To be reliable on UTF-8 you'd need to go back three characters looking for sequence start markers (has the previous character got the top bit set, or the one before that the first two bits set, or the one before that the top three bits). Or you could just react to an encoding exception and try another position.

  • How to remove the last line input into a string indicator??

    I am currently working on a program where the user has the ability to create a profile for one of our lab machines to run.  When the user selects what parameters they would like, a string indicator shows the user the last input they set followed by a comma.  For example, if the user selects which profile they want, and the times they would like to set, the following string would be displayed:
    As you can see in the picture above, the profile is updated in the string indicator after every set button is hit.  In the event the user makes a mistake, I want them to have the ability to delete the last line that was added.
    This is the code I developed so far.  The string coming in and leaving is attached to a shift register so it continues to append to the indicator.  I tried in this case to count how many lines have been written in the string so far, and I built an array with the current string.  Using the delete from array.VI I indexed it to the number of lines that was created so that the last line is deleted.  I unfortunately had no luck.  Any suggestions?

    tbob wrote:
    Fonzie1104 wrote:
    Hey Tbob,
    That almost worked.  The only issue though is it leaves a null string in its place without moving everything after up one line.  Also, if i have a parameter repeating multiple times, it doenst seem to work.
    I'm confused.  If you are deleting the last line, how can there be anything after?  What do you mean by a parameter repeating multiple times?
    If you look at my example front panel, you will see that the last line is deleted.  Isn't this what you asked for?
    It's due to the fact that your constant doesn't have a comma in the last line. If you add that in, you should be able to reproduce his problem. This is just a guess though, I didn't actually test it to see.
    Message Edited by for(imstuck) on 06-08-2010 01:24 PM
    CLA, LabVIEW Versions 2010-2013

  • Read in the last line of a file

    Can I use the "Read from File " vi to read ionly the last line of the file? If so, how? Thanks in advance for the help
    [email protected]

    Reading the "last line" of a file implies that you are dealing with an humanly readable ASCII text file and there are special characters (/n or /r or a combination of the two) that signify line breaks.
    You can only start reading from a certain byte offset using file I/O. Unless all your lines are equal lenght, It is impossible to find the start of the last line without reading every character leading up to it in one way or another.
    So in the most general case, you would need to read the entire file and find the last linefeed.
    HOWEVER: Typically, lines are not infinitely long, so if you have an upper estimate of line lenght, you can read a slightly longer tail from the end of the file and find the last linefeed there. You can probably modify the VI I posted here for your purpose, just use an appropriate length. Message Edited by altenbach on 06-08-2005 10:42 AM
    LabVIEW Champion . Do more with less code and in less time .

  • How do I prevent Pages from pushing paragraphs to next page when they would otherwise begin on the last line of the previous page?

    I am writing papers for school which have strict page limits so I can't afford to be losing lines at the bottom of a page because Pages thinks it looks better to have a new paragraph start on the next page. It does this automatically and I have to go back and manually format to get the first line of the paragraph to start on the last line of the previous page. This then creates problems down the line when I am editing so I would really like to be able to turn the feature off.
    e.g. with Pages auto-formatting
    -----page 1-----
         Paragraph #1 blah blah
    blah blah blah
         Paragraph #2 blah blah
    blah blah blah
    -----page 2-----
         Paragraph #3 blah blah
    blah blah
    e.g. after manual formatting
    -----page 1-----
         Paragraph #1 blah blah
    blah blah blah
         Paragraph #2 blah blah
    blah blah blah
         Paragraph #3 blah blah
    -----page 2-----
    blah blah

    Change the keep with next rules in:
    Inspector > Text > More > Pagination & Break
    Peter

  • How to find out the Last line of a page in Smart forms

    Hi Experts,
    I need to find out the <b>last line of a page in smartforms</b>.
    I have <b>Heading in a text element</b> and its <b>text in another text element</b>.
    If the heading falls in the last line, its contents will be displayed in the next page. I want to print the heading  in the next page.
    Please advise on this issue.
    Thanks in advance,
    Viven

    You can put both the heading and contents in a Folder node and check the page protection checkbox of the Folder node.  This way both will be displayed on the same page always.

  • How to upload CSV file w/o ,, for the last line

    Hi Experts,
    As part of one interface uploading the csv file (4coulmns) manually using the TCODE: CSCA_FILE_COPY.
    After uploading when i see in the AL11 as it is csv file it is filling the , in each space.
    But my issue while running the interface (because of logic in it) checking for the hash total in the last line where (record count, hash total) only 2 items should come but because of manual upload adding the (record count, hash total, , ,) another two spaces.
    Where program not moving further becasue the it is alway comparing the amounts (1000.00 not matching with 1000.00, , ) it is not processing. In production files directly load in to unix server so no issues and i can't ask to change the program code...because iam not following the process. As part of testing i've to do manually only.
    Please suggest the workaround for this.
    Is it possible to change the contents directly in AL11 directly....then HOW ?
    or
    How to create a csv file w/o , , in the last line (may be it is not possible) ?
    Thanks for your replies in advance.
    Regards
    VVR

    I don't think you can edit from AL11, nor creating a CSV without those commas at the end because are created to state fields with empty value.
    You have 6 columns filled with values but for the last line you only fill the first four. It is expected to appear , , for the last 2 columns on the last line.
    I can only suggest keep doing it manually before uploading the CSV file... or... you are saying you can't change the program.
    How about upload all CSV files... then writing another program to get those files from AL11 and delete the spare commas at the end line?
    Cheers,
    Andres.

  • Final total cannot appear when the last line item reached the page end

    Hi All,
    My report included 2 pages. Problem is the final total cannot appear when the last line item reached the page end. (page 2)
    final total will appear on the middle of last page (page 3) when i comment (type    = 'BOTTOM').
    Below is the program.
      CALL FUNCTION 'OPEN_FORM'
        EXPORTING
          device   = 'PRINTER'
          dialog   = 'X'
          form     = 'ZBOTM_VOUCHER'
          language = sy-langu.
      sort itab by vblnr.
      LOOP AT itab INTO wa_itab.
        move wa_itab-vblnr to reguh-vblnr.
        move wa_itab-lifnr to reguh-lifnr.
        move wa_itab-rbetr to reguh-rbetr.
        reguh-rbetr = reguh-rbetr * -1.
        CALL FUNCTION 'WRITE_FORM'
          EXPORTING
            window  = 'MAIN'
            element = 'DETAIL'.
        t_rbetr = reguh-rbetr + t_rbetr.
        AT LAST.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              window = 'LINE'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TOTAL'.
              type    = 'BOTTOM'
              WINDOW  = 'MAIN'.
        ENDAT.
    Thanks.

    Hi,
    Where should I include the code for bottom?
    How to open text editor?
    Thanks.
    Edited by: Alice8 on Feb 7, 2011 9:09 AM

Maybe you are looking for