How to Schedully running PL/SQL?

Hi everyone,
i'm a novice in pl/sql, i'm still learning on the script. I have a database which storing the inventory for waste product. I need to keep track the new waste and update the balance everyday exactly at 11pm. My problem is sometimes the job will fail and i need to recover the database manually.
1) how to make it automatically schedule run the pl/sql script without enter which date need to recover.
2) how to calculate the waste which receive on particular date.
Thanks.
here is my table attributes:
1)ID
2)wasteID
3)receive
4)ship_out
5)opening
6)date
7)waste_type
8)groupID
9)wasteName
Jeat.
Edited by: user11182731 on May 25, 2009 10:22 PM

Justin Cave wrote:
Yes, you can use DBMS_JOB.SUBMIT to submit a job that will call a particular stored procedure on a particular schedule, i.e. call Inventory_Recovery every day at a particular time.
Hi Justin, where to place the rdbms_job.submit code? Since i didn't have any stored procedure
How to create a stored procedure? Any reference??
It seems like you should be able to perform whatever computations you need in a view rather than trying to maintain a summary table that just aggregates your data.
Yeah, i do have a procedure for calculate the waste inventory balance which is corresponded to the procedure inventory_recovery, here the eg code:
PROCEDURE Inventory_Calculation (dInDate DATE, vInsertFlag VARCHAR2) IS
     rDayBeforeInvRec      Wste_Waste_Inventory%ROWTYPE;
     rInDateInvRec      Wste_Waste_Inventory%ROWTYPE;
     fInDateReceiveQty      FLOAT;
     fInDateShipoutQty      FLOAT;
     fInDateOnHandQty       FLOAT;
     fInDateOpeningQty      FLOAT;
     nComponentId     NUMBER(25);
     vCompDept     VARCHAR2(20);
     vCompName     VARCHAR2(80);
     vWasteType     VARCHAR2(2);
     nGroupId                     NUMBER(25);
     vComponentName     VARCHAR2(80);
     CURSOR Day_Before_Fail_Inv_Bal IS
          SELECT * FROM wste_waste_inventory
               WHERE wwin_date = dInDate -1;
          CURSOR InDate_Rec_Exist IS
               SELECT * FROM wste_waste_inventory
               WHERE wwin_date = dInDate
               AND wwin_wwco_id = nComponentId
               AND wwin_comp_dept = vCompDept
               AND wwin_waste_type = vWasteType
               AND wwin_wwgr_id = nGroupId
               AND wwin_component_name = vComponentName;
     BEGIN
          OPEN Day_Before_Fail_Inv_Bal;
               LOOP
                        FETCH Day_Before_Fail_Inv_Bal INTO rDayBeforeInvRec;
               nComponentId     := rDayBeforeInvRec.wwin_wwco_id;
               vCompDept     := rDayBeforeInvRec.wwin_comp_dept;
               vCompName     := rDayBeforeInvRec.wwin_comp_name;
               vWasteType     := rDayBeforeInvRec.wwin_waste_type;
               nGroupId        := rDayBeforeInvRec.wwin_wwgr_id;
               vComponentName     := rDayBeforeInvRec.wwin_component_name;
               OPEN InDate_Rec_Exist;
                        FETCH InDate_Rec_Exist INTO rInDateInvRec;
               IF InDate_Rec_Exist%FOUND THEN
               fInDateOpeningQty      := rDayBeforeInvRec.wwin_onhand;
                         fInDateOnHandQty      := rDayBeforeInvRec.wwin_onhand - rInDateInvRec.wwin_ship_out + rInDateInvRec.wwin_receive;
                       UPDATE wste_waste_inventory SET
                    WWIN_OPENING = fInDateOpeningQty,
                    WWIN_ONHAND  = fInDateOnHandQty                              
                    WHERE wwin_date = dInDate
                    AND wwin_wwco_id = nComponentId
                    AND wwin_comp_dept = vCompDept
                    AND wwin_waste_type = vWasteType
                    AND wwin_wwgr_id = nGroupId
                    AND wwin_component_name = vComponentName;                              
               ELSE          
                    fInDateOpeningQty      := rDayBeforeInvRec.wwin_onhand;
                    fInDateOnHandQty      := rDayBeforeInvRec.wwin_onhand;
                    INSERT INTO wste_waste_inventory (
                         WWIN_ID,
                         WWIN_WWCO_ID,
                         WWIN_RECEIVE,
                         WWIN_SHIP_OUT,
                         WWIN_ONHAND,
                         WWIN_OPENING,
                         WWIN_DATE,
                         WWIN_COMP_DEPT,
                         WWIN_COMP_NAME,
                         WWIN_WASTE_TYPE,
                         WWIN_WWGR_ID,
                         WWIN_COMPONENT_NAME )
                    VALUES (
                         SAPP_SEQ.nextval,
                         nComponentId,
                         0,
                         0,
                         fInDateOpeningQty,
                         fInDateOnHandQty,
                         TO_DATE(dInDate, 'DD-MON-YY'),
                         vCompDept,
                         vCompName,
                         vWasteType,
                         nGroupId,
                         vComponentName );     
                    END IF;               
                               CLOSE InDate_Rec_Exist;
                    EXIT WHEN Day_Before_Fail_Inv_Bal%NOTFOUND;
               END LOOP;
          CLOSE Day_Before_Fail_Inv_Bal;
     COMMIT;          
END Inventory_Calculation;

Similar Messages

  • How Can I Run a SQL Loader Job from Schedular

    How Can I Run a SQL Loader Job from Schedular , So that It Runs every Day.

    Depends on a couple of factors.
    If you are on a UNIX platform, you can create a shell script and schedule it with cron.
    If you are on a Windows platform, you can create a batch file and schedule it with the Windows scheduler.
    Or, if you are on Oracle 9i or 10g, you could use the external table feature instead of SQL*Loader. Then you could write a stored procedure to process the external table and schedule it using the Oracle scheduler (DBMS_JOB). This would probably be my preference.

  • How can I run a SQL script file...

    How can I run a SQL script file from a location on my computer without providing the whole path?
    Is there some way I can set a "Working folder" in SQL Plus??
    Thanks!
    Tom

    You can create an environment variable called "SQLPATH" which is a list of directories that SQL*Plus will search for your .SQL
    scripts.
    I would like to use another directory than the oracle/bin...
    How can I do this ??
    Hello,
    U can do this by this way:
    Save odm_script.sql file to the default Oracle
    directory i.e. Oracle-Home/bin and Run following command
    through SQL Plus.
    SQL>@Script_Name
    I hope this will resolve ur problem.
    Regards,
    Omer Saeed Khan.

  • How can i run Following SQL Server Script in to Oracle 10g

    I m new in Oracle...
    Create Procedure Insert_profilebasicdetail
    @isubprofileid as int,
    @Copyisubprofileid as int,
    @itranno as int,
    As
    Begin
    Declare @IncKeyId as int
    Declare @tempkeyId as int
    set @IncKeyId=(select isNull(Max(ikeyId),0)as MaxKeyId from profilebasicdetail)
    Declare TempInsert cursor for select ikeyId--,iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,iyear
    from profilebasicdetail where isubprofileid=@Copyisubprofileid and itranno=@itranno
    open TempInsert
    fetch from TempInsert into @tempkeyId
    while @@fetch_Status=0
    Begin
    set @IncKeyId = @IncKeyId + 1
    Insert into profilebasicdetail
    (ikeyid,iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,itranno,iyear,isubprofileid)
    values(select @IncKeyId,iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,'1',
    iyear,@isubprofileid from profilebasicdetail where ikeyId=@tempkeyId)
    fetch next from TempInsert into @tempkeyId
    End
    End
    Regards,
    Ajay

    YOu want to migrate your MS sql server procedure to Oracle procedure
    Before running procedure please set the values of tempkeyId_v variable
    Try this
    Create or replace Procedure Insert_profilebasicdetail( isubprofileid_v  number, Copyisubprofileid_v number, itranno_v number )
    As
         IncKeyId_v  profilebasicdetail.ikeyid%type;
         tempkeyId_v profilebasicdetail.ikeyid%type;
    begin
          select nvl((select Max(ikeyId) as MaxKeyId from profilebasicdetail),0) into IncKeyId_v
          from dual ;
         for i in (select ikeyId--,iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,iyear
                from profilebasicdetail
                where isubprofileid=Copyisubprofileid_v and itranno=itranno_v)
         loop
              IncKeyId_v = IncKeyId_v + 1;
              Insert into profilebasicdetail
                   (ikeyid,iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,itranno,iyear,isubprofileid)
                   values(select IncKeyId_v,i.iprofileid,i.iquestionid,i.vquestionans,i.cstatusindi,i.dmodifyon,i.imodifyby,'1',
                        i.iyear,isubprofileid_v from profilebasicdetail where ikeyId=tempkeyId_v);
         end loop
    End;
    / Regards
    Singh
    Create or replace Procedure Insert_profilebasicdetail( isubprofileid_v  number, Copyisubprofileid_v number, itranno_v number )
    As
         IncKeyId_v  profilebasicdetail.ikeyid%type;
         tempkeyId_v profilebasicdetail.ikeyid%type;
    begin
          select nvl((select Max(ikeyId) as MaxKeyId from profilebasicdetail),0) into IncKeyId_v
          from dual ;
         for i in (select ikeyId--,iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,iyear
                from profilebasicdetail
                where isubprofileid=Copyisubprofileid_v and itranno=itranno_v)
         loop
              IncKeyId_v = IncKeyId_v + 1;
              Insert into profilebasicdetail
                   (ikeyid,iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,itranno,iyear,isubprofileid)
                   values(select IncKeyId_v,i.iprofileid,i.iquestionid,i.vquestionans,i.cstatusindi,i.dmodifyon,i.imodifyby,'1',
                        i.iyear,isubprofileid_v from profilebasicdetail where ikeyId=tempkeyId_v);
         end loop
    End;
    / Regards
    Singh

  • How to run recordset SQL query in FORM DATA event

    How can I run recordset SQL query in FORM DATA event upon clicking on Add button in the document?

    Hi Slamet,
    When you receive a form data event you have a class containing inside it a ObjectKeys xml info regarding the object added/modified,...
    With the objects keys you can then use the DI API method called GetByKeys to obtain the DI Object.
    There is some information about it in the SDK Help file, mainly in the "FormDataEvent" class definition:
    <i>The event provides the unique ID (BusinessObjectInfo.ObjectKey) of the modified business object. You can use the value of this property as an input parameter in the DI API DataBrowser.GetByKeys method to get a DI object.</i>
    Pay attention you don't have this information in the Before=True event of the Add as it is not yet in the database.
    Hope it helps
    Trinidad.

  • Interactive report run pl/sql by clicking on link column

    Hi!
    How can I run pl/sql script by clicking on a link column of an interactive report?
    Andras

    EDIT : Oh sorry don't saw the date, I'm a little late...
    Hi,
    if you want a link for each row, an other solution is to include the link column in your query, which would be more customizable, ie :
    select
    COLUMN1,
    COLUMN2,     
    '<ahref="f?p=&APP_ID.:6:&APP_SESSION.::NO::" onclick="your_function('||YOUR_ID_COLUMN||');return false;">link or picture</a>' as "link",
    COLUMN3;
    from
    ...As you see, you will have to include the ID (primary key) column to your report ("hidden") to identify the row clicked when calling your function.
    If you want to use the Link Column property in the report attributes, you will have to call you js function in the "URL" field like that :
    javascript:your_function('#YOUR_ID_COLUMN#');
    Yann.
    Edited by: Yann39 on 17 sept. 2010 02:41

  • Credential problem while running with SQL job agent

    Hi,
    SQL job agent fails to run when I change my computer login (Password) credentials information often.
    How I can run the SQL job agent with Database login credentials.
    Regards
    Venkatesh S

    Hi Venkatesh,
    If I understand correctly, you are using a proxy account has your login credential to run a step of SQL Agent Job. So when you change the login’s password, the credential of the proxy account has an expired password, then the proxy account doesn’t work in
    your job.
    As per my understanding, we can only use SQL Server Agent Service Account or Proxy Account to run the SQL Server Integration Services Package steps in SQL Agent Job. Since the SQL Server Agent Service Account may not have required permissions to access the
    resources in the packages, we recommend use Proxy Account. To create Proxy Account, we should create a credential first. To create a credential, we should specify a Windows user account. So we cannot use a SQL Server authentication login to run the job.
    A good workaround is use a windows user account with a password that never expire or changes rarely or update the password of credential followed by your login.
    Reference:
    How to: Automate SSIS Package Execution by Using the SQL Server Agent (SQL Server Video)
    How to: Run a Package
    How to: Create a Proxy (SQL Server Management Studio
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Running a SQL Loaded Job from Schedular

    How Can I Run a SQL Loader Job from Schedular ,
    Message was edited by:
    jus

    The trick is to create a wrapper script that is referred to by the PROGRAM object with arguments. The wrapper should do the work.
    /usr/local/bin/do_sqlldr.sh:
    #!/usr/bin/env ksh
    # setup actions
    sqlldr control=...
    Don't forget to check who is the owner of $ORACLE_HOME/bin/extjob and that the owner is available.
    My question is how this can be fitted in an DTAP environment where Developement and Test environment are on the same server and have the same job definitions. Development and Test should use different datafile and logfile locations.
    regards,
    Ronald
    http://ronr.nl/unix-dba

  • How can i run this query in BI Answers

    Hi,
    pls tell me how can i run this sql statement in BI Answers....???
    select abc_date,abc_asset_desc,sum(nvl(abc_market_val_lcy,0)+nvl(abc_accr_lcy,0)) "total balance" from abc
    group by abc_date,abc_asset_desc;any help would be appriciated.... :-)
    Regards

    Strange question this one.
    normally with Answers you pick the columns you want to report on and the BI server will construct the SQL for you.
    In this example you would need a star with the abc dimension logical table and a logical fact for abc (these can be in the same table), which has a calculated field for 'Total Balance'.
    You then pick the columns you require and Answer and the BI will automatically add the group by.
    Adrian
    Majendi

  • How Execute a very long SQL in a Storep Procedure inside a String?

    How Execute a very long SQL in a Storep Procedure inside a String?
    I have a very very long sql in a String , How can I run this SQL?
    Thaks in advance.

    Xavi wrote:
    I have a very very long sql in a String , How can I run this SQL? Version? If you are on 11g, dynamic SQL can be a CLOB. If you are on older versions us DBMS_SQL package.
    SY.

  • How to run a sql script in oracle forms

    Hi,
    For me there is an sql script. I need to run that sql script in forms.
    Actually we will run that sql file in pl/sql developer by giving @and the file name.
    But how to run that file in forms.
    Can any one help on these.Which book I have to look.
    Thanks

    Actually there is a script files which will drop all the indexes and tables.
    DROP querry will be there for each index and each table.
    So I run the script all the indexes and all the tables will be deleted. So using forms I have to run that script.
    Thanks

  • How to I run SQL Loader in a procedure

    Hi
    Can somebody tell me how can i run SQL Loader in a pl/sql procedure ?
    i tried this:
    host sqlldr73 tiger/scott load.ctl
    then this
    host sqlldr73 tiger/scott "c:\load.ctl"
    but none works.
    Please advise.
    Thanks.
    regards
    Esther

    friend
    sqlldr is an application residing in the OS. procedure runs in the dbms engine.
    you cannot run an os command directly from a procedure or a function or a package .
    If you want to do so you need to use either a daemon process created by a PRO*C program
    or a JAVA stored procedure to do so.
    just refer to previous question forums, you can find the solution. Somebody has already given a solution using
    java to run an OS command . check it out
    prakash
    [email protected]

  • How to run the SQL Script in SQL Prompt?

    Hi ExpertGroup,
    I have written one SQL Script name called "MySQLSCript.SQL". I want to know how to run the SQL Script in SQL Prompt?.
    Generally, I run SQL Script in PL/SQL Developer tool. But In this case, some SET command is not working/supporting in PL/SQL Developer Tool.
    Let me know, How to Run in SQl Prompt.
    Thanks & Regards,
    Senthil K Kumar.

    This is my SQL Script....
    SET COLSEP '|'
    SET LINESIZE 32767
    SET PAGESIZE 50000
    /* SET LINESIZE 3000
    SET PAGESIZE 50000
    SET DEFINE OFF */
    SET ECHO OFF
    SET FEEDBACK OFF
    --SET HEADING OFF
    SET TRIMSPOOL ON
    SET NEWPAGE NONE
    SET UNDERLINE OFF
    SPOOL &&EnterPath;
    SELECT * FROM &&TableName;
    SPOOL OFF
    SET FEEDBACK ON
    --SET DEFINE ON
    PROMPT Done.
    I am able to run this script in SQL Prompt....
    Its executing fine...
    But, If I am executing again it maynot asking for new set of data....
    alternativily its taking old values only.....
    how can i exeute with new set of data in the sql prompt.....

  • How to run a SQL manually with the same SQL_ID

    I want to know how to run a SQL which comes from application side manually so that same SQL_ID is generated. I am aware that even if there is a small change in the sql(even a space) the sql_id gets changed. CURSOR_SHARING_PARAMETER is similar in my DB.
    Thanks
    Rudresh

    I think you really want is the execution plan (plan_hash_value), what about outlines ?
    HTH
    Antonio NAVARRO

  • How can I get size of fetched data size when run a SQL ?

    Hi,
    When I run a SQL how can I get fetched data size?
    regards,

    We can get it using some calculations:
    1. SQL%ROWCOUNT attribute will fetch you number of rows returned in a SQL statement.
    Problem-->Now you need to get the size of 1 row.
    Solution-->
    Step 1.We can get size of table from dba_segment data dictionary.
    Select block_size from dba_segemnts where segment name like '%YOURTABLE%';
    Step2 . Get count of rows in your table
    Select count(*) from YOUR_TABLE
    Step 3.
    Get size of 1 row--> Divide result in Step1 by result in Step 2.
    Required result--> multiple result in step3 with SQL%ROWCOUNT..
    I hope this is what u want.

Maybe you are looking for

  • Display .gif In Applet Problem

    I have been making a game. Very simply, the game has a main class and another truely important class that extends JFrame, it is the map. In it i need to upload .gif files and display them. It worked up until recently because i needed to make a sepper

  • JDK 1.6 u12 installation on Windows XP as non-admin user

    I am working on a machine which does not grant my user the admin rights. I had wanted to use JDK with Netbeans. The Netbeans was available as ZIP file, but it required pre-installed JDK. I am not able to install JDK (latest version 1.6 u12) as non-ad

  • Re: authorization object

    Hi,     I have created authorizatin field for authorization object and class.  So now how can i add this authorizationh object for a particular user. rgds p.kp

  • Buying a movie on your (US) account on someone elses laptop from Europe

    To give my friends a movie to watch on their new iPod Touch (on their way back to Europe), I used their laptop to buy a movie on my US account from the US store. Their iTunes and Laptop originated in Europe and although I bought the movie and downloa

  • "Minus Front" a simple shape on top of a complex clipping mask

    I have a clipping path that is made up of: 1. a complex assortment of vector shapes (a pattern) and 2. a simple shape on top. My pattern appears to be inside the simple shape, because of the clipping mask. Now, I'd like to "punch-out" a shape in the