Create a procedure to return period and year value

Hi All,
I have a requirement to develop a procedure
which will accept any date and return the two values period, yr
as follows
if date is 1st oct 2011 then period should be 1 yr should be 2012
if date is 1st nov 2011 then period should be 2 yr should be 2012
if date is 1st dec 2011 then period should be 3 yr should be 2012
if date is 1st jan 2012 then period should be 4 yr should be 2012
if date is 1st feb 2012 then period should be 5 yr should be 2012
if date is 1st mar 2012 then period should be 6 yr should be 2012
if date is 1st apr 2012 then period should be 7 yr should be 2012
if date is 1st may 2012 then period should be 8 yr should be 2012
if date is 1st june 2012 then period should be 9 yr should be 2012
if date is 1st july 2012 then period should be 10 yr should be 2012
if date is 1st aug2012 then period should be 11 yr should be 2012
if date is 1st sept 2012 then period should be 12 yr should be 2012
if date is 1stoct 2012 then period should be 1 yr should be 2013
if date is 1st nov 2012 then period should be 2 yr should be 2013
if date is 1st dec 2012 then period should be 3 yr should be 2013
and so on
Please tell me how can i achive these through a plsql function
Thanks in anticipation.

CREATE OR REPLACE Function testdate
( INDATE IN DATE )
RETURN number
IS
PERIOD number;
YR NUMBER;
BEGIN
&INDATE
select
case
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Oct'
then '1'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy') FROM DUAL)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Nov'
then '2'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy') FROM DUAL)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Dec'
then '3'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy') FROM DUAL)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Jan'
then '4'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy') FROM DUAL)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Feb'
then '5' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Mar'
then '6' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Apr'
then '7' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='May'
then '8' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Jun'
then '9' AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Jul'
then '10'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Aug'
then '11'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
when TO_CHAR(TO_DATE(INDATE,'DD-MON-YYYY'),'MON')='Sep'
then '12'AND (SELECT to_char(add_months(to_date(INDATE),12),'yyyy')from dual)
ELSE NULL
end
into PERIOD
FROM DUAL;
RETURN PERIOD;
RETURN YR;
end TESTDATE;
EXCEPTION
WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('NO OUTPUT');
END;
**Mark a Person Correct or helpful if his answer is as such**
Edited by: Anshul Sharma on Feb 15, 2012 8:46 PM
Edited by: Anshul Sharma on Feb 21, 2012 12:47 AM

Similar Messages

  • Plsql function to return period and yr values

    Hi All,
    I have a requirement to develop a function
    which will accept any date and return the two values period, yr
    as follows
    if date is 1st oct 2011 then period should be 1 yr should be 2012
    if date is 1st nov 2011 then period should be 2 yr should be 2012
    if date is 1st dec 2011 then period should be 3 yr should be 2012
    if date is 1st jan 2012 then period should be 4 yr should be 2012
    if date is 1st feb 2012 then period should be 5 yr should be 2012
    if date is 1st mar 2012 then period should be 6 yr should be 2012
    if date is 1st apr 2012 then period should be 7 yr should be 2012
    if date is 1st may 2012 then period should be 8 yr should be 2012
    if date is 1st june 2012 then period should be 9 yr should be 2012
    if date is 1st july 2012 then period should be 10 yr should be 2012
    if date is 1st aug2012 then period should be 11 yr should be 2012
    if date is 1st sept 2012 then period should be 12 yr should be 2012
    if date is 1stoct 2012 then period should be 1 yr should be 2013
    if date is 1st nov 2012 then period should be 2 yr should be 2013
    if date is 1st dec 2012 then period should be 3 yr should be 2013
    and so on
    Please tell me how can i achive these through a plsql function
    Thanks in anticipation.

    Hi,
    This forum is for questions using SQL*Developer, not for general PL/SQL questions.
    It would be better to ask this question in the SQL and PL/SQL forum -
    PL/SQL
    Regards,
    Mike

  • Determining last date if period and year are given

    hi,
    what is the code if  the period and year are given and  to  print the  last date of that particular period and
    year.

    suppos period is perio = '2006002'
    Data sdate type sy-datum.
    Data edate type sy-datum.
    mm = perio+5(2).
    yy   = perio+0(4).
      concatenate yy mm '01' into sdate.
      call function 'SG_PS_GET_LAST_DAY_OF_MONTH'
        exporting
          day_in            = sdate
        importing
          last_day_of_month = edate.
    edate is your lst day of that period month.
    \[removed by moderator\]
    Regards
    Rajesh
    Edited by: Jan Stallkamp on Jul 21, 2008 2:35 PM

  • Accumulated values from rpsco up to specific period and year

    I am develping report with parameters: period and year.
    Then my programs need to accumulate values in table rpsco from the period 01 year 1800 and up to period and year in my selection.
    Any suggestions?

    Hi Prasad,
    This would be happening if you have put the user entry variable in the global filter of your query.
    As a result the complete data set is restrcted to get the data only for one month.
    Please use the variable for user entry month in a selection and not globally.
    -Vikram

  • TVARV - Dynamic Period and Year

    Hi,
    A standard FI report is executed weekly in batch job. The selection screen for the report has the following fields: Period and Year. We need the following:
    1) A report variant that takes the current period and current year
    2) A report variant that takes the previous period and current year
    I know that it is possible to have dynamic dates (Current / date calculations), but is it possible with period and year as well ina  variant?
    What do the variables in TVARV table "SAP_SCMA_PERIOD" and "SAP_SCMA_FISC_YEAR" do?
    Since this is a standard report, what could be the solution?
    Awaiting response.

    Hi Anuritha,
    Did you able to solve this problem. Basically I am also in the same situation, so it would be great help if you suggest me what needs to be done exactely !
    How did you manage the variants SAP_SCMA_FISC_YEAR & SAP_SCMA_PERIOD in TVARV table to work accordengly.
    Looking forward for your reply.
    --Thanks
    Pankaj

  • How to create logical columns for current period and prior period

    Hello all.
    Is there any way in obiee to create a new logica column in BMM layer that says "CURRENT PERIOD" AND "PRIOR PERIOD" OR ONE SINGLE COLUMN THAT SAYS "PERIOD".
    In those columns what I need is if it a current period column it shoould have 03/01/2012-03/31/2012 (this month date range)
    and in prior period column I shouldhave 02/01/2012 -02/29/2012(which is previous month date range).These columns I will be using in my reports.
    Please help me if we can create any such columns with these conditions/requirements

    Hi,I have already created he dynamic variables.But I am not getting how to use those variables and create the new logical columns in bmm layer.
    this is what I am trying
    case when VALUEOF("Current Month begin date"."Current Month begin date") ='..' and VALUEOF("Current Month end date"."Current Month end date")
    ='..' then 'current period' end
    I don't really understand what I should write case when VALUEOF("Current Month begin date"."Current Month begin date") ='..'??

  • FM to find the first & last date of month when we enter period and year

    Hi Gurus,
               I required an urgent need.
               I want a function module which gives me first and the last date of the month when I enter the period and the year.
               Reply me as soon as possible.
    Regards,
    Sagar

    Try this coding...  enter    02/2007 into the selection screen field and execute
    report zrich_0001 .
    data: start_date type sy-datum,
          end_date type sy-datum.
    parameters: p_spbup type spbup.
    start-of-selection.
      start_date = p_spbup.
      start_date+6(2) = '01'.
      call function 'LAST_DAY_OF_MONTHS'
           exporting
                day_in            = start_date
           importing
                last_day_of_month = end_date.
      write:/ start_date, end_date.
    Regards,
    Rich Heilman

  • Need to create a procedure whic h search and drop tables from the db.

    Dear Gurus,
    I need to create a procedure, which first checks the tables and then drop those tables if find in the database. For example, I have 5 tables, then my procedure should first checks the existence , then drop all those 5 tables from the database. Actually, I have to attach this procedure to report buildeer, so please keep in mind the above mentioned scenario. Your input will be highly appriciated.
    hare krishna
    Alok

    Dropping 5 tables each time user hits the report!!! (According to my understanding)
    I would like to share my experience. My group developed many complex reports, we used oracle jobs to run the complex queries time to time, according to our business requirements and stored the result in a final table. Just for viewing at front end level, we used a simple select statement.
    -aijaz

  • Calling Stored Procedure which returns single or multiple value

    Hi All Experts,
    I have written one stored procedure which is returning different
    integer values according to condition.I am calling this
    stored procedure through prepareCall() method then executeUpdate() method ,but it is always returning 1,not my desired value.
    Pl also tell me,if my stored procedure returns more than one value
    then how will i get those values in my java program?
    Pl help by writing some sample code.
    Thanx in Advance.
    Pradipto

    1) Create CallableStatement
    2) For each of returning value you have to call RegisterOutParameter()
    3) For others user setXXX() method depending on type of parameter
    4) call
    5) use vars registered through RegisterOutParameter() - all your values should be there
    Pavel

  • Srvrmgr syntax: how can I create Named Subsystem with both Name and Description values?

    In looking through bookshelf, there is no syntax discussed that allows you to include both the Name value and the Description value for a Named Subsystem/Profile Configuration.  In the screenshot, the circled values were created with the server manager command-line.
    In contrast, you can create a component definition with a Name (full name) and Description.
    For CompDef, this works:
    create component definition CompDefTest1_enu for component type AppObjMgr component group Fins run mode Interactive full name "Test Comp Def Test 1" description "Test 1 Object Manager CompDef"
    For Named Subsytem, this does NOT work:
    create named subsystem Test5 for subsystem EAITransportDataHandlingSubsys full name "Test 5" description 'Test 5 Description'
    Can anyone tell me if, for a Named Subsytem, there is a proper syntax to include both the Name and Description values in the command-line, or is the only way to manually create it in the UI?

    Hi,
    I have reviewed the help for create command in srvrmgr, it does not give the full name and description as parameters for subsystem creation. However, as you indicated these parameters are available for component definition creation:
    srvrmgr> help create
      create { component group | compgrp } <component group name>
           [ full name <descriptive name> ]
           [ { description | desc } <description of component group> ]
      create { component definition | compdef } <component definition name>
           for { component type | comptype } <component type name>
               { component group | compgrp } <component group name>
           run mode { batch | interactive | background }
           [ full name <descriptive name> ]
           [ { description | desc } <description of component definition> ]
           [ with [param <param_name>=<value>[, <param_name>=<value>...]]
                  [fixparam <fixed_param_name>=<fixed_value>[,...]]]
      create named subsystem <named_subsystem_name> for
           subsystem <subsystem_name> with <param_name>=<param_value> [, ..]
    Bookshelf also has an example of subsystem creation that does not include full name and description:
    http://docs.oracle.com/cd/E14004_01/books/StoreFwdMsg/StoreFwdMsg_InstallConfig14.html#wp1351472
    In this case I suggest you to create a ticket on My Oracle Support to confirm that srvrmgr does not support creating a new subsystem with full name and description parameters, and request an enhancement request for these parameters to be included in create statement for new subsystems when using srvrmgr.
    Hope it helps,
    WSiebel

  • How to create one procedure which can drop and create materialized view

    Hi,
    I want to create one pl/sql procedure which can first drop materialized view CATEGORY_PK and after that create same materialized view CATEGORY_PK.
    programme is as follows:
    DROP MATERIALIZED VIEW CATEGORY_PK;
    CREATE MATERIALIZED VIEW CATEGORY_PK REFRESH FORCE WITH PRIMARY KEY AS
    SELECT cav1.ownerid AS categoryid, p.uuid AS productid ,p.domainID AS productdomainid,pav.stringvalue AS NAME
         ,pav2.stringvalue AS ID, pav3.stringvalue AS SHORT
    FROM product p, product_av pav, catalogcategory_av cav1, catalogcategory_av cav2,product_av pav2,product_av pav3
    WHERE
    cav1.NAME = 'PRODUCT_BINDING_ATTRIBUTE' AND
    cav2.NAME = 'PRODUCT_BINDING_VALUE' AND
    cav1.ownerid = cav2.ownerid AND
    p.uuid = pav.ownerid AND
              p.uuid = pav2.ownerid AND
              p.uuid = pav3.ownerid AND
    pav.NAME = cav1.stringvalue AND
              pav2.NAME = cav1.stringvalue AND
              pav2.NAME = cav1.stringvalue AND
    pav.stringvalue = cav2.stringvalue AND
              pav2.stringvalue = cav2.stringvalue AND
              pav3.stringvalue = cav2.stringvalue
    UNION
    SELECT catalogcategoryid AS categoryid, productid, repdomainid AS productdomainid,pav1.stringvalue AS NAME
         ,pav2.stringvalue AS ID, pav3.stringvalue AS SHORT
    FROM productcategoryassignment ,product_av pav1,product_av pav2,product_av pav3
         WHERE pav1.ownerid=productid
         AND pav2.ownerid=productid
         AND pav3.ownerid=productid
         AND pav1.NAME='name'
         AND pav2.NAME='productID'
         AND pav3.NAME='shortDescription';

    user498566 wrote:
    I want to create one pl/sql procedure which can first drop materialized view CATEGORY_PK and after that create same materialized view CATEGORY_PK.That sounds like a waste of time and resources. What do you hope to achieve by this? A refresh? If so, a simple refresh of the old materialized view will do.
    If you truly want to continue this road, you'll have to use the EXECUTE IMMEDIATE command to execute DDL commands from within PL/SQL.
    Regards,
    Rob.

  • How to create stored procedure for insert update and delete operations with input output paramters?

    I  have the follwing table is called master table contain the follwing fields,
    So here i need to create  three Stored procedures 
    1.Insert operations(1 o/p paramter,and  14 input paramters)              - uspInsert
    2.Update operations(1 o/p paramter,and  14 input paramters)          - uspUpdate
    3.Delete Operations(1 o/p paramter,and  14 input paramters)          
     - uspdelte
    The following is the table ,so using this to make the three sp's ,Here we will use Exception machanism also.
    Location 
    Client Name
    Owner 
    ConfigItemID
    ConfigItemName
    DeploymentID
    IncidentID
    Package Name
    Scope 
    Stage
    Type 
    Start Date
    End Date
    Accountable 
    Comments
    So can u pls help me out for this ,bcz i knew to stored procedure's creation.

    I  have the follwing table is called master table contain the follwing fields,
    So here i need to create  three Stored procedures 
    1.Insert operations(1 o/p paramter,and  14 input paramters)              - uspInsert
    2.Update operations(1 o/p paramter,and  14 input paramters)          - uspUpdate
    3.Delete Operations(1 o/p paramter,and  14 input paramters)            - uspdelte
    The following is the table ,so using this to make the three sp's ,Here we will use Exception machanism also.
    Location 
    Client Name
    Owner 
    ConfigItemID
    ConfigItemName
    DeploymentID
    IncidentID
    Package Name
    Scope 
    Stage
    Type 
    Start Date
    End Date
    Accountable 
    Comments
    So can u pls help me out for this ,bcz i knew to stored procedure's creation.
    Why you have to pass 14 parameters for DELETE and UPDATE? Do you have any Primary Key?  If you do NOT have primary key in your table then in case you have duplicate information, SQL will update both or delete them together. You need to provide DDL of
    you table. What are the data types of fields?
    Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered.

  • How to get the same period last year value using Fiscal Calendar?

    Hi there,
    I am using DAX in a Tabular Model project but I am getting stuck trying to get the following:
    We are using a Fiscal Calendar (from 01 April to 31 March). 
    Previous Period Value
           Value
    2012
    April
    15
    May
    10
    Jun
    20
    2013
    April
    15
    30
    May
    10
    20
    Jun
    20
    25
    I have tried to use sameperiodlastyear but there is an error saying that this function cannot be used for non contiguous dates. DATEADD is given the same error...
    Could anyone help me getting the right measure expressions for [Previous Period Value]?
    Thanks and best regards,
    Joss

    Hi Joss,
    In SQL Server Analysis Services, we can can compare revenue with the hierarchy periods (year, month, day) by using the PARALLELPERIOD function, and now you want to compare with custom periods. (NOTE: We cannot compare it with the PARALLELPERIOD function
    since
    PARALLELPERIOD function returns a member from a prior period in the same relative position as a specified member. So if the first time span not equal to the second one (such as the first period is 3 days, and the second period is 2 month)).  Here
    is a sample query about PARALLELPERIOD function for your reference.
    with
    set Hotels as
    [Hotels].[Hotel ID].&[1015],
    [Hotels].[Hotel ID].&[5640],
    [Hotels].[Hotel ID].&[8800]
    set Period as [Arrival Date].[Date].[Month].&[2012]&[1]:[Arrival Date].[Date].[Month].&[2012]&[12]
    member [Arrival Date].[Date].[0] as sum({ Period })
    member [Total Amount N-1] as (PARALLELPERIOD([Arrival Date].[Date].[Year], 1, [Arrival Date].[Date].[Year].&[2012]), [Measures].[Total Amount])
    select
    [Measures].[Total Amount],
    [Measures].[Total Amount N-1]
    } on 0,
    nonemptycrossjoin
    Hotels,
    Hotels.[Hotel].children,
    *{[Arrival Date].[Date].[0]}
    } on 1
    from [Booking_Cube]
    Regards,
    Charlie Liao
    TechNet Community Support

  • Creating a popup to return more than one value

    Hi
    I am trying to create a POPUP item on my page.
    I have created a List of Values with the following queries
    select NAME d, ID r from EMPLOYEE order by 1
    The page displays a text box with a popup icon adjacent to it.
    On clicking the popup icon the popup window displays the name of all the employess in order, on choosing the employee the Id of the employee gets populated into the text box; I would like the name to be displayed on the text box.
    I also would like to have the employee name to be available in the page. Is this possible?
    The current popup is similar to the select list. I would like to obtain both the values from my popup window i.e the employee name and employee id into my page. So that I can display the employee name to the user but while submitting the page i can pass the employee id.
    Can you give me some suggesstions as to how to achieve this.
    Thanks.
    Message was edited by:
    KART

    Hmm, can't think it's going to be possible to pass back two values from a standard popup. One option:
    Use a standard popup and set its SQL to something like:
    SELECT employee d, (employee || ' ( ' || id || ')') r FROM employee;
    This will populate your item with something like: Smith (0122345)
    Assuming the item with the popup is called :P1_MYITEM, you could then reference the ID of the employee in a PL/SQL process when the page is submitted, something like:
    emp_id := substr(:P1_MYITEM,instr(:P1_MYITEM,'(')+1,instr(:P1_MYITEM,')')-instr(:P1_MYITEM,'(')-1)
    Or you could use the same kind of code in a computation to set a hidden item to contain the employee's ID.
    It's not ideal but might do the trick depending exactly how rigid your requirements are.
    Andy

  • Create a Procedure that will accept a variable

    Hi,
    I'm new to pl/sql and I'm trying to create a procedure that will accept a variable. I want to use this sql to create restore points that can store the name of each batch job as it runs.
    The code works fine on it's own, but if I try to create the procedure it asks me for a value for 1, how do I stop it doing that?
    CREATE OR REPLACE PROCEDURE create_restore_point AS
    DECLARE
    pointno number(5);
    pointname varchar2(128) := upper('&1');
    dbname v$database.name%TYPE;
    scn_time date;
    scn number;
    BEGIN
    SELECT restore_point_seq.nextval into pointno from dual;
    SELECT name into dbname from v$database;
    SELECT sysdate into scn_time from dual;
    SELECT dbms_flashback.get_system_change_number into scn from dual;
    INSERT into restore_point
    values
    (pointno,pointname,dbname,scn_time,scn);
    commit;
    END create_restore_point;
    Many thanks in advance,
    Tom.

    It asks for value of 1 because you have &1 in your code. If you want to pass the value for pointname, then you can change your procedure like below.
    CREATE OR REPLACE PROCEDURE create_restore_point (svar varchar2)AS
    DECLARE
    pointno number(5);
    pointname varchar2(128) := upper(svar);
    dbname v$database.name%TYPE;
    scn_time date;
    scn number;
    BEGIN
    SELECT restore_point_seq.nextval into pointno from dual;
    SELECT name into dbname from v$database;
    SELECT sysdate into scn_time from dual;
    SELECT dbms_flashback.get_system_change_number into scn from dual;
    INSERT into restore_point
    values
    (pointno,pointname,dbname,scn_time,scn);
    commit;
    END create_restore_point;

Maybe you are looking for

  • NULL and Unspecified in Dashboard prompts after upgrading 10g to 11g OBIEE

    Hi All, We are working on OBI upgradation project from 10g to 11.1.1.6.5. We are facing one issue in Dashboard prompt level. If we can create Dashboard prompt on a column, its giving "NULL", "Unspecified" additionally. But, in 10g there are no extra

  • OOS b-channel

    On my syslog I notice this kind of error on E1 b-channel: %CCM_CALLMANAGER-CALLMANAGER 3-BChannelOOS I also notice that: - I have an OOS b-channel from Real Time Monitoring Tool. - if I disconnect the E1 cable from the router and then I connect the c

  • Returning of material by 122 and via delivery component in migo

    I read a post in which return delivery has been discussed through. But in my business the return delivery is done delivery component and sent back to the vendor via a challan. Also tell me how to get back the payment from the vendor. Presently we are

  • Lock Entries - How to unlock

    Hi Gurus, I have an ID locking the Interactive Planning --> Demand Planning Area, this is not showing up in SM12, but showing up from the menu --> Edit --> Lock Entries. What do I do to unlock these? Thanks JS

  • Missing app store icon

    Hello, I am missing my app store icon on my IMAC, I looked all over under application, I don't see it. How do I get it back? Thanks!