Function in a Trigger

Hello every one. I have a question for you. I need a second eye, I think I am missing something. OK I have the following trigger
1 CREATE OR REPLACE TRIGGER lock_ids_autonumber
2 BEFORE INSERT ON lock_ids FOR EACH ROW
3 BEGIN
4 IF :NEW.id IS NULL THEN
5 SELECT column_value as seqnum from table(ome_nextval(upper('lock_seq'))) INTO :NEW.id FROM dual;
6 END IF;
7* END;
Where ome_nextval is a function, it is as following. The function returns the type which is CREATE TYPE num_t AS TABLE OF NUMBER
CREATE OR REPLACE FUNCTION ome_nextval(p_seq_name IN VARCHAR2,
p_block_size IN NUMBER DEFAULT 1)
RETURN num_t
PIPELINED AS
PRAGMA autonomous_transaction;
pl_current_value NUMBER := 0;
BEGIN
SELECT current_value
INTO pl_current_value
FROM my_sequences
WHERE seq_name = p_seq_name
FOR UPDATE OF current_value;
UPDATE my_sequences
SET current_value = current_value + p_block_size
WHERE seq_name = p_seq_name;
COMMIT;
FOR i IN pl_current_value..pl_current_value+p_block_size - 1
LOOP
PIPE ROW(i);
END LOOP;
END;
When I run the trigger, I get the folloiwng error...
LINE/COL
ERROR
2/8
PLS-00049: bad bind variable 'NEW.ID'
3/9
PL/SQL: SQL Statement ignored
3/93
PL/SQL: ORA-00933: SQL command not properly ended
LINE/COL
ERROR
3/98
PLS-00049: bad bind variable 'NEW.ID'
I will really appreciate it, if some one can point to the mistake I am making.

Hi Alex,
That would probably be due to this thread:
Re: Sequence Issue
If you take a holiday in San Francisco, you should first read up, before posting again ;-)
(and have some coffee ofcourse).
Now, I totally agree of course: the block-allocate solution I offered, was never meant to be used for block sizes of 1...
Toon

Similar Messages

  • Java function call from Trigger in Oracle

    Moderator edit:
    This post was branched from an eleven-year-old long dead thread
    Java function call from Trigger in Oracle
    @ user 861498,
    For the future, if a forum discussion is more than (let's say) a month old, NEVER resurrect it to append your new issue. Always start a new thread. Feel free to include a link to that old discussion if you think it might be relevant.
    Also, ALWAYS use code tags as is described in the forum FAQ that is linked at the upper corner of e\very page. Your formulae will be so very much more readable.
    {end of edit, what follows is their posting}
    I am attempting to do a similar function, however everything is loaded, written, compiled and resolved correct, however, nothing is happening. No errors or anything. Would I have a permission issue or something?
    My code is the following, (the last four lines of java code is meant to do activate a particular badge which will later be dynamic)
    Trigger:
    CREATE OR REPLACE PROCEDURE java_contact_t4 (member_id_in NUMBER)
    IS LANGUAGE JAVA
    NAME 'ThrowAnError.contactTrigger(java.lang.Integer)';
    Java:
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "ThrowAnError" AS
    // Required class libraries.
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import com.ekahau.common.sdk.*;
    import com.ekahau.engine.sdk.*;
    // Define class.
    public class ThrowAnError {
    // Connect and verify new insert would be a duplicate.
    public static void contactTrigger(Integer memberID) throws Exception {
    String badgeId;
    // Create a Java 5 and Oracle 11g connection.
    Connection conn = DriverManager.getConnection("jdbc:default:connection:");
    // Create a prepared statement that accepts binding a number.
    PreparedStatement ps = conn.prepareStatement("SELECT \"Note\" " +
    "FROM Users " +
    "WHERE \"User\" = ? ");
    // Bind the local variable to the statement placeholder.
    ps.setInt(1, memberID);
    // Execute query and check if there is a second value.
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
    badgeId = rs.getString("Note");
    // Clean up resources.
    rs.close();
    ps.close();
    conn.close();
    // davids badge is 105463705637
    EConnection mEngineConnection = new econnection("10.25.10.5",8550);
    mEngineConnection.setUserCredentials("choff", "badge00");
    mEngineConnection.call("/epe/cfg/tagcommandadd?tagid=105463705637&cmd=mmt%203");
    mEngineConnection.call("/epe/msg/tagsendmsg?tagid=105463705637&messagetype=instant&message=Hello%20World%20from%20Axium-Oracle");
    Edited by: rukbat on May 31, 2011 1:12 PM

    To followup on the posting:
    Okay, being a oracle noob, I didn't know I needed to tell anything to get the java error messages out to the console
    Having figured that out on my own, I minified my code to just run the one line of code:
    // Required class libraries.
      import java.sql.*;
      import oracle.jdbc.driver.*;
      import com.ekahau.common.sdk.*;
      import com.ekahau.engine.sdk.*;
      // Define class.
      public class ThrowAnError {
         public static void testEkahau(Integer memberID) throws Exception {
         try {
              EConnection mEngineConnection = new EConnection("10.25.10.5",8550);
         } catch (Throwable e) {
              System.out.println("got an error");
              e.printStackTrace();
    }So, after the following:
    SQL> {as sysdba on another command prompt} exec dbms_java.grant_permission('AXIUM',"SYS:java.util.PropertyPermission','javax.security.auth.usersubjectCredsOnly','write');
    and the following as the user
    SQL> set serveroutput on
    SQL> exec dbms_java.set_output(10000);
    I run the procedure and receive the following message.
    SQL> call java_contact_t4(801);
    got an error
    java.lang.NoClassDefFoundError
         at ThrowAnError.testEkahau(ThrowAnError:13)
    Call completed.
    NoClassDefFoundError tells me that it can't find the jar file to run my call to EConnection.
    Now, I've notice when I loaded the sdk jar file, it skipped some classes it contained:
    c:\Users\me\Documents>loadjava -r -f -v -r "axium/-----@axaxiumtrain" ekahau-engine-sdk.jar
    arguments: '-u' 'axium/***@axaxiumtrain' '-r' '-f' '-v' 'ekahau-engine-sdk.jar'
    creating : resource META-INF/MANIFEST.MF
    loading : resource META-INF/MANIFEST.MF
    creating : class com/ekahau/common/sdk/EConnection
    loading : class com/ekahau/common/sdk/EConnection
    creating : class com/ekahau/common/sdk/EErrorCodes
    loading : class com/ekahau/common/sdk/EErrorCodes
    skipping : resource META-INF/MANIFEST.MF
    resolving: class com/ekahau/common/sdk/EConnection
    skipping : class com/ekahau/common/sdk/EErrorCodes
    skipping : class com/ekahau/common/sdk/EException
    skipping : class com/ekahau/common/sdk/EMsg$EMSGIterator
    skipping : class com/ekahau/common/sdk/EMsg
    skipping : class com/ekahau/common/sdk/EMsgEncoder
    skipping : class com/ekahau/common/sdk/EMsgKeyValueParser
    skipping : class com/ekahau/common/sdk/EMsgProperty
    resolving: class com/ekahau/engine/sdk/impl/LocationImpl
    skipping : class com/ekahau/engine/sdk/status/IStatusListener
    skipping : class com/ekahau/engine/sdk/status/StatusChangeEntry
    Classes Loaded: 114
    Resources Loaded: 1
    Sources Loaded: 0
    Published Interfaces: 0
    Classes generated: 0
    Classes skipped: 0
    Synonyms Created: 0
    Errors: 0
    .... with no explanation.
    Can anyone tell me why it would skip resolving a class? Especially after I use the -r flag to have loadjava resolve it upon loading.
    How do i get it to resolve the entire jar file?
    Edited by: themadprogrammer on Aug 5, 2011 7:15 AM
    Edited by: themadprogrammer on Aug 5, 2011 7:21 AM
    Edited by: themadprogrammer on Aug 5, 2011 7:22 AM
    Edited by: themadprogrammer on Aug 5, 2011 7:23 AM
    Edited by: themadprogrammer on Aug 5, 2011 7:26 AM

  • Function inside a trigger

    Can i write function inside a trigger?
    My requirement is that i've to call a function inside a trigger. Since this function is not frequently used so what i am thinking that i should write this function inside trigger. Can i do that?
    i know that function can be called inside trigger, but can i create a function inside trigger?
    if yes, then how?
    give me an overview. I'll appricate any kind of help.

    Hi,
    jadoo wrote:
    you mean to say that i can create a function in declaration section of trigger?Just an example,
    SQL> select empno,sal, deptno
      2  from emp
      3  where empno=7369;
         EMPNO        SAL     DEPTNO
          7369        800         20
    SQL> create table sal_inc_tab
      2  (inc_empno number,
      3  inc_sal number);
    Table created.
    SQL> create or replace trigger f_trg After update on emp
      2  REFERENCING NEW AS NEW OLD AS OLD
      3  FOR EACH ROW
      4  Declare
      5   v_inc_sal number;
      6   function sal_inc (v_sal number)
      7   return number as
      8   Begin
      9    return :new.sal+3000;
    10   end sal_inc;
    11  BEGIN
    12   v_inc_sal:=sal_inc(:new.sal);
    13   Insert into sal_inc_tab values(:new.empno,v_inc_sal);
    14  end;
    15  /
    Trigger created.
    SQL> select * from sal_inc_tab;
    no rows selected
    SQL> update emp
      2  set deptno=10
      3  where empno=7369;
    1 row updated.
    SQL> select * from sal_inc_tab;
    INC_EMPNO    INC_SAL
          7369       3800You can do same thing without function. Here there was no specific logic as such, it was just to show you how this is executed.
    Twinkle

  • Function module to trigger Infopackages

    Hi,
    Need your help to clarify certain doubts,
    Std. Infopackage name (0PAK*) will be same for each and every master data object through out all the systems ??
    Means suppose 0MATERIAL_ATTR has infopackage 0PAKXXX that is been installed by system from BC .
    Will it be the same if i will install for another system ?
    And also if there is any function module to trigger infopackage schedule , pls let me know.
    Regards
    Nimesh

    Hi,
    I am not sure whether you can directly trigger the infopackage through function module. But there is an alternative way.
    You can create an event in the transaction sm62 and in the infopackage scheduler you can give that event name.
    You can trigger this event by using the function module "RSSM_EVENT_RAISE" and subsequently you can trigger the infopackage.
    Hope this will be somewhat helpful to you.
    Regards,
    K.Manikandan

  • Can we write function in a trigger??

    Can we write function in a trigger??

    3360 wrote:
    810534 wrote:
    Can we write function in a trigger??This can be better phrased as two questions.
    Would we want to write a function in a trigger?
    Answer - No.
    Is there any problem that needs to be solved by writing a function in a trigger?
    Answer - No.Even better would be the same two questions with "a function in " removed.
    Same answers.

  • Is there any function module to trigger workflow template

    Hi,
    I have created a workflow template in tcode PFTC, which i am using to send email, this workflow needs to be triggered once the document is posted, there are no events being triggered at that stage, My query is 'Is there any function module to trigger this workflow template from the user exit'?.
    Thanks in Advance
    Santosh

    Use FM
    SAP_WAPI_START_WORKFLOW.
    or if you have triggering event for the wflow use
    SWE_EVENT_CREATE
    SAP_WAPI_CREATE_EVENT
    Thanks
    Arghadip

  • How to write the custom Function Module to trigger the Alert.

    Hi all,
    I have developed a custom alert category in Tx - alrtcatdef. Now i want to trigger it from my custom function module. what should i do or what is the procedure to trigger the alert from my custom function module.
    Arul Jothi

    hi arul,
    try this program.
    RSALERTTEST.
    check out this link...
    <a href="/people/ginger.gatling/blog/2005/12/02/innovative-ways-to-use-alerts:///people/ginger.gatling/blog/2005/12/02/innovative-ways-to-use-alerts
    regs,
    jaga

  • Any method has similar function as 'when_mouse_enter' trigger in 10g

    in 10g, we cannot use 'when_mouse_enter', 'when_mouse_leave' functions, is there any other functions have similar interactive functions in 10g?

    We use when-mouse-click when on the web to emulate the when_mouse_enter trigger. Or in some cases, when-mouse-click with ctrl button (Checking :System.Mouse_button_shift_state).
    Instead of when-mouse-leave, we just started a non-repeating timer, and did the same as the wme trigger after 3 seconds.

  • Any method have similar function as 'when_mouse_enter' trigger in 10g

    in 10g, we cannot use 'when_mouse_enter', 'when_mouse_leave' functions, is there any other functions provide similar interactive functions in 10g?

    We use when-mouse-click when on the web to emulate the when_mouse_enter trigger. Or in some cases, when-mouse-click with ctrl button (Checking :System.Mouse_button_shift_state).
    Instead of when-mouse-leave, we just started a non-repeating timer, and did the same as the wme trigger after 3 seconds.

  • Can't compile stored functions in forms trigger

    I have put this code in POST_QUERY trigger. But it does not compile.
    select substr(wds(round(d2h(h2d(max(to_number(to_char(msg_time))))
    - h2d(min(to_number(to_char(msg_time))))),2)),1,40) into :tm1 from test_hst_msg;
    Please note all the fucntions are existed and are successfully compiled.
    It is giving compilation error.
    function 'WDS' may not be used in sql.
    do you have any remeady to anyone.
    Thanks.

    May need to add PRAGMA RESTRICT_REFERENCES compiler directive.

  • How to call a function from a trigger in a forms

    Hi,
    I have a conversion function already stored in Program Units.
    Now, how do I call it from a field trigger ?
    Thanks very much.
    Thuy
    null

    Thuy (guest) wrote:
    : Hi,
    : I have a conversion function already stored in Program Units.
    : Now, how do I call it from a field trigger ?
    : Thanks very much.
    : Thuy
    assume the conversio function is f .
    Therefore f(x) will return a value into a variable hence
    IN THE FIELD TRIGGER
    declare
    v datatype(presecion);
    begin
    v:=f(x);
    end ;
    null

  • Create a procedure for SAE function by using trigger.

    how to create a procedure by using triggers.
    we Have a job constant for the SAE function to trigger psuedo code SAE_ENG_DOC description: Engineering Documentation requirement. This should only trigger 1 time per job regardless of how many up issues recosting there may be.
    and we have to add 2 hrs for Engineering Documentation .
    Please give me response as soon as possible.
    Thx & Regards
    Sridevi

    The response as soon say that shine light on document reflects wording on manual into retina for purpose of consumption by cerebral cortex for the understanding the problem to formulate solution.
    Or else you can try plain and simply English saying WHAT the problem is, without making assumptions that we understand your tables, your software, your database, your environment and your requirements.
    And drop the "give me response as soon as possible" as no one here owes you a damn thing in terms of how quick to respond to your problem.

  • Rollover Slidelet does not function when the trigger & display areas overlap

    Hi everyone,
    I am trying to use a rollover slidlet where the user hovers over a specific area (my target area) and then an image appears within that same area; thus I want my target area and display area to be the same. Then when the user clicks on this same area, I also would like the slide to continue onto the next slide. The technique works fine when the trigger area and and the display area DO NOT overlap, but once they do the image in the display area no longer appears and my mouse begins pulsing. Does anyone know how I can get the slidelet to behave like I want it to? Or know of any other way I can accomplish this? Advanced actions?
    Thanks so much.

    Indeed, you cannot have Rollover area and Rollover slidelet in the same place, very annoying.
    Advanced actions cannot be triggered by a rollover event, except for Rollover slidelet, and that is the issue. If you really want a hover over effect, the only way I see is using the Eventhandler widget from InfoSemantics, it is not free:
    http://www.infosemantics.com.au/catalog/widgets/interactive/wdgt_event_handler_01
    Lilybiri

  • Error when inserting data .. to check the functionality of a trigger .

    hallo,
    im trying to write a trigger like that :
    CREATE OR REPLACE TRIGGER raum_besetzt
    BEFORE DELETE OR UPDATE OR INSERT ON BUCHUNGEN
    FOR EACH ROW
    DECLARE
    v_p NUMBER;
    v_t NUMBER;
    BEGIN
    SELECT ANzahl_plaetze into v_p
    FROM RAEUME;
    SELECT ANzahl_teilnehmer into v_t
    FROM BUCHUNGEN;
    INSERT INTO BUCHUNGEN VALUES (:NEW.BUCH_ID, :NEW.RAUM_ID, :NEW.MITA_ID, :NEW.VON, :NEW.BIS, :NEW.ANZAHL_TEILNEHMER, :NEW.VART_ID);
    IF (v_t > v_p) THEN RAISE_APPLICATION_ERROR (-20001, ' diesen RAUM ist leer ');
    END IF;
    END;the trigger have to check that all participants will be booked in the room can be accommodated. On error, the reservation is cancel.
    so i implemented it the way that number of participants ( anzahl_teilnehmer ) in the Table Reservations ( Buchungen ) is greater than the number of places ( Anzahl_plaetze ) in the table Rooms ( Raeume )
    so now i want to add some data to the table BUCHUNGEN ( Reservations ), so i can see if the trigger works!
    What i get is the Error below !! :
    Fehler beim Start in Zeile 56 in Befehl:
    INSERT INTO BUCHUNGEN (BUCH_ID, RAUM_ID, MITA_ID, VON, BIS, ANZAHL_TEILNEHMER, VART_ID)
    VALUES                (5, 5, 5, '', '', 30, 3)
    Fehlerbericht:
    SQL-Fehler: ORA-01422: Exakter Abruf gibt mehr als die angeforderte Zeilenzahl zurück
    ORA-06512: in "RAUM_BESETZT", Zeile 5
    ORA-04088: Fehler bei der Ausführung von Trigger 'RAUM_BESETZT'
    01422. 00000 -  "exact fetch returns more than requested number of rows"
    *Cause:    The number specified in exact fetch is less than the rows returned.
    *Action:   Rewrite the query or change number of rows requestedcan anyone help :)
    thank you ..

    Logic such as this should be written in a little api. A trigger is possible, but it might be pretty difficult to implement the full solution in a trigger which has several restrictions. An api usually doesn't have the same technical restrictions (trigger need to prevent endless loops, therefore they will raise an mutating table error if you insert into the same table)
    The main issue is that during the execution of your trigger, another process might add a booking without commiting it yet. But your trigger can't see this new booking from the different session. This has to be solved on a logical level first before solving it on database level. How do you want to handle such a situation?

  • Sales order creation, standard event trigger is taking long time .

    We have a requirement where we are sending data to CRM system using RFC function module. This data is sent while sales order creation or change. We have used standard event BUS2032.CREATED to trigger CRM FM in sales order creation mode. In sales order change mode, we are using custom event. In production system, our custom change event is getting triggered fine and data is sent to CRM system with small time lag of around 1 minute. But, while sales order creation, standard event trigger is taking long time ( sometimes about 20 minutes) in production system.
    We tried triggering same custom event at the time of sales order creation using FM u2018SWE_EVENT_CREATE_IN_UPD_TASKu2019 as well but, still we are not able to improve performance of the event trigger at sales order creation.
    Regards,
    Sushee Joshi

    HI,
    we have written SWE_EVENT_CREATE in update task
    I think instead of calling in update task simply call to function module CALL FUNCTION "SWE_EVENT_CREATE" might trigger the event immediately.. Did you try to check in this way..
    OR
    And I also suggest you to check the entry in SWE2 txn with respect to your workflow tempalte, may be you have enable the option ENABLE EVENT QUEUE, this could be one of the reasons.. If it is enabled please disable it (uncheck)
    Please check..
    Regards
    Pavan

Maybe you are looking for

  • Is there a way to create links to certain parts of a video?

    I would like to have links at certain time stamps within my video (which is a recording of my screen I did not use Power Point), this way I can call out important points and the viewer can go straight to them. Is this possible in Adobe Presenter 9?

  • JPanel with Image just doesn't want to show

    Hello, i am trying to create a JPanel with a JLabel to which i assign an ImageIcon, but for some reason the JPanel seems not to appear in my JFrame. Here's the code: private void jbInit() throws Exception     NumberListener numListener = new NumberLi

  • How best to use catalogs, collections etc

    I wonder if anyone can help out on a newbie question about how best to use catalogs, collections, etc Let's say I shoot an event A.  I take loads of photographs, which I import into Lightroom.  I choose some that I like and I flag them.  So far so go

  • How do you add the files name to images within a PDF

    I have been searching the web trying to find an answer to this question, I am not sure what the proper term is called, but I refer to it as a 'coded pdf'. Hopefully someone knows what I am talking about and can help me find an answer! The end product

  • I need an urgent help for  Xquery tranformation failed on OSB.

    I have made an xq then imported it into my proxyService, but when I call my proxyService I get the following error. here is the response of my proxyService call. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Bo