1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Help needed in writing a SP

Discussion in 'General' started by shwetainnani, Oct 28, 2009.

  1. shwetainnani

    shwetainnani Active Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    55
    Hi All,

    I am new to using oracle and want to write a SP which does the following

    If Ex_key is null and END DATE is not null and not of STDATE +1 and PST in (R or RR) then
    WT = CASH/SUM OF CASH for same Ex-Key
    MV = Ex_key MV * WEIGHT
    N = Ex_key N * WIEIGHT

    I am not sure how to get started with

    Main pointers I need on are as below

    how to write this SP.
    How to How to get the sum of cash for same Ex_key
    how to get the Ex_key MV and Ex_key N

    Please help as I have to deliver this end of this week and I do not know how to even start this.
     
  2. shwetainnani

    shwetainnani Active Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    55
    Hi All,

    I started this with getting the sum of CASh for the same Ex_key and I am stuck in this step only doesnt work

    select EX_KEY, SUM(CASH)
    FROM
    TT
    WHERE
    FID = 3
    GROUP BY EX_KEY

    Could you please advise.
     
  3. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,346
    Likes Received:
    347
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    You need a cursor for such constructs as PL/SQL is not the same as SQL*Plus:

    declare

    cursor get_key_sums is
    select EX_KEY, SUM(CASH)
    FROM
    TT
    WHERE
    FID = 3
    GROUP BY EX_KEY;

    begin

    for key_rec in get_key_sums loop
    ....


    This should get you started.