PL/SQL - using procedure within the definition of the cursor parameters.

Hi all

I am currently working on a procedure which has a cursor inside. The only parameter passed when his appeal is a table name (TABLE_NAME parameter) that I want to use as a string in a LIKE comparison within the defined cursor.

Here is the code:
PROCEDURE PURGE (TABLE_NAME IN VARCHAR) 
    IS
        CURSOR TABLES_CUR 
        IS 
            SELECT 
                OBJECT_NAME 
            FROM 
                SYS.DBA_OBJECTS 
            WHERE 
                OWNER = 'MYSCHEMA'
                AND OBJECT_TYPE = 'TABLE'
                AND OBJECT_NAME like 'TABLE_NAME_%'
                AND CREATED = sysdate-3;
        TABLE_DEL TABLES_CUR%rowtype;
    BEGIN
        OPEN TABLES_CUR;
        LOOP
            FETCH TABLES_CUR INTO TABLE_DEL;
            EXIT WHEN TABLES_CUR%NOTFOUND;
            DBMS_OUTPUT.PUT_LINE('TABLE_DEL');
        END LOOP;
        CLOSE TABLES_CUR;
    END PURGE;
However the TABLE_NAME parameter value is not being interpolated, this slider will eventually return nothing.

What should I do to get interpolated and not interpreted as a literal string?

Thanks in advance.
Frank.
OBJECT_NAME like your_parameter||'%'

Tags: Database

Similar Questions

  • Avoid calling the procedure in the cursor loop

    Hi all

    The following example of procedure the procedure written in cursor loop, is called each time until the end of the cursor loop...
    procedure proc_main is
    DECLARE
     cursor c1 is 
        select e.empno empno
               ,e.ename ename
               ,d.dname dname
               ,d.loc   loc
        from emp e,dept d
        where e.deptno = d.deptno ;
     
    BEGIN
      for i in c1 LOOP
       proc_test(i.empno,i.ename,i.dname,i.loc) ;
       end loop;
    END;
    -----------
    
    PROCEDURE proc_test (p_empno,p_ename,p_dname,p_loc) is
    ---
    ---
    begin
     select * into v1,v2,v3 ..
      from temp_tab
       where col1 =p_empno
        ----
        ----
    
    end;
    What would be the alternative methods to write the procedure above instead to call the procedure inside the cursor for loop
    My idea is to use collections... could you give me the code example using collections to meet the above criteria

    Thank you

    Published by: smile on February 28, 2012 15:45

    The ideal would be to collect all SQL logic and put as much of it in a single SQL statement as possible. It would be also great to determine what is the final outcome of the process and use it as a starting point for your SQL. For example, if the desired result is to upgrade the salaries of the employees where they have an entry in table x, you might find that you can avoid needing to separate the logic between multiple, i.e. instead of procedures

    procedure proc_main is
    DECLARE
     cursor c1 is
        select e.empno empno
               ,e.ename ename
               ,d.dname dname
               ,d.loc   loc
        from emp e,dept d
        where e.deptno = d.deptno ;
    
    BEGIN
      for i in c1 LOOP
       proc_test(i.empno,i.ename,i.dname,i.loc) ;
       end loop;
    END;
    -----------
    
    PROCEDURE proc_test (p_empno,p_ename,p_dname,p_loc) is
    ---
    ---
    begin
     select * into v1,v2,v3 ..
      from temp_tab
       where col1 =p_empno
        ----
        ----
    
        UPDATE
            emp e
        SET
            sal = v2
        WHERE
            e.empno = p_Empno;
    
    end;
    

    You may simply have

    procedure proc_main is
    BEGIN
    
        UPDATE
            emp e
        SET
            sal = ( SELECT
                        t.new_sal
                    FROM
                        temp_tab t
                    WHERE
                        t.empno = e.empno
                   )
        WHERE
            EXISTS
                (   SELECT
                        NULL
                    FROM
                        temp_tab t
                    WHERE
                        t.empno = e.empno
                );
    
    END;
    

    Even if your logic is more complex, you are likely to find that you can merge several of the statements that you could be running in a loop and replace that loop with a join.

    Given the particular structure of what you posted if, instead of calling the procedure in a loop, you can simply move the cursor c1 as a parameter to proc_test that is

    procedure proc_main is
    
        lc_c1   sys_refcursor;
    
    BEGIN
    
        OPEN lc_c1 FOR
        select e.empno empno
               ,e.ename ename
               ,d.dname dname
               ,d.loc   loc
        from emp e,dept d
        where e.deptno = d.deptno ;
    
       proc_test(c1) ;
    
    END;
    -----------
    
    PROCEDURE proc_test (p_Cursor sys_refcursor) is
    
    begin
    
        LOOP
            FETCH ....
    
            ...DO SOMETHING...
    
            EXIT WHEN p_Cursor%NOTFOUND;
    
        END LOOP;
    
        CLOSE p_Cursor;
    END;
    

    But I highly recommend that you consider trying to merge as much of your SQL before considering the approach of cursor.

    HTH

    David

  • The SQL has aged in the cursor cache.

    Hello
    in 10g R2, Ihave the following:
    The SQL has aged in the cursor cache.

    Does that mean that undo_retention is not big enough?

    At the moment it is 10800, 3 hours.

    Thank you.

    To cancel retention and aging SQL out of cache are two different things and are not not depedant.

  • Debug/run procedures within the package

    Debugging with SQL Developer was generally very nice and I have come to rely on these tools. Today, I've written a procedure in a package and I want to debug this process, but I don't see it in the list of targets. It seems that I see only functions in the target list. I understand that the procedures need not have the same kind of output in function, but sometimes I like to create procedures that have multiple SETTINGS, especially when it comes to an exit very closely related.

    The interesting thing is that I can create this same procedure as a stand-alone procedure and the run/debug works great. Apparently I'm missing something obvious in SQL Developer somewhere I thought it was there all the time (I guess for a while since I've written a procedure with OUT parameters) but maybe I'm wrong. Any ideas or help someone?

    Earl

    It should work.

    Is that you can create a package of simple heel with just a function procedure that is a NULL; and use it as a test?

    If this does not work there either, please send a screenshot so we can see what you see in the debugging with the missing procedure dialog box.

  • to find the location of PL/SQL, stored PROCEDURE in the database

    Hello

    This is the detail I have the executable of the Application Developer program simultaneous

    Executable NAPESCO_STAFF_LEDGER_DTLS

    Short name NPSTALEDDTLS

    Application of human resources

    Execution of PL/SQL, stored procedure method

    Name of file execution NAPESCO_STAFF_LEDGER_DTLS


    I would like to know how to view and change this procedure, where it is stored

    kindly help

    Hello

    This seems to be a custom package. To display the source of the simultaneous program ' PL/SQL Stored Procedure', please refer to (Note: 455582.1 - where can I get the whole "stored procedure" Pl/Sql Source file on the current program?).

    Thank you
    Hussein

  • Return of the ref cursor of procedure where the cursor is defined in the specification

    Hello

    Here's pseudo-code

    create or replace package test
    as
    cursor c_emp (number cv_emp_id)
    is
    Select emp_name emp where emp_id = cv_emp_id;

    type ref_c is ref cursor;

    function get_emp_name (number p_emp_id) return ref_c;
    end test;
    /


    create or replace the test physics package
    as
    ref_c function get_emp_name (number p_emp_id)
    is
    ret_val ref_c;
    Start
    Open c_emp (p_emp_id);
    ret_val: = c_emp;
    return ret_val;

    end get_emp_name;
    end test;
    /

    Returns me "PLS-00382: expression is of the wrong type. I tried to use a strongly typed Ref cursor based on the cursor, but nothing helped.

    Clearly, I understand something... and if I can't assign as ' ret_val: = c_emp "and if there is another key way it so please let me know.

    Thank you

    Ralph

    Published by: user13024707 on May 5, 2010 04:43

    user13024707 wrote:
    Clearly the point of my question is being missed.

    Or maybe the question is not been clearly asked. ;)

    I want to set the cursor in the PACKAGE SPECIFICATION, and not in the package body. The issue of the bind variable and the string is neither here nor there because I pass parameters to the cursor.

    What you ask is to use a PL/SQL cursor (defined in the specifications of the package or elsewhere) and that convert a Ref Cursor. N ° cannot be done.
    PL/SQL cursors should be used in the PL/SQL code. REF CURSOR is primary used to pass back a reference to a cursor (and all queries are cursors) to a layer of application outside of PL/SQL for example .net, java, etc.. Once you start using the ref Cursor only really, you have the choice of opening it based on a (dynamic) or a fixed query string as in the examples given. You cannot open a cursor of a PL/SQL cursor definition Ref.

    The difference is that when you do:

      CURSOR cur_mycursor IS
        SELECT ...
    

    you declare a cursor in pl/sql definition, not actually a slider itself. The cursor itself is created when you issue an OPENING or a statement FOR etc. So a Ref Cursor (reference to a slider) cannot refer to the definition of the cursor because it is only a definition, not a cursor (i.e. it has not been sent engine sql and instantiated at that time here). Instead the Ref Cursor must reference a cursor (query), itself, and that may be presented as a string or as the query itself that is issued against the sql engine and then the ref cursor points

    Thus, slider ref and PL/SQL cursors are different concepts, both designed to manage cursors in a slightly different way of programming. You cannot mix them.

  • Plu SQL hang up when the cursor is fired.

    Hello
    I'm just a beginner in sql and plsql. I run the cursor query as below in my sql more window:

    Declare
    CURSOR emp_cursor IS SELECT * FROM employees WHERE employee_id = 100;
    employees emp_record % rowtype;
    Begin
    OPEN emp_cursor;
    LOOP
    LOOK INTO emp_record emp_cursor;
    DBMS_OUTPUT. Put_line (emp_record);
    END LOOP;
    NARROW Emp_cursor;
    END;

    While I try to run the plu SQL hang (the cursor (_) flashes to a new line in trying to retrieve the result). Even after 10-15 minutes the result is displayed and I cannot type in any other question, that the system is not ready. In short sql plu hangs up.

    Add the exit condition

    FETCH emp_cursor INTO emp_record;
    exit when emp_cursor%notfound;
    

    also your call to DBMS_OUTPUT. Procedure put_line() is not.
    It takes a VARCHAR2 as an input parameter, when you pass a variable with employees % rowtype.
    For me, it showed the following error:

    DBMS_OUTPUT.PUT_LINE(emp_record);
    *
    ERROR at line 8:
    ORA-06550: line 8, column 1:
    PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
    

    That should be:

    DBMS_OUTPUT.PUT_LINE(emp_record.employee_id); --Or whatever columns you want to display
    
  • How to convert sql server procedures in the format of oracle

    Hello

    I need help, I got some procedures that is written in the format MS Sql, I need to convert those to the format of the oracle, and I don't know how to do. Could someone help me?

    IN SQL server code format is:

    / * Object: StoredProcedure [dbo]. [sp_rpt_get_job_log_on_demand]    Script Date: 20/12/2013-09:07:26 * /.

    SET ANSI_NULLS

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE PROCEDURE [dbo]. [sp_rpt_get_job_log_on_demand]

    (

    @JOB_ID INT

    @REPORT_DATE AS DATETIME

    , @PERIOD VARCHAR (100)

    )

    AS

    BEGIN

    SET @REPORT_DATE = CONVERT (DATETIME, CONVERT (DATE, @REPORT_DATE))

    DECLARE @MONTH INT = (YEAR (@REPORT_DATE) * 100) + MONTH (@REPORT_DATE)

    , @TODAY = INT ((((@REPORT_DATE) YEAR * 100) + MONTH (@REPORT_DATE)) * 100) + DAY (@REPORT_DATE)

    @YEAR INT = YEAR (@REPORT_DATE)

    SELECT J.JOB_ID

    J.JOB_NAME

    CASE

    WHEN F.FREQUENCY_SUBTYPE IS NULL, F.FREQUENCY_TYPE

    OF OTHER F.FREQUENCY_TYPE + '-' + F.FREQUENCY_SUBTYPE

    END AS FREQUENCY_TYPE

    L.TRANSACTION_DATE

    L.PROCESS_DATE

    START_TIME

    END_TIME

    DATEDIFF(MINUTE,START_TIME,END_TIME) AS TIME_TAKEN

    L.RECORD_COUNT

    ISNULL(L.EXECUTION_STATUS, 'NOT STARTED') AS EXECUTION_STATUS

    L.ERROR AS ERROR_DESC

    P.PRIORITY_NUMBER

    P.COLOR_CODE

    OF dbo.JOBS J AS

    INNER JOIN dbo. ACE OF FREQUENCY F

    ON J.FREQUENCY_ID = F.FREQUENCY_ID

    INNER JOIN dbo. JOB_PRIORITY AS P

    ON J.PRIORITY_ID = P.PRIORITY_ID

    LEFT JOIN dbo. TBK_POS_FACT_LOADING_SUMMARY ACE L

    ON J.JOB_ID = L.JOB_ID

    AND)

    (@PERIOD = 'TODAY' AND CONVERT (DATETIME, CONVERT (DATE, L.START_TIME)) = @REPORT_DATE) OR

    (@PERIOD = 'MONTHS' AND ((START_TIME) YEAR * 100) + MONTH (START_TIME) = @MONTH) OR

    (@PERIOD = 'YEAR' AND YEAR (START_TIME) = @YEAR)

    )

    AND CONVERT (DATETIME, CONVERT (DATE, L.START_TIME)) < = @REPORT_DATE

    WHERE F.FREQUENCY_TYPE <>'NONE'

    AND J.JOB_ID = @JOB_ID

    UNION ALL

    SELECT J.JOB_ID

    J.JOB_NAME

    CASE

    WHEN F.FREQUENCY_SUBTYPE IS NULL, F.FREQUENCY_TYPE

    OF OTHER F.FREQUENCY_TYPE + '-' + F.FREQUENCY_SUBTYPE

    END AS FREQUENCY_TYPE

    L.TRANSACTION_DATE

    L.PROCESS_DATE

    START_TIME

    END_TIME

    DATEDIFF(MINUTE,START_TIME,END_TIME) AS TIME_TAKEN

    L.RECORD_COUNT

    L.EXECUTION_STATUS

    L.ERROR AS ERROR_DESC

    P.PRIORITY_NUMBER

    P.COLOR_CODE

    OF dbo.JOBS J AS

    INNER JOIN dbo. ACE OF FREQUENCY F

    ON J.FREQUENCY_ID = F.FREQUENCY_ID

    INNER JOIN dbo. JOB_PRIORITY AS P

    ON J.PRIORITY_ID = P.PRIORITY_ID

    INNER JOIN dbo. TBK_POS_FACT_LOADING_SUMMARY ACE L

    ON J.JOB_ID = L.JOB_ID

    WHERE F.FREQUENCY_TYPE = 'NONE '.

    AND)

    (@PERIOD = 'TODAY' AND CONVERT (DATETIME, CONVERT (DATE, L.START_TIME)) = @REPORT_DATE) OR

    (@PERIOD = 'MONTHS' AND ((START_TIME) YEAR * 100) + MONTH (START_TIME) = @MONTH) OR

    (@PERIOD = 'YEAR' AND YEAR (START_TIME) = @YEAR)

    )

    AND J.JOB_ID = @JOB_ID

    AND CONVERT (DATETIME, CONVERT (DATE, L.START_TIME)) < = @REPORT_DATE

    END

    GO

    I tried to convert it to a format of oracle... But I get the error message.

    --------------------------------------------------------------------------------------------------

    CREATE OR REPLACE PROCEDURE POS.sp_rpt_get_job_log_on_demand_V)

    JOB_ID NUMBER,

    DATE OF REPORT_DATE,

    PERIOD VARCHAR2 (100))

    AS

    BEGIN

    l_MONTH: = TO_CHAR (REPORT_DATE, "YYYYMM");

    TODAY: = TRUNC (REPORT_DATE);

    l_YEAR: = TO_CHAR (REPORT_DATE, 'YYYY');

    SELECT J.JOB_ID,

    J.JOB_NAME,

    CASE

    WHEN F.FREQUENCY_SUBTYPE IS NULL, F.FREQUENCY_TYPE

    OF OTHER F.FREQUENCY_TYPE | '-' || F.FREQUENCY_SUBTYPE

    END

    AS FREQUENCY_TYPE.

    L.TRANSACTION_DATE,

    L.PROCESS_DATE,

    START_TIME,

    END_TIME,

    (END_TIME - START_TIME) AS TIME_TAKEN,

    L.RECORD_COUNT,

    NVL (L.EXECUTION_STATUS, "NOT STARTED") AS EXECUTION_STATUS,

    L.ERROR AS ERROR_DESC,

    P.PRIORITY_NUMBER,

    P.COLOR_CODE

    OF POS.JOBS J.

    POINT OF SALE. FREQUENCY F,

    POINT OF SALE. JOB_PRIORITY P,.

    POINT OF SALE. TBK_POS_FACT_LOADING_SUMMARY L

    WHERE J.FREQUENCY_ID = F.FREQUENCY_ID

    AND J.PRIORITY_ID = P.PRIORITY_ID

    AND J.JOB_ID = L.JOB_ID

    (PERIOD = 'TODAY'

    AND TO_CHAR (L.START_TIME, 'YYYYMMDD') =

    TO_CHAR (REPORT_DATE, 'YYYYMMDD'))

    OR (PERIOD = 'MONTHS' AND TO_CHAR (START_TIME, "YYYYMM") = MONTH)

    OR (PERIOD = 'YEAR' AND TO_CHAR (START_TIME, 'YYYY') = YEAR)

    AND F.FREQUENCY_TYPE <>'NONE'

    AND TRUNC (L.START_TIME) < = TRUNC (REPORT_DATE)

    AND JOB_ID = J.JOB_ID

    UNION ALL

    SELECT J.JOB_ID,

    J.JOB_NAME,

    CASE

    WHEN F.FREQUENCY_SUBTYPE IS NULL, F.FREQUENCY_TYPE

    OF OTHER F.FREQUENCY_TYPE | '-' || F.FREQUENCY_SUBTYPE

    END

    AS FREQUENCY_TYPE.

    L.TRANSACTION_DATE,

    L.PROCESS_DATE,

    START_TIME,

    END_TIME,

    (END_TIME - START_TIME) AS TIME_TAKEN,

    L.RECORD_COUNT,

    L.EXECUTION_STATUS,

    L.ERROR AS ERROR_DESC,

    P.PRIORITY_NUMBER,

    P.COLOR_CODE

    OF POS.JOBS J.

    POINT OF SALE. FREQUENCY F,

    POINT OF SALE. JOB_PRIORITY P,.

    POINT OF SALE. TBK_POS_FACT_LOADING_SUMMARY L

    WHERE F.FREQUENCY_TYPE = 'NONE '.

    AND J.FREQUENCY_ID = F.FREQUENCY_ID

    AND J.PRIORITY_ID = P.PRIORITY_ID

    AND J.JOB_ID = L.JOB_ID

    (PERIOD = 'TODAY'

    AND TO_CHAR (L.START_TIME, 'YYYYMMDD') =

    TO_CHAR (REPORT_DATE, 'YYYYMMDD'))

    OR (PERIOD = 'MONTHS' AND TO_CHAR (START_TIME, "YYYYMM") = MONTH)

    OR (PERIOD = 'YEAR' AND TO_CHAR (START_TIME, 'YYYY') = YEAR)

    AND JOB_ID = J.JOB_ID

    AND TRUNC (L.START_TIME) < = TRUNC (REPORT_DATE)

    END;

    /

    POS PROCEDURAL errors. SP_RPT_GET_JOB_LOG_ON_DEMAND_V:

    LINE/COL ERROR

    -------- -----------------------------------------------------------------

    4/28 PLS-00103: encountered the symbol "(" quand attend un de la) "

    Next:

    := . ), @ % of default characters

    The symbol ': = ' has been replaced by "("pour continuer.) "

    76/1 PLS-00103: encountered the symbol "END" when awaits an of the

    Next:

    . (* % & -+; / TA for rem rest mod < an exhibitor > (*))

    and or group having intersect less order start union where

    connect | multiset

    The symbol ';' was replaced by 'END' continue.

    Thank you and best regards,

    John of Vikash

    Keep in mind, DBMS_OUTPUT is reserved for debugging purposes. If you want the output to a front-end, you can use SYS_REFCURSOR as OUTPUT parameter and get the data of the SELECT query.

  • How to use methods within the itemRenderer

    Hello

    I have basic itemRenderer as a component:

    < mx:Component id = "ColorRenderer" >
    < mx:Label
    Text = "{rgb2hex (255,100,50)} ' / / this gives error: 1180: call to a method may be undefined rgb2hex"
    / >
    < / mx:Component >

    My method works if I use it with a 'normal' tag < mx:Label = "22" x = "12" text = "{rgb2hex (255,100,50)}" width = "150" / > "
    but it does not work inside the itemRenderer?

    What I'm missing here?

    When you use the tag you define a new variable scope. In this context, the rgb2hex does not exist. You need to qualify: { outerDocument.rgb2hex (255,100,50)}

  • How to configure within the fixed parameters flexible time limits.

    I'm looking to set up a set in two layers of time limits on user accounts in Vista.  First of all, I would like to limit the specific times where an account will be available.  Second, I want to limit the total number of hours that the account can be used within these limits.  It is NOT practical or reasonable at all in my situation to simply set the deadlines.  I need a combined fixed/flexible system.  How it is made, or Microsoft simply failed to provide an adequate solution, forcing me to buy a third-party product to make up yet another gap in Vista?

    That's what Microsoft provides:

    http://www.Microsoft.com/Windows/Windows-Vista/features/parental-controls.aspx

    Explore the features: Parental controls

    http://www.bleepingcomputer.com/tutorials/tutorial139.html

    The best tutorial on setting up.

    See you soon. Mick Murphy - Microsoft partner

  • How to read a variable main.swf (this content.swf of load) and use within the loaded movie?

    Hello

    How to read a variable main.swf (this content.swf of load) and use it within the content.swf?

    I have a variable called TextColor = 'Green' handmade film and I want to read this variable from inside the content movie?

    anyone can help!

    Thank you very much.

    MyGiantBrain thanks for your reply but kglad method worked very well.

    Thanks kglad but there is some changes to your code so that it works, and it is:

    trace (MovieClip (parent.parent) ["TextColor"]);

    Thank you

  • procedure within procedural problem

    Hello
    I have a table of 5 different magazines and an array of purchases of these magazines. I wrote a procedure to take the details of a given magazine and place sales for a month in a sales table as follows:

    create or replace procedure monthly_sales (issue of the mag, date startdate, enddate date) is
    magtotal number (7.0);
    magprice magazine.unitprice%type;
    magsales number (7.2);
    Start
    SELECT count (p.magid), m.unitprice magtotal, magprice to purchase p and m magazine where p.datepurchased between the startdate and enddate, p.magid = mag and m.magid = p.magid
    M.unitprice group;
    magsales: = magtotal * magprice;
    Insert in the value of sales (startdate, mag, magtotal, magsales);
    end;

    However, what I want to do is have a procedure that you just need to run once and it will enter into sales for a month for all the dirty magazines in the table. My thought was to try to do it using the procedures within a procedure as follows:

    create or replace procedure monthly_sales (date startdate, enddate date) is
    magtotal number (7.0);
    magprice magazine.unitprice%type;
    magsales number (7.2);
    mag1 procedure is
    Start
    SELECT count (p.magid), m.unitprice magtotal, magprice to purchase p, m magazine where p.datepurchased between startdate and enddate, and p.magid = 1 and m.magid is p.magid
    M.unitprice group;
    magsales: = magtotal * magprice;
    Insert into the sales value (startdate, 1, magtotal, magsales);
    mag1 end;
    procedure mag2 is
    Start
    SELECT count (p.magid), m.unitprice magtotal, magprice to purchase p, m magazine where p.datepurchased between startdate and enddate, and p.magid = 2 and m.magid is p.magid
    M.unitprice group;
    magsales: = magtotal * magprice;
    Insert into the sales value (startdate, 2, magtotal, magsales);
    end mag2;
    mag3 is
    Start
    SELECT count (p.magid), m.unitprice magtotal, magprice to purchase p, m magazine where p.datepurchased between startdate and enddate, and p.magid = 3 and m.magid is p.magid
    M.unitprice group;
    magsales: = magtotal * magprice;
    Insert into the sales value (startdate, 3, magtotal, magsales);
    mag3 end;
    mag4 procedure is
    Start
    SELECT count (p.magid), m.unitprice magtotal, magprice to purchase p, m magazine where p.datepurchased between startdate and enddate, and p.magid = 4 and m.magid is p.magid
    M.unitprice group;
    magsales: = magtotal * magprice;
    Insert into the sales value (startdate, 4, magtotal, magsales);
    end mag4;
    Start
    SELECT count (p.magid), m.unitprice magtotal, magprice to purchase p, m magazine where p.datepurchased between startdate and enddate, and p.magid = 5 and m.magid is p.magid
    M.unitprice group;
    magsales: = magtotal * magprice;
    Insert into the sales value (startdate, 5, magtotal, magsales);
    end;

    However, when I run the present, it is consider all procedures within the main procedure and just enter the results for the magazine 5. I am at a loss as to why it doesn't work, it's even the right way to go about this? any help would be greatly appreciated

    Thank you

    Why do the hard?
    A simple insert statement will do.

    I did a bit of a guess as to the structure of your tables:

    create table magazine (magid number primary key, unitprice number);
    create table purchase (magid number references magazine(magid), datepurchased date);
    create table sales (startdate date, magid number references magazine(magid), magtotal number, magsales number);
    
    insert into magazine(magid, unitprice) values (1, 3.95);
    insert into magazine(magid, unitprice) values (2, 4.95);
    insert into magazine(magid, unitprice) values (3, 3.50);
    insert into magazine(magid, unitprice) values (4, 6.0);
    insert into magazine(magid, unitprice) values (5, 5.50);
    
    insert into purchase(magid, datepurchased) values (1, sysdate);
    insert into purchase(magid, datepurchased) values (1, sysdate);
    insert into purchase(magid, datepurchased) values (2, sysdate);
    insert into purchase(magid, datepurchased) values (2, sysdate);
    insert into purchase(magid, datepurchased) values (2, sysdate);
    insert into purchase(magid, datepurchased) values (4, sysdate);
    insert into purchase(magid, datepurchased) values (5, sysdate);
    insert into purchase(magid, datepurchased) values (5, sysdate);
    insert into purchase(magid, datepurchased) values (5, sysdate);
    insert into purchase(magid, datepurchased) values (5, sysdate);
    
    commit;
    
    create or replace procedure monthly_sales(p_startdate in date, p_enddate in date)
    is
    begin
      insert into sales (startdate, magid, magtotal, magsales)
        select p_startdate
        ,      p.magid
        ,      count(p.magid)
        ,      count(p.magid) * m.unitprice
        from   purchase p
          join magazine m on m.magid = p.magid
        where  p.datepurchased between p_startdate and p_enddate
        group by p.magid
        ,        m.unitprice;
    end;
    /
    
    begin
      monthly_sales(trunc(sysdate,'MM'), last_day(trunc(sysdate,'MM')));
    end;
    /
    
    select * from sales;
    
    STARTDATE      MAGID   MAGTOTAL   MAGSALES
    --------- ---------- ---------- ----------
    01-JAN-11          1          2        7.9
    01-JAN-11          2          3      14.85
    01-JAN-11          4          1          6
    01-JAN-11          5          4         22
    
  • How to apply the procedure inside a procedure and the evils of the value in a variable?

    Hi all

    I'm usung oracle 11g.

    Here is my package and procedure

    I want to call get_email_details this procedure within the process_email_master and store the value in a variable in main proceedings

    create or replace

    PACKAGE ms_gen_process_email

    as

    type email_type is rendered (subject varchar2 (4000 tank),

    email_body varchar2 (4000 tank),

    to_receipent varchar2 (4000 tank),

    cc_receipent varchar2 (4000 char));

    type email_type_table is table of the email_type;

    procedure process_email_master)

    p_metric_name IN VARCHAR2,

    p_current_stage in varchar2,

    p_action in varchar2,

    p_pid number,

    P_OBJECT_ID in varchar2

    -p_emai_master on p_email_type_table

    );

    PROCEDURE get_email_details)

    p_metric_name IN VARCHAR2,

    p_current_stage in varchar2,

    P_ACTION in varchar2,

    p_email_type_table1 on email_type_table

    ) ;

    END ms_gen_process_email;

    ----

    create or replace

    PACKAGE ms_gen_process_email BODY

    as

    procedure process_email_master)

    p_metric_name IN VARCHAR2,

    p_current_stage in varchar2,

    p_action in varchar2,

    p_pid number,

    p_object_id in varchar2

    )

    as

    Start

    null;

    EXCEPTION

    WHILE OTHERS

    then

    null;

    end process_email_master;

    PROCEDURE get_email_details)

    p_metric_name IN VARCHAR2,

    p_current_stage IN VARCHAR2,

    P_ACTION in varchar2,

    p_email_type_table on email_type_table

    )

    as

    BEGIN

    Select the object, email_body, to_receipent, cc_receipent

    bulk collect into p_email_type_table

    of ms_gen_email_config_detail

    WHERE email_key =)

    SELECT email_key

    OF ms_gen_email_config

    WHERE metric_name = p_metric_name

    AND action p_action =

    and current_stage = p_current_stage

    );

    for me in p_email_type_table.first... loop of p_email_type_table. Last

    dbms_output.put_line (p_email_type_table (i) reserve .under | p_email_type_table (i) .email_body: p_email_type_table (i) .to_receipent: p_email_type_table (i) .cc_receipent);

    end loop;

    EXCEPTION

    WHILE OTHERS

    THEN

    NULL;

    END get_email_details;

    END ms_gen_process_email;

    but I get this error message

    Error (15,31): PLS-00201: identifier 'P_EMAIL_TYPE_TABLE' must be declared

    Concerning

    Dale

    See below the test case and change your code. You can call the procedure in detail within a main as procedure below

    CREATE or REPLACE PACKAGE test_pkg AS

    TYPE rec_val IS RECORD (empno, emp.empno%TYPE,

    Ename emp.ename%TYPE

    );

    TYPE nt_tabtest IS TABLE OF THE rec_val;

    PROCEDURE get_email_id (p_type to nt_tabtest);

    PROCEDURE get_email_master;

    END;

    /

    CREATE or REPLACE PACKAGE test_pkg BODY

    AS

    PROCEDURE get_email_id (p_type ON nt_tabtest)

    AS

    BEGIN

    SELECT EmpNo, ename COLLECT in BULK in p_type FROM emp;

    END;

    PROCEDURE get_email_master

    AS

    v_type nt_tabtest;

    BEGIN

    get_email_id (v_type);

    BECAUSE me IN v_type. FIRST... v_type. LAST

    LOOP

    DBMS_OUTPUT. Put_line (v_type (i) .empno: v_type (i) .ename);

    END LOOP;

    END;

    END;

    /

    Post edited by: 000000

  • procedure in the procedure

    Hello

    can we call the same procedure within the procedure?
    or parcel?
    -- Procedures.
    CREATE OR REPLACE PROCEDURE P1 IS
    BEGIN
    NULL;
    END;
    
    PROCEDURE P1 Compiled.
    ------------------------------------
    CREATE OR REPLACE PROCEDURE P2 IS
    BEGIN
    NULL;
    P1;
    END;
    
    PROCEDURE P2 Compiled.
    ------------------------------------
    --now replacing procedure P1
    CREATE OR REPLACE PROCEDURE P1 IS
    BEGIN
    NULL;
    P2;
    END;
    
    PROCEDURE P1 Compiled.
    ------------------------------------
    --  now again compile P1 procedure, will get error.
    CREATE OR REPLACE PROCEDURE P1 IS
    BEGIN
    NULL;
    P2;
    END;
    Warning: execution completed with warning
    PROCEDURE P1 Compiled.
    
    -- Packages
    CREATE OR REPLACE PACKAGE PCK IS
    PROCEDURE P1;
    PROCEDURE P2;
    END;
    /
    CREATE OR REPLACE PACKAGE BODY PCK IS
    
    PROCEDURE P1 AS
    BEGIN
    P2;
    END;
    PROCEDURE P2 AS
    BEGIN
    P1;
    END;
    
    BEGIN
    P1;
    P2;
    END;
    
  • calling a procedure in the loop

    I just want to know one thing:

    I call a procedure with the following parameters

    DECLARE

    PROFIT_CENTER NUMBER ;

    START

    PROFIT_CENTER : = 1109--(de même, je fais tourner le proc pour 5 profit_centers plus 1123,1132,1122,3211,1111 un par un en passant les valeurs manuellement, il prend près d'une minute pour chaque centre de profit)

    Prc_test_calc () PROFIT_CENTER);

    COMMIT;

    END;

    For each proc profit_center takes 1 minute (approx.) time.

    But when I'm putting loop to call the procedure for each profit_center, I don't know why it takes too long for each profit_center

    Please let me know is there something wrong with the loop below

    DECLARE

    PROFIT_CENTER NUMBER ;

    cursor c_profit is

    Select separate PROFIT_CENTER de plng_pc profit_center in ()1109 1123,1132,1122,3211,1111)-Plng_pc is a table where profit_center information is obtain from

    START

    For pc_rec in c_profit

    loop

    Prc_test_calc (  pc_rec . PROFIT_CENTER );

    COMMIT;

    End loop;

    END;

    Could you please sugget me if something goes wrong?

    Hello

    as suggested, have you checked the query for the cursor loop and have you tried the process with no cursor loop.

    Concerning

    André

Maybe you are looking for

  • Wi - Fi connection problems

    Recently, my iPhone 6 has not been able to connect to Wi - Fi. Whether my house, my friend apartment or any source of Wi - Fi public. I tried to reset my iPhone network settings, it did not help my situation. Any suggestions?

  • Want 5640: A6 Photo prints

    I put my setting on the printer to print A6 (10 x 15 cm). I just get the error that chose the format is not supported in the photo tray. A4, I got the main tray works well. I tried with Photoshop and also Lightromm with the same result. If I choos au

  • Update graphics on the Satellite 2450-201

    Hay I have nvidia geforce 420 go. Is it possible at this level to something better like the last fx nvidia maybe?

  • Anyone else having a problem with Spotlight and iOs 9?

    I have all the Spotlight options switched immediately, but ever since the last update of the firmware (9.2.1) more time when I search for an app, nothing comes... I have 'Suggestions' allowed to. I tried to turn it off and restart my iPhone 6 and re-

  • Cannot install Games for Windows Live

    I need to install Games for Windows Live to play several games on this laptop. When I run gfwlivesetup, all downloads very well and gets to the point where it installs GFWL and I get the following error every time: "An error occurred during the insta