How to convert pl/sql block into single update statement

Dear all gurus,
I have pl/sql block mention below, Can I convert this pl/sql block to single update statement if possible?
If not how to optimize this block?
Pleaese suggest.
thanks in advance.
Vijay
DECLARE
CURSOR vt_mlr_cursor IS Select master_key, user4 from vt_mlr Where USER4 is not null;
USERFIELD VARCHAR2(100);
C1 VARCHAR2(3); /* this will return location of first space = 12 */
C2 VARCHAR2(3); /* this will return location of second space = 20 */
C3 VARCHAR2(3); /* this will return location of third space = 28 */
C4 VARCHAR2(3); /* this will return location of forth space = 35 */
Field1 VARCHAR2(40); /* this will return FTMYFLXA04W */
Field2 VARCHAR2(10); /* this will return VPI0043 */
Field3 VARCHAR2(10); /* this will return VCI0184 */
Field4 VARCHAR2(10); /* this will return 005 */
Field5 VARCHAR2(10); /* this will return 00001 */
Field_2_n_3 VARCHAR2(25);
key VARCHAR2(10);
BEGIN
FOR vt_mlr_record IN vt_mlr_cursor
LOOP
key := vt_mlr_record.master_key;
USERFIELD := vt_mlr_record.user4;
C1 := INSTR(vt_mlr_record.user4,' ',1,1); /* this will return location of first space = 12 */
C2 := INSTR(vt_mlr_record.user4,' ',1,2); /* this will return location of second space = 20 */
C3 := INSTR(vt_mlr_record.user4,' ',1,3); /* this will return location of third space = 28 */
C4 := INSTR(vt_mlr_record.user4,' ',1,4); /* this will return location of forth space = 35 */
Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1); /* this will return FTMYFLXA04W */
Field2 := SUBSTR(vt_mlr_record.user4,C1+4,C2-C1-4); /* this will return VPI0043 */
Field3 := SUBSTR(vt_mlr_record.user4,C2+4,C3-C2-4); /* this will return VCI0184 */
Field4 := SUBSTR(vt_mlr_record.user4,C3+4,C4-C3-4); /* this will return 005 */
Field5 := SUBSTR(vt_mlr_record.user4,C4+4,LENGTH(vt_mlr_record.user4)-C4-3); /* this will return 00001 */
Field_2_n_3 := Field2 || '/' || Field3;
/*DBMS_OUTPUT.PUT_LINE ('Current key is: ' || vt_mlr_record.master_key);*/
UPDATE vt_mlr
SET
aggregator_clli = Field1,
aggregator_vpi_vci = Field_2_n_3,
aggregator_slot = Field4,
aggregator_port = Field5
WHERE
master_key = vt_mlr_record.master_key;
END LOOP;
END;
/

Hi Vijay,
Here's something to start with, you should be able to complete it.
First, combine your select and update statements:
update vt_mlr
   set aggregator_clli = field1
      ,aggregator_vpi_vci = field_2_n_3
      ,aggregator_slot = field4
      ,aggregator_port = field5
where user4 is not null;Then put these two
C1 := INSTR(vt_mlr_record.user4,' ',1,1); 
Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1);into
Field1 := SUBSTR(vt_mlr_record.user4,1,INSTR(vt_mlr_record.user4,' ',1,1) -1);And put it into the update statement, removing reference to record
(I have also removed default values for position and occurrence in instr function):
update vt_mlr
   set aggregator_clli = substr(user4, 1, instr(user4,' ') - 1)
      ,aggregator_vpi_vci = field_2_n_3
      ,aggregator_slot = field4
      ,aggregator_port = field5
where user4 is not null; I think you can do the rest from here ;-)
Regards
Peter

Similar Messages

  • How to convert select-options table into single field internal table

    Hi,
    My requirement is to convert select-options table into single internal table which has one field.
    e.g. select-options: s_matnr for mara-matnr.
           select-options table can have options  'BT',"EQ", "NE", "GE", "GT", "LE", "LT", "CP" etc. select-options table
           have   Sign:I ,Option:BT, Low: 1, High.10.The new internal table records should be 1,2,3,4,5,6,7,8,9,10.
    Please suggest any function module available for this scenario in SAP.
    Thanks,
    Somi.
    Edited by: somi reddy satti on Sep 15, 2009 3:18 PM

    Hi Sowmya,
    Here is the answer if I understand well of your question.
    Data: begin of gt_mon OCCURS 0,
                  mon(2)             TYPE n,
             end of gt_mon.
    Data: begin of gt_year OCCURS 0,
                  year(4)             TYPE n,
             end of gt_year.
    Select-options: s_period       FOR ptdw_pws_db-kmonth NO-EXTENSION
                                                                                    DEFAULT sy-datum(6)
                                                                                    TO sy-datum(6).
    For example according to above statement period is 201110 is 201201.
    Period field does n't exists in SAP for selection. If your selection is on date based on period which is given on the selection-screen then you need to convert the period to date by concatenating ( or using FM to convert )01 at the end of each period . You need to declare one range table for date to select the data from table.
    loop at s_period.
    gr_date-sign   = s_period-sign.
    gr_date-option = s_period-option.
    COncatenate s_period-low
                          '01'
    into gr_date-high.
    COncatenate s_period-high                   
                           '01'
    into gr_date-low
    append gr_date.                      
    ENDloop.
    Thanks,
    Satheesh

  • How to convert pl/sql code into java/j2ee

    Hi,
    We have a PL/SQL Oracle App server application that we will support if we can convert in j2ee/java. But when i did take a look at the code, these pl/sql contains all HTML and java code inside the stored procedures.
    And iam looking to explore some tools and mechanisms that can convert these pl/sql in a JAVA application so that i can deploy this new app into my BEA81 environment.
    Does any body has any idea:
    a) How to convert from pl/sql > java ?
    b) Any plugins or tools of BEA that can run these pl/sql (the way thay are currently...i.e w/o converting) in BEA 81 container ?
    thanks, sangita

    these pl/sql contains all HTML and java code insideJava or JavaScript. They are not the same. I wouldn't expect to see Java inside html, whereas JavaScript would be intermixed. On the other hand you might have a java stored proc (Oracle 9/10) which is generating HTML.
    >
    Does any body has any idea:Refactor.
    I doubt it just has html and JavaScript/Java. So what you have is a mess that mixes several things that should have been seperate in the first place.

  • How to convert an sql query into a recordset?

    HI, I'm having a hard time building a locations of service form for users to insert, update the cities, counties, zip codes based on the states selected.
    so I found this  query that works great if I use basic  menus and text boxes, but can't use to make comma separated menus because it is nat a record set.
    The problem is that I have a table called zip_codes, with the following fields: state_label, Zip_b, county, city.
    zip codes correspond to the cities, counties and states.
    example:
    Colorado,  Colorado Springs, El Paso,  80918
    Users make a selection of state or states and the recordset is filtered by user selection.
    I manage the part of making a select mutiple drop menu that passes the values to my query page like this.
    <form action="litsTA.php"; method="post">
    <h3>Choose State(s)</h3>
    <p>hold Control key to select multiple states</p>
    <select  name="States_served[]_<?php echo $cnt1; ?>" multiple="multiple" onchange='showselection()'>
      <?php
    do { 
    ?>
      <option value="<?php echo $row_state['state_label']?>"><?php echo $row_state['state_label']?></option>
      <?php
    } while ($row_state = mysql_fetch_assoc($state));
      $rows = mysql_num_rows($state);
      if($rows > 0) {
          mysql_data_seek($state, 0);
           $row_state = mysql_fetch_assoc($state);
    ?>
    </select>
    <p>
      <input type="submit" value="submit" />
    </p>
    </form>
    And the query I need to convert into a recordset looks like this
      mysql_select_db($database_duitop, $duitop);
    $query_TONY = "SELECT * FROM zip_code WHERE state_label IN (";  
    for ($i=0; $i<=count($state_list)-1; $i++) {
    //echo $state_list[$i];
    $query_TONY = $query_TONY . "'" . $state_list[$i] . "'";
    if ($i < count($state_list)-1) {
    $query_TONY = $query_TONY . ", ";
    $query_TONY = $query_TONY . ") GROUP BY county ORDER BY state_label, city ASC";
    Any way that was my attempt to converting the query into a recordset.
    any help, or samples will be appreciated.

    Use Tcode SQ01.
    Give the query name press Enter.
    The query will be listed in the table below.
    Select the Query => From the Main menu select QUERY => More Functions => Display Report Name.
    You will get the program name, now go to Se38 and display the program...

  • How to Append two  word documents into single  using   java

    How to Append two word documents into single using java
    we tried this but it's not append the one word document to other
    source code:public class AppendTwoWordFiles {
         public static void main(String []arg)throws IOException
              FileInputStream fi=null;
              FileOutputStream fo=null;
              try {
                   System.out.println("Enter the source file name u want to append");
                   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                   File f1=new File(br.readLine().toString());
                   System.out.println("Enter the Destination file name ");
                   File f2=new File(br.readLine().toString());
                   fi = new FileInputStream(f1);
                   fo = new FileOutputStream(f2,true);
                   byte b[]=new byte[2];
                   while((fi.read(b))!=-1);
              fo.write(b);
    System.out.println("Successfully append the file");
              } catch (FileNotFoundException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              finally{
              fi.close();
              fo.close();
    plz reply me quickly ,,,what can i follow

    Use this code ..
    and give the path of the both file like this.....
    source file ---- C:/workspace/Practice/src/com/moksha/ws/test/practice.text
    destination file ---- C:/workspace/City/src/com/moksha/ws/test/practice1.text
    import java.io.*;
    public class AppendTwoWordFiles {
         public static void main(String[] arg) throws IOException {
              FileInputStream fi = null;
              FileOutputStream fo = null;
              try {
                   System.out.println("Enter the source file name u want to append");
                   BufferedReader br = new BufferedReader(new InputStreamReader(
                             System.in));
                   File f1 = new File(br.readLine().toString());
                   System.out.println("Enter the Destination file name ");
                   File f2 = new File(br.readLine().toString());
                   fi = new FileInputStream(f1);
                   fo = new FileOutputStream(f2, true);
                   byte b[] = new byte[2];
                   int len = 0;
                   while ((len = fi.read(b)) > 0) {
                        fo.write(b, 0, len);
                   System.out.println("Successfully append the file");
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
              } finally {
                   fi.close();
                   fo.close();
    }

  • How to convert data from rows into columns

    Hi,
    I have a sql table and the data looks like this
    GLYEAR GLMN01 GLMN02 GLMN03 GLMN04
    2007 -109712.40 6909.15 4758.72 56.88
    2007 -13411.32 19132.9 -5585.07 4362.64
    Where GLyear reprsents Year and GLMN01 is February, GLMN02 is March and so on,
    Now i want my output to be something like this which i want to insert into another table
    GLYear GLMonth GLAmount
    2007 February -109712.40
    2007 March 6909.15
    2007 April 56.88
    My new table has 3 columns, GLYear,GLMonth,GLAmount.
    Can someone please help me with the select statement on how to do this, i can work with the inserts.
    Thanks.

    I want you to check these form tread they have the same discussion as you.  They will definitely solve your problem
    http://blog.jontav.com/post/8344518585/convert-rows-to-columns-columns-to-rows-in-sql-server
    http://dba.stackexchange.com/questions/19057/convert-rows-to-columns-using-pivot-in-sql-server-when-columns-are-string-data
    http://stackoverflow.com/questions/18612326/how-to-convert-multiple-row-data-into-column-data-in-sql-server
    I hope this helps you in solving your problem. 
    Please remember to click “Mark as Answer” on the post that has answered your question as it is very relevant to other community members dealing with same problem in seeking the right answer

  • How to convert a PDF file into a full editable WORD file?

    Hi,
    I tried to convert a pdf file into word but it is not fully editable. I can edit the title from the main page and that's it. The rest of the word document is saved as image. I tried editing teh pdf file but that one is not working either.
    Please help on how to convert a PDF file into a full editable WORD file.
    Thank you

    Not all PDF files are created equal.  When a PDF file is created with Adobe Tools it is usually "tagged" with information about the fonts the images, the layout etc...    This way when the PDF is saved to a new format like PPT or DOC then the results are usually usable.  However, if you have a PDF file that was not tagged for some reason then run the Accessibility tools on the PDF to acquire some basic tagging.  This may get you a better result.  Also if you have a PDF that is an image, then you may want to run OCR on it.

  • How to convert my MM alias into an AppleID to use it with iCloud?

    I used MobileMe and created a mail that became my Apple ID. Then I created an alias that became my main e-mail so now with iCloud I wish that aslias could become my Apple ID. I don't care to loose the first Apple ID but "How to convert my MM alias into an AppleID to use it with iCloud?"

    You cannot convert an alias to Apple ID.
    You can transfer your MM to iCloud with your main Apple ID.
    There will be your alias as well.
    Regards

  • How to import an assignment block into a word document

    hi all,
              how to import an assignment block into a word document ,actually we an option called import to Excel,
            but i don't know make it for Word document.....
    Regards
    Sunil Kumar SA

    Use the Media Browser in Word, which you can access via the Ribbon (Insert -> Picture) or via the Insert menu.
    Regards
    TD

  • How to convert an int variable into String type

    hi everybody
    i want to know how to convert an interger variable into string variable
    i have to implement a code which goes like this
    Chioce ch;
    for(int i=0;i<32;i++)
    // here i need a code to convert the int variable i into a string variable
    ch.add(String variable);
    how do i convert that int variable i into a String type variable??
    can anyone help me?

    Different methods:
    int a;
    string s=a+"";or
    String.valueOf(int) is the better option because Int.toString() generated an intermediate object to get the endresult
    Ema

  • How to convert an NWDI project into a Local project?

    Hi Experts,
    Please tell me " how to convert an NWDI project into a Local project? "
    If you c

    Hi Srini
    1. Copy/Paste Webdynpro components in the new project as was suggested before
    2. Or create new project, copy _comp folder from old project to the new one. But, do not forget to update .dcdef & .project files manually after this. You have to set the correct project name in .dcdef and set the correct local project path in .project.
    BR, Sergei

  • How to Convert Oracle Apps Report into XML Publisher

    Hi
    How to Convert Oracle Apps Report into XML Publisher?
    Thanks

    In Brief :
    Re: XML Publisher
    In Details :
    http://www.oracle.com/technology/products/xml-publisher/docs/XMLEBSRep.pdf

  • 2.....how to convert normal function module into remote enabled function mo

    Hi...
    2.....how to convert normal function module into remote enabled function module?
    thanks and regards,
    k.swaminath.

    Hi,
    In the attributes tab select radio button as  remote enabled instead of normal..
    u can call the remote enabled fm as...
    CALL FUNCTION <Function module> destination <destination name>
    Regards,
    Nagaraj

  • I can't find this anywhere... how to convert mp3 (not music) into text without spending much $$$.

    i can't find this anywhere... how to convert mp3 (not music) into text without spending much $$$.

    function(){return A.apply(null,[this].concat($A(arguments)))}
    hope1hope2 wrote:
    i can't find this anywhere... how to convert mp3 (not music) into text without spending much $$$.
    It's very unlikely that you'l
    l find any help here; this forum is used only
    for testing purposes. Unfortunately, I cannot suggest
    another forum
    Extra line breaks kindly supplied by the software.

  • How to convert trailing minus sign into the leading minus sign

    Hi
    Can any plz tell me How to convert trailing minus sign into the leading minus sign? I mean in PI the amount filed shows like 150.00- i want to convert that into -150.00.
    Thanks
    Govinda

    Hi Shabarish,
    The code works but what if the input is something like [   10.000-] i.e. with some spaces before 10.000- and the output as per your code comes as [-     10.000]. How do we tackle such cases if there is inconsistency in data i.e. some values come as [    10.000-] i.e. spaces before the number and some values as [12.000-].
    The output of this will come as
    [-    10.000]
    [-12.000]
    How to make it as
    [-10.000]
    [-12.000]
    Regards,
    Shaibayan

Maybe you are looking for

  • SSRS 2012, SQL Server 2012. Problem with changing database

    Hi all! I have a problem with changing database for SSRS. I have a SSRS 2012 and SQL Server 2012. These programs is on WIndows Server 2012. I need to link SSRS to the new database instance. For this I run SSRS Configeration Manager, open tab Database

  • Software Inventory in 2012 very slow

    Hi, like many other people, I've noticed software inventory running much slower than in 2007. Various people have said its been assigned a lower priority, and also have given the opinion that its not a useful feature.. However, in my environment, I h

  • No PSA for Info Source

    HI All, We have the flow - Cube- C013 to DSO- 610 Cube- C016 to DSO- 610 For that we generated Export data source from CUbe- C013  to DSO-610 and Export data source from CUbe- C016  to DSO-610. As of now we followed the transport procedure from BI DE

  • Why wont you update iPod Touch 2g to iOS 5?!

    Apple, i have an iPod touch 2g and i was wondering hwhen you will EVER update the iPod touch 2g (or all the other generations) higher?

  • Opportunity Team Email Workflow

    Hi, I need to send an email as and when a new user is added to the oppty Team.I need to send an Email to the particular Member who is geting added.Kindly help me with how to select the Email address.I can use the Oppty Team object,trigger event as wh