Reg: DDL within a procedure.

Dear Experts,

Can we have a DDL inside a procedure/package. Here is the sample code for reuse by the members of the team if any change should be done.

Could you please clarify for me / guide me, it is the right approach or would there be effects or is - this cool by oracle or not.

CREATE OR REPLACE

PROCEDURE ALTPRC)

TNOM IN VARCHAR2,

NAME OF COLUMN IN VARCHAR2,

DTYPE IN VARCHAR2)

IS

VSQL VARCHAR2 (100);

BEGIN

VSQL: = 'alter table ' | TNOM | 'Add'. COLNAME | » '|| DTYPE;

DBMS_OUTPUT. Put_line ('Alter Stmt: ' |) VSQL);

RUN IMMEDIATELY VSQL;

END;

ALTPRC EXEC ('emp1', 'testcol', 'number');

Thank you

Can do us, YES. Should do us, (there are always exceptions) most of the time no..

Issue DDL COMMIT before and after the statement. So, it cannot be part of a transaction. A good DB design will not data structure allow to change on the FLY. A good application handles changes to dictionary in a version control system.

So can you share with us what kind of benefits you are searching by an alter as statement

ALTPRC EXEC ('emp1', 'testcol', 'number');

to the course to do as

ALTER TABLE EMP1 ADD COLUMN TESTCOL NUMBER;

One of the reasons could connect. But I can't find satisfactory as a reason to do it this way.

Tags: Database

Similar Questions

  • Reg: Mailing 'time of procedure then run ".

    Hi all

    I created a PL/SQL procedure that will send e-mail about password expiration of oracle user details.

    Here's my script

    declare
    crlf VARCHAR2(2)  := chr(13)||chr(10);
    CURSOR c1 IS SELECT 
    e.alternate_name,e.email,e.cc,u.expiry_date, round(u.expiry_date-sysdate) as date_diff 
    FROM dba_users u, email_address e 
    WHERE u.username=e.username;
    username VARCHAR2(50); 
    email VARCHAR2(250);
    expire_date varchar2(50);
    date_diff  varchar2(50);
    sender VARCHAR2(40) := '[email protected]';  
    message VARCHAR2(200);
    final_message varchar2(1000);
    mailhost VARCHAR2(30) := 'x.x.x.x';  
    mail_conn UTL_SMTP.connection; 
    BEGIN 
    message:=' user will expire in ';  
    OPEN c1; 
    LOOP 
    FETCH c1 INTO username,email,expire_date,date_diff; 
    EXIT WHEN c1%NOTFOUND;  
       final_message := final_message || 'user: '|| username ||')' || crlf || 'Password of ' || username||message||' '||date_diff||'days'||' (Expiry Date: ' || expire_date || '): ';
    END LOOP; 
    CLOSE c1;
    mail_conn := UTL_SMTP.open_connection(mailhost, 25); 
    UTL_SMTP.helo(mail_conn, mailhost);
    UTL_SMTP.mail(mail_conn, sender); 
    UTL_SMTP.rcpt(mail_conn, email);
    UTL_SMTP.DATA(mail_conn, 'To: ' || email || crlf || 'Subject: ' || '[Test Mail]: Oracle User Password Expiry Reminder('||final_message||')';
    UTL_SMTP.quit(mail_conn);
    END;
    /
    
    
    

    I have planned the procedure above using DBMS_SCHEDULER

    Schedule: Fridays at 10:00

    When I run the above procedure, I will get an email about the oracle user password expiration information.

    But I want to add the next execution of the procedure in the same mail by querying dba_scheduler_jobs.

    I could do this using nested cursors, but I get execution instead of the next pending execution date.

    Is it possible to get the next execution date of the method, either by pulling the trigger, either within the procedure that precedes itself?

    REF-> previous discussion: https://forums.oracle.com/thread/2612449

    Hi Madhu,

    Please check DBMS_SCHEDULER. EVALUATE_CALENDAR_STRING.

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25788/d_sched.htm#ARPLS72367

    Example link above...

    > set SERVEROUTPUT ON

    > ALTER SESSION set NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS.

    session the changed VALUE.

    > DECLARE

    start_date TIMESTAMP;

    return_date_after TIMESTAMP;

    next_run_date TIMESTAMP;

    BEGIN

    start_date: =.

    TO_TIMESTAMP_TZ (sysdate, 'DD-MON-YYYY HH24:MI:SS');

    return_date_after: = start_date;

    FOR I IN 1.5 LOOP

    DBMS_SCHEDULER. () EVALUATE_CALENDAR_STRING

    "FREQ = ALL DAYS; BYHOUR = 9; BYMINUTE = 30; BYDAY = MON, FRI, MAR, SEA, GAME '.

    start_date, return_date_after, next_run_date);

    DBMS_OUTPUT. Put_line ('next_run_date: ' | next_run_date);

    return_date_after: = next_run_date;

    END LOOP;

    END;

    anonymous block filled

    next_run_date: December 16, 13 09.30.44.000000 AM

    next_run_date: 17 December 13 09.30.44.000000 AM

    next_run_date: December 18, 13 09.30.44.000000 AM

    next_run_date: December 19, 13 09.30.44.000000 AM

    next_run_date: 20 December 13 09.30.44.000000 AM

    I hope this helps.

    VR,

    Sudhakar

  • Wrong execution of a package within a procedure stored

    Oracle version: 10.2.0.4 RAC

    I posted the below problem in REPLICATION forum but I think he needs to be here. I think I'm having a problem with some "shade" of Oracle, which relates to the appellant a package in a regulation and immunities.

    Here is the original post:
    ================================================================================================

    Get an ora-12048 and ora - 942 when executing dbms_refresh.refresh in a stored procedure. When I invoke dbms_refresh.refresh directly from SQLPlus things work very well.

    Here is the header and the relevant code in the stored procedure:

    create or replace PROCEDURE p_mv_refresh (p_refgrp IN VARCHAR2) AS

    v_refgrp all_refresh_children.rname%TYPE;

    BEGIN
    v_refgrp: = UPPER (p_refgrp);
    DBMS_REFRESH. Refresh (v_refgrp);
    end;

    Here is the definition of the refresh Group:

    exec dbms_refresh.make (name = > 'BENEFITS_REFGRP',-)
    list = > 'MV_INDIVIDUAL_CUR, MV_CCR_CUR, MV_BUSINESS_DBA_CUR, -.
    next_date = > sysdate;
    interval = > NULL,--
    implicit_destroy = > FALSE;
    Lax = > FALSE;
    rollback_seg = > NULL,--
    push_deferred_rpc = > FALSE;
    refresh_after_errors = > FALSE;
    purge_option = > NULL,--
    parallelism = > 8, -.
    heap_size = > NULL);

    I run in SQLPLUS by passing the name of the refresh Group in the stored procedure:

    SQL > exec p_mv_refresh ('BENEFITS_REFGRP');

    And I get this:

    Error: ORA-12048: error in materialized view Refresh
    'UIMVIEWS '. "" MV_BUSINESS_DBA_CUR ".
    ORA-00942: table or view does not exist

    When I have exec dbms_refresh.refresh('BENEFITS_REFGRP') directly in SQLPlus, everything runs without failure.

    Here is the definition of MV:

    CREATE THE MV_BUSINESS_DBA_CUR MATERIALIZED VIEW
    ON PREBUILT TABLE
    COMPLETE REFRESH
    DISABLE THE QUERY REWRITE AS
    (SELECT *)
    OF xxxxxxxx...) ;

    There is no newspaper of MV on the source (no fast refresh) table.

    Table source and MV are same DB, different schemas.

    Just to be safe in tests, I attributed select privileges on the source table to the MV schema via a role and directly. Does not solve.

    New - the MV refreshes thin when done directly from a SQLPlus prompt. It fails only when I run it from within the stored proc.

    Thanks in advance for your suggestions...

    TonyG

    Here are additional info I posted:
    =========================================================================
    Here is an update - I tried the same procedure only this time replaced the call to dbms_refersh with a call to dbms_mview, just to see if he would run.

    This isn't. I am quite sure, I hit a kind of question of privilege that has to do with a package requiring a package, but I don't know enough with what it might be. dbms_mview works fine from the command line, just like the fact dbms_refresh.

    Here's what happened when I called the proc dbms_mview

    Error: ORA-12008: error in the path of refresh materialized view
    ORA-00942: table or
    view does not exist
    =========================================================================

    Thanks in advance for any help.

    A stored procedure does not inherit from grants of role, you must make grants directly to the relevant tables/views/mast views and can not give these permissions to the roles of througth.

    Date of arrival:
    http://download.Oracle.com/docs/CD/B10500_01/server.920/a96524/c24privs.htm#4770--> blocks named with copyright

    Published by: Pedro_gloria on 10-Dec-2010 07:54

  • Multiple sub-programs within a procedure call

    I'm trying to program it in pl/sql for the program that is already written in cobol. The program in cobol has several programs, but they use or access multiple variables used in other programs. As create of these subprograms in separate proceedings (with a pass), it will take several variables back, I built subprocedured in a procedure so that they can share these common variables. Problem arises when these Subprocedures call new procedure that are common to the other Subprocedures.
    Example of

    Create or replace procedure that x is

    -Sub procedure
    procedure as A1
    Start
    --
    b;-will call the sub sub procedure, which shares many variables
    --
    end;

    procedure as a2
    Start
    --
    b; -call Sub procedure sub who shares many variables
    --
    end;

    procedure b as
    Start
    null;
    end;


    Start
    A1; -subprocedure that shares many variables
    A2; -subprocedure that shares many variables

    end;
    Question is how to write sub sub procedure b? Compilation top says this sub b procedure should be defined as part of a1 and a2 procedures that I will be duplication b. procedure (because there are many variables in the procedure b uses whats in other proceedings, I don't want to create a separate procedure within the package passing - variable input and output variables). Can someone please suggest a solution for this? Appreciate the answer on that.

    Published by: vamadeva July 27, 2010 12:08

    Published by: vamadeva July 27, 2010 12:10

    It is the forward declaration. You must program Sub B before you make calls in the procedure of A1 and A2.

    Create or replace procedure X is
    
    ---subprogram b---
    procedure b as
    begin
    null;
    end;
    
    --subprocedure
    procedure a1 as
    begin
    --
    b;--will call sub sub procedure which shares many variables
    --
    end;
    
    procedure a2 as
    begin
    --
    b; --will call sub sub procedure which shares many variables
    --
    end;
    
    begin
    a1; -- subprocedure which shares many variables
    a2; --subprocedure which shares many variables
    
    end;
    

    Try this out, surely it would work.

  • Droping a table from within a procedure by passing the name of the Table as an Argument

    HII All

    I want to remove a table from a procedure dynamically passing the table name as a parameter of a procedure manual

    to do this, I wrote the following procedure

    CREATE OR REPLACE PROCEDURE DEL_TAB (TAB_NAME IN VARCHAR2) AS

    V_TAB_NAME VARCHAR2 (10);

    V_STMT VARCHAR2 (50);

    BEGIN

    V_TAB_NAME: = TABLE_NAME;

    V_STMT: = 'DROP TABLE' | V_TAB_NAME;

    RUN IMMEDIATELY 'V_STMT ';

    DBMS_OUTPUT. PUT_LINE(V_TAB_NAME||) e TABLE DELETED ');

    END DEL_TAB;

    but whenever I'm execute it gives me an error

    ERROR on line 1:

    ORA-06550: line 1, column 15:

    PLS-00357: Table, view or sequence of reference 'A' not allowed in this context

    ORA-06550: line 1, column 7:

    PL/SQL: Statement ignored

    Please tell me the solution...

    Thanks in advance

    Alisson

    Why do you want to implement this procedure? If you want to remove a table just issue the DROP of stand-alone statement. Why write a procedure for this? Also you must understand the difference between REMOVE and DROP in the context of RDBMS. You either use them which is incorrect. DELETION is to remove rows from a table and DROP is to remove the database table.

    And with regard to your problem

    > RUN IMMEDIATELY 'V_STMT ';

    This should be

    immediately run v_stmt;

    You closed the V_STMT variable is in single quotes. You must remove the apostrophes.

  • Dynamic insertion within the procedure error


    Hi all

    I use under oracle database on HP - UX.

    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE Production 10.2.0.5.0
    AMT for HP - UX: 10.2.0.5.0 - Production Version
    NLSRTL Version 10.2.0.5.0 - Production

    I'm not able to run the procedure below and it returns the error. The insert in the procedure returns error. If I execute manually only the insert statement, it works well.
    Can someone help me with this issue?

    Procedure
    ===========
    create or replace procedure test_proc
    as
    v_sql varchar2 (2000);
    Start
    v_sql: =' insert into TABLE1 (select owner, object_type, object_name, "S", "Y" of dba_objects@LINK1 )
    where owner = "ABC" and object_type = "TABLE" less
    Select the owner, object_type, object_name, "S", "Y" from dba_objects where owner = "ABC" and object_type = "TABLE") ';

    immediately run v_sql;
    commit;
    end;
    /

    exec test_proc;

    Error:
    ===========

    ERROR on line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "SYSTEM. TEST_PROC", line 8
    ORA-06512: at line 1

    user running this procedure doesn't have permission to read data from DBA_OBJECTS. Grant select permission on that to the user running this procedure and it should work.

    Onkar

  • Reg: inserting values using procedures in odi

    Hello

    Hello everyone, I have a requirement like values are inserted into the table of DBMS using the odi procedure very.

    I use this procedure in a package, this package including refresh variables so that it runs several times using County.

    I'm trying to insert values into the table, the table is empty. so when I am trying to run this package I get error like

    This

    ODI-1228: Dailyfileloads task (procedure) insertion fails on the target of ORACLE DSS_ORACLE connection.
    Caused by: java.sql.SQLSyntaxErrorException: ORA-00917: Missing comma

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:889)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:476)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:204)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:540)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:217)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1079)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1466)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3752)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3937)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1535)
    at oracle.odi.runtime.agent.execution.sql.SQLCommand.execute(SQLCommand.java:163)
    at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:102)
    at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:1)
    at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2906)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2609)
    at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:537)
    at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:453)
    at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1740)
    to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ 2.doAction(StartSessRequestProcessor.java:338)
    at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:214)
    at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:272)
    to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$ 0 (StartSessRequestProcessor.java:263)
    to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ StartSessTask.doExecute (StartSessRequestProcessor.java:822)
    at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:123)
    to oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$ 2.run(DefaultAgentTaskExecutor.java:82)
    at java.lang.Thread.run(Thread.java:662)

    I'm not able to solve this please help me.

    Code of procedure like this: insert into dailyload_apmstr (FILENAME) values (DSS. #sample);

    Kind regards
    Sri

    Can you please close the thread marking the answers that help complete or correct

  • How to filter data in cursors within the procedure

    Hello

    Yesterday, I tried all night, but couldn't do it.

    I know that is incomplete, I just want to know how to filter the data based on the setting in

    Basically, here I want to get only the records that match the id_fichier


    create or replace PROCEDURE clearing_details (p_file_id in varchar2)
    IS
    strStatusCode VARCHAR2 (6);
    CURSOR PD1 IS
    SELECT COUNTRY_CODE, EOD_MARK OF LINK_STATUS WHERE FILE_ID is p_file_id


    Can someone help me on this please:


    Thanks for reading.

    Does do the same if you run the query itself in SQL * Plus with the same value you pass as a parameter?

    Without seeing your data and which parameter you're passing, we will fight help more as the concept itself works great as you have been demonstrated.

  • Creating views, dynamic SQL within stored procedure

    I'm having a problem with the creation of dynamic views of in a stored procedure. The following declare block works fine:

    DECLARE
    parameter i_nom_table varchar2 (200): = 'abc ';
    xyz cursor script, SELECT step
    STARTING from scripts
    WHERE table_name = i_nom_table parameter
    ORDER BY step CAD;
    l_sql scripts.script%TYPE;
    l_step scripts.step%TYPE;
    l_error VARCHAR2 (200);
    l_code VARCHAR2 (200);
    Start
    XYZ OPEN;
    LOOP
    XYZ-FETCH INTO l_step, l_sql;
    OUTPUT WHEN xyz % NOTFOUND;
    immediately run l_sql;
    insert into ingest_log values (null, sysdate, i_nom_table, l_step, l_sql, 'Success' parameter);
    END LOOP;
    CLOSE XYZ;
    insert into ingest_log values (null, sysdate, parameter i_nom_table, 0, "Accomplished all the steps.", "Success");
    EXCEPTION WHEN OTHERS THEN
    l_error: = substr (SQLERRM, 1, 200);
    l_code: = SQLCODE;
    insert into ingest_log values (null, sysdate, parameter i_nom_table, l_step, l_sql, l_code |) ' - ERROR - ' | l_error);
    END;

    However, if I create a procedure with this block and try to run it I get an insufficient privileges error. Do not know why. All tables, views, procedures are under the same user, and the user that I'm connected as the runtime of the declare block. The user has the following privileges:

    Connect, resource, xdbadmin, s/n

    Any reason you can think of for this? Script values are generally "CREATE OR REPLACE VIEW As.... » ;

    Permissions in Oracle to do indirectly through roles are not available when compiling packages, functions, and stored procedures. Direct subsidies are required during the creation of these objects in the database.

    http://articles.TechRepublic.com.com/5100-10878_11-6183799.html

  • Reg:-grant to the procedure.

    Hi friends,
    I want to give Executre grant to the other diagram how to give...
    Example:-Package stored in Schema1

    But I want to run this package through schema to.

    Pls help.

    Kind regards
    Aude
    grant execute on PROCEDURE to SCHEMA;
    

    Make sure you have either a synonym for the procedure or it is referenced using the procedures scheme
    for example, MySchema.myprocedure

  • 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
    
  • APEX email in external procedure

    I'm going gray on this... What don't get me?

    DECLARE


    I have a procedure in this case called proc_name.
    I have other tasks to recurring scheduler that runs under the same syntax that work very well and have for years;
    I am running DB 11.2 and 4.2 APEX

    BEGIN


    I'm just trying to implement another Planner position to warn users in 60 days to a deadline.
    I can confirm that the FOR LOOP in the procedure returns values.

    I'm using the syntax is the following: I can't remember where he comes and also can't explain p_protocol or p_flow_id - but it works in other proceedings...


    Proc_name (p_sgid = > VALID_SECURITY_ID p_protocol = > 'http://DB_SERVER_FQDN/pls/apex/', p_flow_id = > '200');


    content of the procedure is:
    p_sgid in NUMBERS
    p_flow_id in VARCHAR2

    values within the procedure:
    wwv_flow_api.set_security_group_id (p_security_group_id = > p_sgid);
    apex_application.g_flow_id: = p_flow_id;

    The mail bit comes later...

    20001 when I start work without exceptions I get ORA-: this procedure must be called from a session of the application.
    This means for me that the security_id is not passed but does not explain why other procedures work fine. under the same user.

    I hope that some of this means something to someone!

    END;

    Hi Samuistu,

    Samuistu wrote:

    I'm going gray on this... What don't get me?

    The mail bit comes later...
        20001 when I start work without exceptions I get ORA-: this procedure must be called from a session of the application.
    This means for me that the security_id is not passed but does not explain why other procedures work fine. under the same user.
    I hope that some of this means something to someone!

    Yes. To call the APEX_MAIL package from outside the context of a request for Application Express, you must call APEX_UTIL. SET_SECURITY_GROUP_ID to set the context of APEX Session as follows:

    PROCEDURE PRC_SEND_EMAIL ( P_PARAM1  IN VARCHAR2
                               ...
                             , P_PARAM2  IN VARCHAR2
                             , P_APP_ID  IN NUMBER )
    AS
    -- variable declarations
    BEGIN
    
      -- set APEX session context
      FOR C1 IN ( SELECT WORKSPACE_ID
                    FROM APEX_APPLICATIONS
                  WHERE APPLICATION_ID = P_APP_ID )
      LOOP
        APEX_UTIL.SET_SECURITY_GROUP_ID(P_SECURITY_GROUP_ID => C1.WORKSPACE_ID);
      END LOOP;
    
      -- mail sending code using APEX_MAIL
    
    END PRC_SEND_EMAIL;
    

    NOTE: You can define constant G_APP_ID in your package and set it to your application number to use instead of P_APP_ID in the code above.

    See the documentation for APEX_MAIL: https://docs.oracle.com/cd/E37097_01/doc.42/e35127/apex_mail.htm#AEAPI341

    (See the first section of the 'Note')

    Kind regards

    Kiran

  • insufficient privileges when you create sequence using the procedure

    CREATE OR REPLACE PROCEDURE schema1.proc1 AS
    BEGIN
    EXECUTE IMMEDIATE 'DROP SEQUENCE schema1.add_ins_seq';
    EXECUTE IMMEDIATE 'CREATE SEQUENCE schema1.add_ins_seq MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 1000 NOORDER  NOCYCLE';
    END;
    

    This procedure is created to schema1 by schema1.

    Schema1 boasts a CREATE SEQUENCE privilege.

    When I run this procedure through SQL Developer after the Cup to schema1, the error is thrown in insufficient privilege to CREATE SEQUENCE, however, DROP SEQUENCE is executed. I can create the sequence without the procedure call.

    If I add AUTHID CURRENT_USER so I don't get the error of insufficient privileges.

    Why it gives this error when the owner and the applicant of the procedure is schema1?

    Hello

    1st thing to know: when a procedure is defined (and updated), any privileges granted through ROLE is not taken into account. This is because these privileges can be active or not at the level of the session (as happens if for example a user has active 'role A' in session 1 but not in session 2 and if this role has been used to define a procedure?) The proecedure must at the same time be VALID in session 1 and INVALID session 2? Is not possible.

    Thus, for instance in a situation of 'standard': user SYSTEM has 'DBA Rôle', so you can for example make a sqlplus session "SELECT * v $ instance;", but you would write a procedure owned by system making instance_name SELECT INTO l_variable OF v$ instance;  "then"surprise": the procedure cannot be compiled because of the ORA-904 Table or view does not exist..." To be able to create the procedure, a DSS system needs to be done.

    2nd thing for your special case, a little more complex: default for a procedure is 'AUTHID DEFINE', but once more: it means "privileges of the author creating the procedure", so without taking into account the acquired privileges through roles... Your user name is 'sequence create' through a role, it cannot use the privilege within the procedure.  But... but when you define the procedure with AUTHID CURRENT_USER, privileges are evaluated at run time, and thanks to the active ROLE in the session by calling the procedure, at this time, the user can create the sequence.  If try again you but with 'The VALUE NONE ROLE' in the session before the call, you will again have the question.

    Conclusion: If you need to do the action, you must grant the user the necessary privilege directly.

    Best regards

    Bruno Vroman.

  • How do I inject inside the ODI 11 G PL/SQL (not function procedure)

    Hello Expert,

    would be like double until OWB and ODI OWB 11 G I wich 'The user function' run PL/SQL and it remove some data in the table and the reel journal, is possible that I can do the same thing in ODI, in my case, I can't call function, or a procedure stored outside the ODI. See below the part of the PL/SQL based on user OWB.

    coil MyFile... Journal

    command prompt

    create table MyTable as

    Select a.*

    Of...

    commit;

    command prompt

    spool off;

    "exit";

    Thank you!

    You can run a PL within a procedure, you simply copy paste your PL and place in a procedure inside the ODI.

    I hope this can help you!

  • ORA-06565: cannot run the ROLE VALUE from stored procedures

    Hello!

    I'm trying to call a procedure from a function. Among the statements in the procedure stored is of dbms_session.set_role ('HAVE');

    I get the error "Cannot run a DEFINED ROLE less stored proceduers". I joined the call in an anonymous block above, but the error still exists.

    Any idea will really help me.

    Thank you

    >
    I'm trying to call a procedure from a function. Among the statements in the procedure stored is of dbms_session.set_role ('HAVE');

    I get the error "Cannot run a DEFINED ROLE less stored proceduers". I joined the call in an anonymous block above, but the error still exists.

    Any idea will really help me.
    >
    This will work only if the procedure is defined for the APPELLANT's rights.

    Roles are disabled in named PL/SQL blocks unless you use of the APPELLANT's rights by setting the code with AUTHID CURRENT_USER.

    The Oracle documentation provides a very clear explanation - based restriction is for the NAMED PL/SQL blocks rights DEFINER of this use (the default):
    >
    Roles used in the appointed with rights to define blocks

    All roles are disabled in any PL/SQL block named (stored procedure, function, or trigger) that runs with the rights of the author. Roles are not used to privilege control, and you cannot define roles within the procedure of a DEFINER rights.
    >
    The database Security Guide has the information in the section "operation of the roles in PL/SQL blocks (which, of course, wouldln was necessary if they didn't work.).
    http://docs.Oracle.com/CD/B28359_01/network.111/B28531/authorization.htm#i1007304
    >
    The use of roles in a PL/SQL block depends on if it is an anonymous block, or a block named (stored procedure, function, or trigger), and if it runs with the rights of the author or the rights of the applicant.

    Roles used in the appointed with rights to define blocks
    All roles are disabled in any PL/SQL block named (stored procedure, function, or trigger) that runs with the rights of the author. Roles are not used to privilege control, and you cannot define roles within the procedure of a DEFINER rights.

    The SESSION_ROLES view shows all roles that are currently enabled. If a named PL/SQL block that runs with DEFINER SESSION_ROLES rights issues, the query returns no rows.

    See also:

    Oracle database reference

    Roles used in blocks named with the rights of the plaintiff and anonymous PL/SQL
    Named PL/SQL blocks that run with the rights of the applicant and the anonymous PL/SQL blocks are executed at the end of the privileges granted through active roles. Current roles are used for verification within rights Summoner of privilege the PL/SQL block. You can use dynamic SQL statements to define a role in the session.

Maybe you are looking for

  • Photo very slow download on iCloud drive, Mac Air 2009, El Capitan

    I hope someone can help... I installed El Capitan on my Mac Air since end 2009 and since improved Air and iPads to iCloud by car. Are my approximately 9000 pictures on Mac Air download at a speed of max 50 per hour. Also I don't see any files or fold

  • 9.3.1 iOS used to install on the iPhone 6

    I tried several times to install the new ios and it won't work.  It downloads the update well and then goes through the installation process but comes back with an error: "cannot install update.» Year error occurred installing iOS 9.3.1. "" Try again

  • Where a document?

    Then the option to search in OS X works very well and is very fast, I find it almost impossible to understand where the document that I found. At the same time, I was able to select a document in the search results, press command-I and an 'info' on t

  • Bug in Riched20.dll using EM_STREAMOUT XP

    Hello It seems that something has broken my routine to read RTF controls - at least I remember it working earlier. I get the first (and only) fragment of it in p_szB of my structure but then it crashes after that my routine is back. struct RTFdumpInf

  • How can I unlock my hotmail account

    When I try to log in I get a message "your account is blocked."