Using APEX_MAIL from within a procedure invoked from DBMS_JOB

I have done a lot of googling and wasted a couple of days getting nowhere and would appreciate some help. But I do know that in order to use APEX_MAIL from within a DBMS_JOB that I should
"In order to call the APEX_MAIL package from outside the context of an Application Express application, you must call apex_util.set_security_group_id as in the following example:
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;
I have created a procedure that includes the above (look towards the end)
create or replace procedure VACANCIES_MAILOUT
(p_application_nbr number,
p_page_nbr number,
p_sender varchar2)
AS
Purpose: Email all people registerd in MAILMAN [email protected]
with details of any new vacancies that started listing today.
Exception
when no_data_found
then null;
when others then raise;
l_body CLOB;
l_body_html CLOB;
l_vacancy_desc VARCHAR2(350);
to_headline varchar2(200);
to_org varchar2(100);
l_vacancies_desc varchar2(2000);
to_workspace_id number(22);
CURSOR vacancies_data IS
select DISTINCT v.headline to_headline,
ou.org_name to_org
from VACANCIES v,
Org_UNITS ou
where
ou.org_numb = v.Org_Numb
and v.public_email_sent_date is Null
Order by ou.org_name, v.headline;
BEGIN
BEGIN
FOR vacancies_rec in vacancies_data
-- build a list of vacancies
loop
BEGIN
l_vacancy_desc := '<br><b>' ||
vacancies_rec.to_org || '<br>' ||
vacancies_rec.to_headline || '</b><br>';
-- l_vacancy_desc :=
-- vacancies_rec.to_org || ' - ' ||
-- vacancies_rec.to_headline ;
l_vacancies_desc := l_vacancies_desc || l_vacancy_desc;
END;
END LOOP;
END;
l_body := 'To view the content of this message, please use an HTML enabled mail client.'||utl_tcp.crlf;
l_body_html :=
'<html>
<head>
<style type="text/css">
body{font-family:  Verdana, Arial, sans-serif;
                               font-size:11pt;
                               margin:30px;
                               background-color:white;}
span.sig{font-style:italic;
font-weight:bold;
color:#811919;}
</style>
</head>
<body>'||utl_tcp.crlf;
l_body_html := l_body_html || l_vacancies_desc
|| '<p>-----------------------------------------------------------------------------------------------------------------</strong></p>'
||utl_tcp.crlf
|| '<p>The above new vacancies have been posted on the <strong>Jobs At Murdoch</strong> website.</p>'
||utl_tcp.crlf
||'<p>For futher information about these vacancies, please select the following link</p>'
||utl_tcp.crlf
||'<p> Jobs At Murdoch </p>'
||utl_tcp.crlf
||'<p></p>'
||utl_tcp.crlf;
l_body_html := l_body_html
||' Regards
'||utl_tcp.crlf
||' <span class="sig">Office of Human Resources</span>
'||utl_tcp.crlf;
for c1 in (
select workspace_id
from apex_applications
where application_id = 1901)
loop
apex_util.set_security_group_id(p_security_group_id => c1.workspace_id);
end loop;
apex_mail.send(
p_to => '[email protected]',
p_from => '[email protected]',
p_body => l_body,
p_body_html => l_body_html,
p_subj => 'Jobs At Murdoch - new vacancy(s) listed');
update VACANCIES
set public_email_sent_date = trunc(sysdate,'DDD')
where public_email_sent_date is null;
commit;
END;
but still get the error
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /oracle
System name: Linux
Node name: node
Release: 2.6.18-194.17.1.el5
Version: #1 SMP Mon Sep 20 07:12:06 EDT 2010
Machine: x86_64
Instance name: instance1
Redo thread mounted by this instance: 1
Oracle process number: 25
Unix process pid: 5092, image: (J000)
*** 2011-07-12 09:45:03.637
*** SESSION ID:(125.50849) 2011-07-12 09:45:03.637
*** CLIENT ID:() 2011-07-12 09:45:03.637
*** SERVICE NAME:(SYS$USERS) 2011-07-12 09:45:03.637
*** MODULE NAME:() 2011-07-12 09:45:03.637
*** ACTION NAME:() 2011-07-12 09:45:03.637
ORA-12012: error on auto execute of job 19039
ORA-20001: This procedure must be invoked from within an application session.
ORA-06512: at "APEX_040000.WWV_FLOW_MAIL", line 290
ORA-06512: at "APEX_040000.WWV_FLOW_MAIL", line 325
ORA-06512: at "APEX_040000.WWV_FLOW_MAIL", line 367
ORA-06512: at "HRSMENU_TEST.VACANCIES_MAILOUT", line 94
ORA-06512: at line 1
Can someone please tell me what what stupid thing I am doing wrong? The procedure worked when invokded from SQL Workshop but fails in a DBMS_JOB.
much thanks Peter

I think that might help...
http://www.easyapex.com/index.php?p=502
Thanks to EasyApex..
LK

Similar Messages

  • PL/SQL: Executing a procedure from within another procedure

    Hello, I'm a newbie and I need help on how to execute procedures from within another procedure. The procedure that I call from within the procedure have return values that I want to check.
    I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    but I get the error message:
    PLS-00103: Encountered the symbol "USER_GET_FORUM_INFO" when expecting one of the following::= . ( @ % ; immediate
    The symbol ":=" was substituted for "USER_GET_FORUM_INFO" to continue.
    And when I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    I get the error message:
    PLS-00222: no function with name 'USER_GET_FORUM_INFO' exists in this scope
    PL/SQL: Statement ignored
    The procedure USER_GET_FORUM_INFO exists. (don't understand why it says "no FUNCTION with name", it's a procedure I'm executing)
    I'm stuck so thanks for any help...
    Below is all the code. I'm using Oracle 9i on RedHat Linux 7.3.
    ================================================================================
    CREATE OR REPLACE PROCEDURE user_forum_requestsaccess (
    p_forumid IN NUMBER,
    p_requestmessage IN VARCHAR2
    AS
    var_forumid NUMBER;
    var_forum_exists NUMBER;
    var_forum_access NUMBER;
    request_exists NUMBER;
    var_forumname VARCHAR2(30);
    FORUM_DOESNT_EXIST EXCEPTION;
    FORUM_USER_HAS_ACCESS EXCEPTION;
    FORUM_REQUEST_EXIST EXCEPTION;
    BEGIN
    SELECT SIGN(NVL((SELECT request_id FROM forum.vw_all_forum_requests WHERE forum_id = p_forumid AND db_user = user),0)) INTO request_exists FROM DUAL;
    EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    IF var_forum_exists = 0 THEN
    RAISE FORUM_DOESNT_EXIST;
    ELSIF var_forum_access = 1 THEN
    RAISE FORUM_USER_HAS_ACCESS;
    ELSIF request_exists = 1 THEN
    RAISE FORUM_REQUEST_EXIST;
    ELSE
    INSERT INTO tbl_forum_requests VALUES (SEQ_TBL_FORUM_REQ_REQ_ID.NEXTVAL, SYSDATE, p_requestmessage, p_forumid, user);
    INSERT INTO tbl_forum_eventlog VALUES (SEQ_TBL_FORUM_EVNTLOG_EVNT_ID.NEXTVAL,SYSDATE,1,'User ' || user || ' requested access to forum ' || var_forumname || '.', p_forumid,user);
    COMMIT;
    END IF;
    EXCEPTION
    WHEN
    FORUM_DOESNT_EXIST
    THEN RAISE_APPLICATION_ERROR(-20003,'Forum doesnt exist.');
    WHEN
    FORUM_USER_HAS_ACCESS
    THEN RAISE_APPLICATION_ERROR(-20004,'User already have access to this forum.');
    WHEN
    FORUM_REQUEST_EXIST
    THEN RAISE_APPLICATION_ERROR(-20005,'A request to this forum already exist.');
    END;
    GRANT EXECUTE ON user_forum_requestsaccess TO forum_user;
    ================================================================================
    Regards Goran

    you don't have to use execute when you want to execute a procedure (only on sql*plus, you would use it)
    just give the name of the funtion
    create or replace procedure test
    as
    begin
        dbms_output.put_line('this is the procedure test');
    end test;
    create or replace procedure call_test
    as
    begin
        dbms_output.put_line('this is the procedure call_test going to execute the procedure test');
        test;
    end call_test;
    begin
        dbms_output.put_line('this is an anonymous block calling the procedure call_test');
        call_test;
    end;
    /

  • Create a text file output from within a procedure

    I can output to a file from within SQL+ using the spool command but how do I do this from within a procedure?
    I have got a table called ABC and want to output columns A and B to a new text file based on variables pased through when the procedure is run, the name of the text file should be generated from a sequence?
    Any info appreciated.
    Cheers
    Cliff

    Hi,
    U can use UTL_File Package, But the only constraint is it will write the file only on the server m/c and not on the client m/c.
    Regards
    Gaurav

  • Shrink file (log) from within a procedure

    I'd like to incorporate the DBCC shrinkfile command to my maintenance procedure. This procedure gets called after I've finished my weekly importing process. I only need to shrink the log files as almost all the modifications are either a record update or
    an insert (there are very few deletions done). I need to do this across several databases and for software maintainability would prefer to have only the one procedure.
    My issue is that there does not seem to be a way to point to the various databases from within a procedure to preform this operation. Also the maintenance plan modules have a shrink database operation but I don't see a shrink file operation so that doesn't
    appear to be an option.
    Have I overlooked something or is it not possible to preform a shrink file operation for the transaction log files for multiple databases?
    Developer Frog Haven Enterprises

    Thank you for your response. While I did not use your answer verbatim it did lead me to my solution as I only need to preform the shrink operation on 4 out of the 7 databases in my SQL instance.
    FYI my final solution was...
    -- shrink the log files
    DECLARE @sql
    nvarchar(500);
    SET @sql
    =
    'USE [vp]; DBCC SHRINKFILE (2, 100);';
    EXEC
    (@sql);
    SET @sql
    =
    'USE [vp_arrow]; DBCC SHRINKFILE (2, 100);';
    EXEC
    (@sql)
    Developer Frog Haven Enterprises

  • How to call a procedure from within another procedure?

    What's the syntax to call a procedure from within a procedure.
    I have a procedure z(user_id IN number, ....)
    then
    procedure a (user_id IN number, ....)
    procedure b (user_id IN number, ....)
    procedure c (user_id IN number, ....)
    I want to call procedure a, b, c from inside procedure z.
    How would I do that?

    Same way :
    SCOTT@db102 SQL> create or replace procedure a (p1 in varchar2) is
      2  begin
      3     dbms_output.put_line (p1);
      4* end;
    SCOTT@db102 SQL> /
    Procedure created.
    SCOTT@db102 SQL> create or replace procedure z (par1 in number) is
      2  begin
      3     if par1 != 0 then
      4             a ('This is proc a');
      5     end if;
      6* end;
    SCOTT@db102 SQL> /
    Procedure created.
    SCOTT@db102 SQL> set serveroutput on
    SCOTT@db102 SQL> exec z (1);
    This is proc a
    PL/SQL procedure successfully completed.
    SCOTT@db102 SQL>                                                    

  • Running unix commands from within a procedure

    Oracle 11.1, AIX 6.1
    ================
    A developer would like to know what the commands are to execute from within a procedure to run unix commands on the database server and capture those results back to the procedure for parsing & manipulation.
    Thanks.

    Don't take this as the correct way to do it, but this is merely 'a' way to do it:
    have a db procedure thats executes a db function
    create or replace procedure csproc(p_cmd in varchar2)
    as
    x number;
    begin
    x:=csfunc(p_cmd);
    dbms_output.put_line('x is: '||x);
    end;
    /The function calls a piece of java to execute the os command and return the return code of the os command
    create or replace function csfunc( p_cmd  in varchar2) return number
    as language java
    name 'csclass.RunThis(java.lang.String[]) return integer';
    /Here is the java class to run the os command
    create or replace and compile java source
    named "csclass"
    as
    import java.io.*;
    import java.lang.*;
    public class csclass extends Object
    public static int RunThis(String[] args)
       Runtime rt = Runtime.getRuntime();
        int        rc = -1;
        try
           Process p = rt.exec(args[0]);
          int bufSize = 4096;
           BufferedInputStream bis =
           new BufferedInputStream(p.getInputStream(), bufSize);
           int len;
           byte buffer[] = new byte[bufSize];
           // Echo back what the program spit out
           while ((len = bis.read(buffer, 0, bufSize)) != -1)
              System.out.write(buffer, 0, len);
           rc = p.waitFor();
        catch (Exception e)
           e.printStackTrace();
           rc = -1;
        finally
           return rc;
    /and finally the os command - in this case its a very simple shell script
    #!/usr/bin/ksh
    echo "Hi" >> /app/oracle/workdir/cs.logwill have to grant privileges to my user 'CS' to run the various os commands
    exec dbms_java.grant_permission('CS','java.io.FilePermission','/app/oracle/workdir/cs.ksh','read,execute');
    exec dbms_java.grant_permission('CS','java.io.FilePermission','/app/oracle/workdir/cs.log','write');
    exec dbms_java.grant_permission('CS','SYS:java.lang.RuntimePermission','*','readFileDescriptor');
    exec dbms_java.grant_permission('CS','SYS:java.lang.RuntimePermission','*','writeFileDescriptor');and finally can run the procedure from within the db
    set serveroutput on
    exec dbms_java.set_output(1000000);
    exec csproc('/app/oracle/workdir/cs.ksh');
    x is: 0
    PL/SQL procedure successfully completed.to prove it works ok the logfile shows an entry:
    'Hi'

  • I cannot ping any VIP from within the ACE or from rservers

    I cannot ping any VIP from within the ACE or from rservers.  Is this expected?  I have rservers in other serverfarms that need to be able to communicate with the VIP of other serverfarms.  Any help is greatly appreciated.

    Thanks for you reply.  here is the config.  I removed other rserver and serverfarm config that does not have to do with this issue.
    logging enable
    logging fastpath
    logging standby
    logging console 4
    logging timestamp
    logging trap 4
    logging history 4
    logging buffered 4
    logging persistent 4
    logging monitor 4
    logging device-id hostname
    logging host 172.26.254.185 udp/514
    logging host 172.26.221.25 udp/514
    access-list INBOUND line 8 extended permit ip any any
    access-list INBOUND line 16 extended permit icmp any any
    access-list INBOUND line 24 extended permit tcp any any
    access-list INBOUND line 32 extended permit udp any any
    access-list ORADB line 8 extended permit tcp any any
    probe http CITRIX
      interval 30
      passdetect interval 15
      passdetect count 6
      open 1
    probe tcp HYPERION
      port 19000
      interval 2
      faildetect 2
      passdetect interval 2
      passdetect count 2
      receive 2
      open 1
    probe icmp PROBE_SERVICE_ICMP
      interval 5
      passdetect interval 5
    probe tcp W15SPSWFET001_PROBE
      interval 5
      passdetect interval 5
      connection term forced
      open 1
    parameter-map type connection TIMEOUT
      set timeout inactivity 43200
    parameter-map type http test
      persistence-rebalance
      set header-maxparse-length 2006
    rserver host w0bairwatch003
      description MDM-SEG
      ip address 172.20.60.73
      inservice
    rserver host w0bairwatch004
      description MDM-SEG
      ip address 172.20.60.74
      inservice
    rserver host w0bairwatch005
      description MDM-DEVICE
      ip address 172.20.60.75
      inservice
    rserver host w0bairwatch006
      description MDM-DEVICE
      ip address 172.20.60.76
      inservice
    rserver host w0bhamobile001
      description Lotus Notes Traveler Server
      ip address 172.20.60.57
      inservice
    rserver host w0bhamobile002
      description Lotus Notes Traveler Server
      ip address 172.20.60.58
      inservice
    serverfarm host MDMDEVICE
      predictor leastconns
      probe PROBE_SERVICE_ICMP
      rserver w0bairwatch005
        inservice
      rserver w0bairwatch006
    serverfarm host MDMSEG
      predictor leastconns
      probe PROBE_SERVICE_ICMP
      rserver w0bairwatch003
        inservice
      rserver w0bairwatch004
        inservice
    serverfarm host TRAVLR
      predictor leastconns
      probe PROBE_SERVICE_ICMP
      rserver w0bhamobile001
        inservice
      rserver w0bhamobile002
        inservice
    class-map match-all MDMDEVICE-VIP
      2 match virtual-address 172.20.48.35 any
    class-map match-all MDMSEG-VIP
      2 match virtual-address 172.20.48.33 any
    class-map type management match-any REMOTE_ACCESS
      description Remote access traffic match
      201 match protocol ssh any
      202 match protocol telnet any
      203 match protocol icmp any
      204 match protocol https any
      205 match protocol http any
      206 match protocol xml-https any
      207 match protocol snmp any
    class-map match-all TRAVLR-VIP
      2 match virtual-address 172.20.48.34 any
    policy-map type management first-match REMOTE_MGMT_ALLOW_POLICY
      class REMOTE_ACCESS
        permit
    policy-map type loadbalance first-match MDMDEVICE
      class class-default
        serverfarm MDMDEVICE
    policy-map type loadbalance first-match MDMSEG
      class class-default
        serverfarm MDMSEG
    policy-map type loadbalance first-match TRAVLR
      class class-default
        serverfarm TRAVLR
    policy-map multi-match CLIENTS-VIPS
      class MDMDEVICE-VIP
        loadbalance vip inservice
        loadbalance policy MDMDEVICE
        loadbalance vip icmp-reply active
      class MDMSEG-VIP
        loadbalance vip inservice
        loadbalance policy MDMSEG
        loadbalance vip icmp-reply active
      class TRAVLR-VIP
        loadbalance vip inservice
        loadbalance policy TRAVLR
        loadbalance vip icmp-reply active
    interface vlan 48
      ip address 172.20.48.10 255.255.255.0
      access-group input INBOUND
      access-group output INBOUND
      service-policy input REMOTE_MGMT_ALLOW_POLICY
      service-policy input CLIENTS-VIPS
      no shutdown
    interface vlan 60
      ip address 172.20.60.10 255.255.255.0
      access-group input INBOUND
      access-group output INBOUND
      service-policy input REMOTE_MGMT_ALLOW_POLICY
      no shutdown
    ip route 0.0.0.0 0.0.0.0 172.20.48.1

  • How to use dbms_Scheduler.Create_Job from within stored procedure?

    Hello,
    using 10g (10.1.0.2.0) on Windows 2000 I had problems to create scheduler jobs from within a stored procedure (see example below). What easily succeeds using anonymous blocks failed when calling from a stored procedure, due to ORA-27486. Only when I compile the procedure with invoker's rights the call to dbms_Job.Create_Job is successfull!? From my knowledge there is no difference between invoker's and definer's rights, if I compile and call with the same user, is there?
    Does anyone know the reason for this behaviour or is it simply a bug?
    Have a nice day.
    Björn Hachmann
    Hamburg / Germany
    -- Example start.
    create table t
    a number(1),
    b date default sysdate
    create or replace procedure sched1
    is
    begin
    dbms_scheduler.create_job(
    job_name => 'TEST_JOB1',
    job_type => 'PLSQL_BLOCK',
    job_action => 'BEGIN insert into t values (1); END;',
    repeat_interval => 'freq=secondly',
    enabled => TRUE
    commit;
    end;
    create or replace procedure sched2
    authid current_user
    is
    begin
    dbms_scheduler.create_job(
    job_name => 'TEST_JOB2',
    job_type => 'PLSQL_BLOCK',
    job_action => 'BEGIN insert into t values (2); END;',
    repeat_interval => 'freq=secondly',
    enabled => TRUE
    commit;
    end;
    exec sched1; -- This call fails with ORA-27486.
    exec sched2; -- This call succeeds!
    /* Cleanup.
    exec dbms_scheduler.drop_job('TEST_JOB1', true);
    exec dbms_scheduler.drop_job('TEST_JOB2', true);
    drop table t;
    */

    Your example code ran without problems for me on 10.1.0.3.0 so it probably is a bug.

  • Help!How can I find the name of a calling procedure from within a procedure/function?

    Is there anyway to find out the name of calling procedure(database) from within a database stored procedure/function? This is required for creating an auditing module.
    Thanks,
    Abraham
    ===========
    email:[email protected]

    You can use this query to get the procedure names that are calling your procedure.
    SELECT name FROM all_Dependencies
    WHERE upper(referenced_name) = 'YOUR_PROC_NAME'
    In your procedure, you can get these values into a cursor and then use them one by one.
    Hope this would help.
    Faheem

  • Why do I have to allow a new window every time to open from within another window, Ie, from an email?

    When I try to go to a web site from another web site or from an email from a link, I am required to click on the "ALLOW" button every time. It seems like if I have already clicked on it that I have allowed it. It is very frustrating. If it can't be fixed, I will either go back to an older version of firefox or choose another browser

    hello, you can disable these warnings, when you go to ''firefox > preferences > advanced > general > warn me when websites try to redirect or reload the page''.

  • Calling a procedure from within a procedure

    Hi Guys,
    I have created a package to base a form on. The package contains some procedures, one of which is an Update procedure which can be seen below. I have a procedure in another package that I am trying to call. Basically the second procedure is called to implement a constraint. However, I am unsure as to what I should pass into this procedure, as a package/procedure for basing a form on is different to what I have come across before.
    CREATE OR REPLACE package staff_dml IS
    TYPE staff_rec IS RECORD (staff_id NUMBER(7),
              first_name VARCHAR2(20),
              last_name VARCHAR2(20),
              tel_no NUMBER(11),
              manager_id NUMBER(7),
              position VARCHAR2(20),
    rest_id NUMBER(7),
              grade VARCHAR2(1),
              wage NUMBER(7,2));
    TYPE staff_cursor IS REF CURSOR RETURN staff_rec;
    TYPE staff_table IS TABLE OF staff_rec INDEX BY BINARY_INTEGER;
    PROCEDURE staff_update (data IN OUT staff_table);
    PROCEDURE staff_find (data IN OUT staff_cursor);
    PROCEDURE staff_lock (data IN OUT staff_table);
    END;
    CREATE OR REPLACE PACKAGE BODY staff_dml IS
    PROCEDURE staff_lock (data IN OUT staff_table)
    IS
    temp NUMBER;
    BEGIN
    SELECT staff_id into temp
    FROM staff
    WHERE staff_id = data(1).staff_id
    FOR UPDATE;
    END staff_lock;
    PROCEDURE staff_find (data IN OUT staff_cursor)
    IS
    BEGIN
    OPEN data FOR SELECT staff_id, first_name, last_name, tel_no, manager_id, position, rest_id, grade, wage
    FROM staff;
    END staff_find;
    PROCEDURE staff_update
    (data IN OUT staff_table)
    IS
    BEGIN
    IF data(1).wage != data(1).wage THEN
    special_pkg.staff_chk(data(1).wage,data(1).grade);
    END IF;
    IF data(1).grade != data(1).grade THEN
    special_pkg.staff_chk(data(1).wage,data(1).grade);
    END IF;
    UPDATE staff
    SET first_name = data(1).first_name, last_name = data(1).last_name, tel_no = data(1).tel_no, manager_id = data(1).manager_id,
    position = data(1).position, rest_id = data(1).rest_id, grade = data(1).grade, wage = data(1).wage
    WHERE staff_id = data(1).staff_id;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(SQLCODE||' '||SQLERRM);
    END staff_update;
    END;
    The area I an concerned about is:
    IF data(1).wage != data(1).wage THEN
    special_pkg.staff_chk(data(1).wage,data(1).grade);
    END IF;
    IF data(1).grade != data(1).grade THEN
    special_pkg.staff_chk(data(1).wage,data(1).grade);
    END IF;
    I do not know what I should be passing into the special_pkg.staff_chk procedure which accepts two number inputs. I want to use this package to compare the new inputs on this to the existing ones (this is carried out by the procedure. I have tried using :new. but this is not accepted. If I leave in the EXCEPTION then i get no errors from the form, but it will not save any changes I make on the database. If I remove the EXCEPTION then I get an error from the form - FRM-40735 UPDATE-PROCEDURE trigger raised unhandled exception ORA-04098. I am pretty sure this is because I am not supplying the correct variables to the called procedure,
    The called procedure is below (tested and working):
    PROCEDURE staff_chk
    (p_wage IN NUMBER,
    p_grade IN NUMBER)
    IS
    BEGIN
    IF p_wage BETWEEN 0 AND 7.00 AND p_grade != 'C' THEN
    RAISE_APPLICATION_ERROR(-20002, 'The Incorrect grade has been applied to this employee');
    ELSIF p_wage BETWEEN 7.01 AND 10 AND p_grade != 'B' THEN
    RAISE_APPLICATION_ERROR(-20003, 'The Incorrect grade has been applied to this employee');
    ELSIF p_wage BETWEEN 10.01 AND 20 AND p_grade != 'A' THEN
    RAISE_APPLICATION_ERROR(-20004, 'The Incorrect grade has been applied to this employee');
    END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('Staff member does not exist');
    END staff_chk;
    END;
    Any help would be greatly appreciated.
    Thanks,
    Anton

    Since this appears to be an Oracle Forms related question, you may want to pose it over in the Oracle Forms forum.
    Forms
    The folks over there are a lot more likely to be able to solve your problem.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Calling a procedure from within a procedure - dif to post below

    Hi Guys,
    I have created a package to base a form on. The package contains some procedures, one of which is an Update procedure which can be seen below. I have a procedure in another package that I am trying to call. Basically the second procedure is called to implement a constraint. However, I am unsure as to what I should pass into this procedure, as a package/procedure for basing a form on is different to what I have come across before.
    CREATE OR REPLACE package staff_dml IS
    TYPE staff_rec IS RECORD (staff_id NUMBER(7),
    first_name VARCHAR2(20),
    last_name VARCHAR2(20),
    tel_no NUMBER(11),
    manager_id NUMBER(7),
    position VARCHAR2(20),
    rest_id NUMBER(7),
    grade VARCHAR2(1),
    wage NUMBER(7,2));
    TYPE staff_cursor IS REF CURSOR RETURN staff_rec;
    TYPE staff_table IS TABLE OF staff_rec INDEX BY BINARY_INTEGER;
    PROCEDURE staff_update (data IN OUT staff_table);
    PROCEDURE staff_find (data IN OUT staff_cursor);
    PROCEDURE staff_lock (data IN OUT staff_table);
    END;
    CREATE OR REPLACE PACKAGE BODY staff_dml IS
    PROCEDURE staff_lock (data IN OUT staff_table)
    IS
    temp NUMBER;
    BEGIN
    SELECT staff_id into temp
    FROM staff
    WHERE staff_id = data(1).staff_id
    FOR UPDATE;
    END staff_lock;
    PROCEDURE staff_find (data IN OUT staff_cursor)
    IS
    BEGIN
    OPEN data FOR SELECT staff_id, first_name, last_name, tel_no, manager_id, position, rest_id, grade, wage
    FROM staff;
    END staff_find;
    PROCEDURE staff_update
    (data IN OUT staff_table)
    IS
    BEGIN
    IF data(1).wage != data(1).wage THEN
    special_pkg.staff_chk(data(1).wage,data(1).grade);
    END IF;
    IF data(1).grade != data(1).grade THEN
    special_pkg.staff_chk(data(1).wage,data(1).grade);
    END IF;
    UPDATE staff
    SET first_name = data(1).first_name, last_name = data(1).last_name, tel_no = data(1).tel_no, manager_id = data(1).manager_id,
    position = data(1).position, rest_id = data(1).rest_id, grade = data(1).grade, wage = data(1).wage
    WHERE staff_id = data(1).staff_id;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(SQLCODE||' '||SQLERRM);
    END staff_update;
    END;
    The area I an concerned about is:
    IF data(1).wage != data(1).wage THEN
    special_pkg.staff_chk(data(1).wage,data(1).grade);
    END IF;
    IF data(1).grade != data(1).grade THEN
    special_pkg.staff_chk(data(1).wage,data(1).grade);
    END IF;
    I do not know what I should be passing into the special_pkg.staff_chk procedure which accepts two number inputs. I want to use this package to compare the new inputs on this to the existing ones (this is carried out by the called procedure). I have tried using :new. but this is not accepted. If I leave in the EXCEPTION then i get no errors from the form, but it will not save any changes I make on the database. If I remove the EXCEPTION then I get an error from the form - FRM-40735 UPDATE-PROCEDURE trigger raised unhandled exception ORA-04098. I am pretty sure this is because I am not supplying the correct variables to the called procedure,
    The called procedure is below (tested and working):
    PROCEDURE staff_chk
    (p_wage IN NUMBER,
    p_grade IN NUMBER)
    IS
    BEGIN
    IF p_wage BETWEEN 0 AND 7.00 AND p_grade != 'C' THEN
    RAISE_APPLICATION_ERROR(-20002, 'The Incorrect grade has been applied to this employee');
    ELSIF p_wage BETWEEN 7.01 AND 10 AND p_grade != 'B' THEN
    RAISE_APPLICATION_ERROR(-20003, 'The Incorrect grade has been applied to this employee');
    ELSIF p_wage BETWEEN 10.01 AND 20 AND p_grade != 'A' THEN
    RAISE_APPLICATION_ERROR(-20004, 'The Incorrect grade has been applied to this employee');
    END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('Staff member does not exist');
    END staff_chk;
    END;
    Any help would be greatly appreciated.
    Thanks,
    Anton

    Hi,
    You triggered in fired on table and you procedure in acting is on the same table which rasing the exception.
    Go throw this link you will understand
    http://asktom.oracle.com/tkyte/Mutate/
    - Pavan Kumar N

  • Calling a Member Function from within a Cursor in a Procedure

    Hello Folks
    I'm a newbie to oracle and am in the process of learning 10G. My question is:
    I created a type called row_po and defined a member function getCost() which returns the total cost of the order with line items as nested table, which i intend to call from within a procedure. In the procedure my SELECT returns multiple records and hence I need to use a cursor. For each record I've got to display the order_no, qty and order_cost (qty and order_cost are part of a line items nested table). I'm able to get to the order_no and qty but don't know how to call the member function to get the order_cost. Here's my procedure:
    CREATE OR REPLACE PROCEDURE get_podet(part_num in number)
    AS
    CURSOR c2 is
    SELECT *
    FROM tab_po po, TABLE (po.LineItemList_nestab) L
    WHERE L.PartNo = part_num;
    BEGIN
    FOR crec in c2 LOOP
    DBMS_OUTPUT.PUT_LINE('ORDER NUMBER: ' || crec.PONo);
    DBMS_OUTPUT.PUT_LINE('LINE QTY: ' || crec.Qty);
    {color:#ff0000}*DBMS_OUTPUT.PUT_LINE('ORDER VALUE: ' || ''); -- order_cost which should be returned from the member function i've mentioned --*
    {color}END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Failed' || 'SQLCODE: ' || SQLCODE);
    DBMS_OUTPUT.PUT_LINE('SQL ERROR MESSAGE ' || SQLERRM);
    END;
    The line in red is where i want to call my function getCost() which is a member of tab_po po as mentioned in my SELECT.
    Any thoughts highly appreciated.
    Thanks and Regards

    One way would be to just run the query in a editor (sqlplus or toad) and see whats the column name.
    Before that can you show us the structure of the type.
    If you declare a table type without an object then the default column name is COLUMN_VALUE else the object filed name is taken.
    Example without object in table type.
    SQL> create or replace type tbl as table of integer
      2  /
    Type created.
    SQL> create or replace function fn return tbl
      2  as
      3     ltbl tbl;
      4  begin
      5     select level bulk collect into ltbl
      6       from dual
      7    connect by level <= 10;
      8
      9     return ltbl;
    10  end;
    11  /
    Function created.
    SQL> select * from table(fn)
      2  /
    COLUMN_VALUE
               1
               2
               3
               4
               5
               6
               7
               8
               9
              10
    10 rows selected.
    Example with object in table type.
    SQL> create or replace type obj as object(no integer)
      2  /
    Type created.
    SQL> create or replace type tbl as table of obj
      2  /
    Type created.
    SQL> edit
    Wrote file afiedt.buf
      1  create or replace function fn return tbl
      2  as
      3     ltbl tbl;
      4  begin
      5     select obj(level) bulk collect into ltbl
      6       from dual
      7    connect by level <= 10;
      8     return ltbl;
      9* end;
    10  /
    Function created.
    SQL> select * from table(fn)
      2  /
            NO
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.Edited by: Karthick_Arp on Jan 13, 2009 5:00 AM

  • Invokin SQL*Loader from a stored procedure

    I try to invoke SQL*LOADER from within a database package by using external C procedure (the procedure calls the system() C function) but the loader generates the following error in its log file :
    SQL*Loader -523: error -2 writing to file (STDERR)
    and no data is uploaded.
    I have tried to use system() from within database procedures to execute OS commands and it works. Does anyone know what is the problem with using system() to execute "sqlldr <parameters>"? Is there some other way to call the loader from within a stored PL/SQL procedure?
    Thank you very much for your help.
    Aneta Valova
    null

    Hi
    What is your task and why you are trying to invoke SQL*Loader from strorage procedure or package? Maybe the redirecting of stderr will resolve your problem but thik is it the best way to do your job.
    I am not sure, that invoking other executables from Oracle instance is good idea.
    Regards
    null

  • How to fetch oracle process id from a stored procedure.

    Hi,
    I want to fetch the oracle process id from within a stored procedure.
    I know that the one way to do this is using the v$process view. But, a grant has to be given to the user on this table. Due to the strict policies at my workplace, I do not have the permission to do this, nor can i ask anyone to give the grant. But, i need the oracle pid very much.
    Is there an alternate way to get the oracle process id from within the stored procedure (without using the v$process view, like we have sys_context() to fetch session id without using v$session) ?
    Any help would be appreciated.
    Thanks,
    AP

    Hi,
    The point is i do not want to use v$process ( or v_$process) ,because i can not give the select grant to the user on this view. ( As i need to fetch it from a stored procedure, not from the SQL prompt).
    Rahul , your query is correct. It fetches the values ( though i needed oracle process id not unix pid ; i would get it through p.pid), but i need an alternate approach to this.
    Is there an alternate approach which would enable me to fetch the oracle process id ( without using any of the V$ - system views) ? Does Oracle has such a feature /approach ?
    -AP

Maybe you are looking for

  • To give colours for a certain row in table control in module pool

    Hi, In module pool,,,,,When I am displaying the Table Control......Suppose in some rows personnel no. is there and for the person who has exited from the company should be highlighted with red colour. Please some code.. thanks..

  • Reinstall OS9.2.2-CD start up freezes-cannot boot OS from CD to install

    I recently had to trash the main drive due to a massive failure on my G4. The second HD has 10.4.11 installed on it. I boot from there. It does not have 'classic' installed. Tried to start up and got the message to install OS 9. Got out the install C

  • CF Set form.variable for query and Next/Previous pages error

    I have a CF form with a select that posts to a CF "action" page. On the action page I: CFSET ItemNumber=#form.ItemNumber# I CFOUTPUT the 'ItemNumber' into the CFQUERY (which is an Inner Join dependant on the '#ItemNumber#')... All of the above works

  • VLAN assignment from ACS not applied

    WLC 4402 5.2.157.0 ACS Express 5.0.0.18 We have an issue where the VLAN assigned on the ACS isn't applied on the 4402 WLC. We have 'Allow AAA Override' checked on the WLAN, the QoS is overridden to bronze properly, but the VLAN stays at 0 and the int

  • Centralized event handling

    This is an odd idea we have not seen discussed in the books we have read or even on this forum. Still we think the problem I have to solve must be common. Can you give us some advice ? In our app, we get events coming in from a server reading devices