How to create store procedure using cursor, and looping condition with exce

Hi,
I am new in pl/sql development , please help me for follwoing
1. I have select query by joining few tables which returns lets say 100 records.
2. I want to insert records into another table(lets say table name is tbl_sale).
3. If first record is inserted into tbl_sale,and for next record if value is same as first then update into tbl_sale else
insert new row
4. I want to achieve this using store procedure.
Please help me how to do looping,how to use cursor and all other necessary thing to achieve this.

DECLARE
   b   NUMBER;
BEGIN
   UPDATE tbl_sale
      SET a = b
    WHERE a = 1;
   IF SQL%ROWCOUNT = 0
   THEN
      INSERT INTO tbl_sale
                  (a
           VALUES (b
   END IF;
END;note : handle exceptions where ever needed
Regards,
friend
Edited by: most wanted!!!! on Mar 18, 2013 12:06 AM

Similar Messages

  • How to create a user using XML and specifying addional attributes that are objects

    I'm trying to create a user using XML and specifying some attributes that are objects and not sure how to do it. How would I set the DirectoryUserAcl to Public?
    Here's the xml file:
    <?xml version = '1.0' standalone = 'yes'?>
    <SimpleUser>
    <UserName>mike2</UserName>
    <Password>abc123</Password>
    <AdminEnabled>false</AdminEnabled>
    <HomeFolderRoot>/home</HomeFolderRoot>
    <HasContentQuota>false</HasContentQuota>
    <DirectoryUserAcl> ??? </DirectoryUserAcl>
    <DefaultAclBundleAcl> ??? </DefaultAclBundleAcl>
    <HomeFolderPolicyBundleAcl> ??? </HomeFolderPolicyBundleAcl>
    </SimpleUser>

    I figured out the answer:
    <?xml version = '1.0' standalone = 'yes'?>
    <SimpleUser>
    <UserName>mike2</UserName>
    <Password>abc123</Password>
    <AdminEnabled>false</AdminEnabled>
    <HomeFolderRoot>/home</HomeFolderRoot>
    <HasContentQuota>false</HasContentQuota>
    <DirectoryUserAcl classname="SystemAccessControlList" refType="name">Public</DirectoryUserAcl>
    </SimpleUser>
    null

  • How to creating pdf documents using c# and Adobe SDK

    I downloaded Adobe SDK and go through the samples given in sdk. But i couldn't find any sample code how to create PDF file using C# code.
    Please, help me with this.
    Thanks.

    For desktop-based solutions, look at the Adobe Acrobat SDK which enables development around Acrobat itself. Or if you wish a stand-alone solution (for either desktop or server), we offer the Adobe PDFLibrary, which is the same technology used by all of Adobe's applications.
    For the server, we have our LiveCycle products including LC Generator.
    Leonard

  • Report using cursors and loop

    Hi,
    can anybody suggest what kind of report and in what way I have to use if I want to write query using cursors within loops?
    Thanks!
    Karina.

    Hi,
    I found the solution. I just rewrite all cursors within one SQL statement and it works.
    Karina.

  • How to create a procedure using program unit

    Hai All
    Ii have created a procedure like this
    PROCEDURE Duty_calc
    IS
    procedure w_Time
    is
    begin
    update dail_att set wtime= (select lpad((to_number(to_char(outtime,'hh24mi')-to_char(intime,'hh24mi'))),4,0) from dail_att where attend_date=f_date);
    end w_time;
    begin
    if wtime >0830 then
    update dail_att set etime= (select lpad(wtime-0830) from dail_att where attend_date=f_date);
    else
         null;
    end if;
    duty_calc;
    end duty_calc;
    And i have declare in the program unit as Duty_calc and while i am executing my procedure i had an error
    is it must i need to declare a my inner procedure in my program unit
    Regards
    Srikkanth.M

    the same question you asked 2 month ago and same mistake you are doing
    - Procedure name can only be one.
    - Count proper BEGIN ENDs
    PROCEDURE Duty_calc
    IS
    BEGIN
    begin
    update dail_att set wtime= (select lpad((to_number(to_char(outtime,'hh24mi')-to_char(intime,'hh24mi'))),4,0) from dail_att where attend_date=f_date);
    end;
    begin
      if wtime >0830 then
      update dail_att set etime= (select lpad(wtime-0830) from dail_att where attend_date=f_date);
    else
      null;
    end if;
    end;
    END;

  • How to create an InputSelect using ADF and JSP

    I looking for some docs/instructions on creating "an InputSelect using ADF with JSP".
    Thanks,
    BG...

    Ok here are the Steps
    1) Open the JSP editor for the page in Question.
    2) In the Data Control palette select the item that you want to become the poplist and change the "Drop As" poplist to "Single Select List"
    3) Drag the field into the page. You'll get an empty poplist which implements the <html:select> and <html:optionsCollection> tags.
    4) With the JSP editor still open click on the "UI Model" sub-tab in the Structure pane
    5) Select the field you've just dragged in - then right click to get the context menu and choose "edit"
    6) Change the List Binding Mode poplist to "LOV Mode"
    You're then taken into a couple of screens where you can select the Source VO for the poplist, and the destination dataset, along with the thing you want for the Label and the Value.

  • Very Urgent..How to create a report Using SQ01 and Sq02.

    Hi Friends,
    It's very urgent.pl help  me in generating a report using SQ01 and SQ02.
    Help is appreciated.
    thanks In advance.
    Regards,
    Nanditha.

    Check out these links...
    http://www.insightcp.com/res_15.htm
    http://www.ams.utoronto.ca/Assets/output/assets/adhoc_2990830.pdf.pdf
    Also, do basic search in this forum...you will find a lot of threads related to this.
    SKR

  • How to create Store Procedure for export result select in .txt or .csv

    Hello,
    I'm using MSSQL Server.
    How to export results query  in .txt or .csv?
    But
    I can not use bcp or SQLCMD.

    1) linked server
    insert into txtsrv...table1#txt(CustomerNumber,CustomerName,EntryDate)
    select orderid, shipname, orderdate
    from Northwind..orders
    Set up the linked server
    Connecting a directory of text files as a linked server is easy.  Here’s how:
    In Windows, create a new directory for the linked server.  
    For this article, that directory will be E:\txtsvr. 
    Add that directory as a linked server with sp_addlinkedserver:
    EXEC sp_addlinkedserver txtsrv, 'Jet 4.0',
      'Microsoft.Jet.OLEDB.4.0', 'e:\txtsrv', NULL, 'Text' 
    That’s all that’s required to add the linked server txtsrv
     as a connection to the text files in E:\txtsvr, but there are
     no tables in txtsvr yet.  Also missing is a required file, schema.ini, 
    which must contain a description of each table’s format.  
    You can  learn more about schema.ini from the Microsoft MSDN Library,
     but for now, just use Notepad or your favorite text editor 
    to create the file e:\txtsrv\schema.ini as shown in Listing 1. 
     In addition, create an empty text file in e:\txtsrv named table1.txt.
    The file e:\txtsrv\table1.txt is now an empty table in the linked server txtsrv.  
    We can see that if we list information about all the tables in txtserv with 
    the system stored procedure sp_tables_ex:
    EXEC sp_addlinkedsrvlogin txtsrv, FALSE, Admin, NULL
    EXEC sp_tables_ex txtsrv
    Text files are tables
    We can’t issue a CREATE TABLE statement against this linked server, 
    but we have created a table easily enough.  We can, however, 
    run INSERT and SELECT queries, if we use the four-part naming 
    convention <server>…<table> (that’s three dots):
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to create stored procedure to drop and create table

    Version: Oracle 10g
    I am trying to create a stored procedure that will drop and create a table based on a select statement. I can create the table but I can't drop it.
    CREATE OR REPLACE procedure EC_LOAD is
    begin
    INSERT INTO Sales_table
    (FSCL_WK,
    DIV,
    ACCT_TYPE)
    Select
    FSCL_WK,
    DIV,
    ACCT_TYPE
    from
    sales_revenue;
    end ecload;
    I need to drop Sales_table before inserting the values. How do i do this?

    Or with a drop:
    SQL> desc emp2
    ERROR:
    ORA-04043: object emp2 does not exist
    SQL>
    SQL> declare
      2    cnt      int := 0;
      3  begin
      4    select max (1)
      5      into cnt
      6      from user_tables
      7     where table_name = 'EMP2';
      8
      9    if cnt = 1
    10    then
    11      execute immediate 'drop table emp2';
    12    end if;
    13
    14    execute immediate 'create table emp2 as select * from emp';
    15  end;
    16  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> desc emp2
    Name                                      Null?    Type
    EMPNO                                              NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO                                             NUMBER(2)
    SQL>

  • How to create parallel tasks using parallel for loops

    Hi,
    I am setting up a program that communicates with six logic controllers and has to read the system status every 100 ms. We are using OPC datasockets for this, and they appear a little slow. 
    I have created a uniform comm. method for all controllers, and now I find myself programming this method six times to communicate with each system. I am wondering if this could be done more elegant using the parallel for loop, in which case I would program an exchange once and then have six workers running simultaneously. Since a picture is more clear that a thousand words, what I am asking is this:
    Is it possible to replace something like
    by
    and have this for loop running these tasks in parallel (on different cores / in different threads)?
    I have configured the loop to create 8 instances at compile, so I would have 2 instances surplus available at runtime if I find I need an additional system.
    The benefits of the method show in the second picture to me are:
    * takes less space
    * modifications have to be made only once
    * less blocks, wires and stuff makes it more clear what's going on.
    * flexibility in the actual number of tasks running (8 instances available at runtime)
    * if more tasks are required, I need only to update the maximum number of instances and recompile, i.e. no cutting and pasting required. 
    Unfortunately, I don't have those system available yet, so there's no way to test this. Yet, I would like to know if the above works as I expect - unfortunately the labview help is not completely clear to me on this.
    Best regards,
    Frans 
    Solved!
    Go to Solution.

    Dear mfletcher,
    First of all: thanks for confirming that my intuition was right in this case.
    As for your question on the help: below is a copy/paste from the help on the 'configure parallelism dialog box' 
    Number of generated parallel loop instances—Determines the number of For Loop instances LabVIEW generates at compile time. The Number of generated parallel loop instances should equal the number of logical processors on which you expect the VI to execute. If you plan to distribute the VI to multiple computers, Number of generated parallel loop instances should equal the maximum number of logical processors you expect any of those computers to ever contain. Use the parallel instances terminal on the For Loop to specify how many of the generated instances to use at run time. If you wire a larger number to the parallel instances terminal than you specify in this dialog box, LabVIEW only executes as many loop instances as you specify here.The reason for me doubting if what I programmed would work the way I intended lies in the fact that the help only mentions processors here, which would be interpreted as actual cores. Thus on a dual core machine, the number should be 2.
    I think it would be helpful to mention something about threads here, because in some case one would like to have more parallel threads than there are cores in a system.
    In mu case I would like to create six threads, which on my dual core processor would be spread over only two cores. Then these six threads run in parallel.I know that in case of heavy math that would not help, but since I am doing communications, which have timeouts and such, and that probably runs smoother in six parallel tasks even though I only have two cores. 
    Hope this helps in improving the help of the for loop.
    Regards,
    Frans 

  • How to create a shared network drive and enforce it with password?

    Dear All,
    As stated, i would like to create shared network drive within my office to my department to share file and document. I would also like to have that network drive to be enforce by password protection. I would like this solution be native to Microsoft
    before i result to any 3rd party solution.
    I'm deeply grateful for anyone who can provide me with an solution or suggestion. :)
    Thanks so much,
    Regards,
    Aiphos Hoo

    Hi,
    If you're in a domain, then as S Guna siad, you should guarantee appropriate permissions to users.
    If you're not in a domain, then you can use "Password protected sharing", but this setting doesn't have effect on computers in a homegroup
    Control Panel\All Control Panel Items\Network and Sharing Center\Advanced sharing settings, All networks, turn on "Password protected sharing"
    http://windows.microsoft.com/en-us/windows/share-files-with-someone#1TC=windows-7
    Yolanda Zhu
    TechNet Community Support

  • How to create custom infotype for training and event management

    hai freinds can any one tell me how to create custom infotype for training and event managment with following fields
    PS No – PA0000-> PERNR
    Name   - PA0001 -> ENAME
    IS PS.No. – PA0001-> PS no. of Immediate Superior
    IS name PA0001 -> ENAME
    thanx in advance
    afzal

    Hi,
    Your question is not clear for me. Since it is a TEM infotype, it could be a PD infotype.
    If you wish to create a PD infotype, use transaction PPCI to create the infotype.
    But before that you need to create a structure HRInnnn (where nnnn is the infotype number) with all the fields relevant for the infotype.
    If you wish to create a PA infotype, use transaction PM01 to create the infotype.
    But before that you may be required to create a strcuture PSnnnn  (where nnnn is the infotype number) with all the fields relevant for the infotype.
    Regards,
    Srini

  • How to create a queue using CVP with ICM script(Comprehensive mode)

    Hello Guys,
    I would like to know how can I configure a queue in a comprehensive mode using micro-app at CVP + ICM environment. I work with UCCE at least 2 years, so I know how to create a queue using UCCX and/or IPIVR (I do a queue application using UCCX Editor and at ICM I use the Run external Script component), but at CVP I don't know how to create a application at Call Studio and how to call this application at ICM Script Editor to run this queue if there aren't agents available.
    Can someone help me to understand how can I do that?
    I attached the ICM Script using micro-app. This script runs ok, I call to a Route pattern and CVP route request ICM, so ICM run the script, but if there are no agents available the call drops, so I would like to know how can I create a queue to hold the call and to come back to a available agent.
    Regards,
    Eric Zapparoli
    Unified Communications
    Wittel

    Out of the check mark in the queue to skill group node you go to another run external script node, then you loop into that over and over again until the call is answered.
    david

  • How to create a procedure function with a return value of ref cursor?

    Can anybody provide a sample about how to create a procedure function with a return value of REF CURSOR?
    I heard if I can create a function to return a ref cursor, I can use VB to read its recordset.
    Thanks a lot.

    http://osi.oracle.com/~tkyte/ResultSets/index.html

  • How to pick max value from a column of a table using cursor and iteration

    Hello Everybody
    I have a table loan_detail
    and a column in it loan_amount
    now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
    here is my table
    LOAN_AMOUNT
    100
    200
    300
    400
    500
    5600
    700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
    Regards
    Peeyush

    SQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
    HIGHEST_SAL LOWEST_SAL
           5000        800
    SQL> set serverout on
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := counter;
    10      counter := counter + 1;
    11    END LOOP;
    12    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    13    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    14  END;
    15  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Even smaller
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := 1;
    10    END LOOP;
    11    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    12    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    13  END;
    14  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM

Maybe you are looking for