How to create an INSERT trigger which creates a "sequence number"

Imagine a table T_Q with columns C_1, C_2, C_3 and UN_123.
C_1, C_2 and C_3 are all numeric and given by the user.
UN_123 has to be a calculated sequence number starting by 1 and incremented by 1 for each combination of C_1, C_2 and C_3, i.e., the sequence number depends on the key values C_1, C_2 and C_3.
Could anybody provide a code sample on how to create a BEFORE INSERT trigger , which calculates the value of the column UN_123 based on the values of C_1, C_2 and C_3 ??
Premise: Rather than using any sequence, the trigger code should only be based on the table T_Q
null

<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Rainer Wagner ([email protected]):
Imagine a table T_Q with columns C_1, C_2, C_3 and UN_123.
C_1, C_2 and C_3 are all numeric and given by the user.
UN_123 has to be a calculated sequence number starting by 1 and incremented by 1 for each combination of C_1, C_2 and C_3, i.e., the sequence number depends on the key values C_1, C_2 and C_3.
Could anybody provide a code sample on how to create a BEFORE INSERT trigger , which calculates the value of the column UN_123 based on the values of C_1, C_2 and C_3 ??
Premise: Rather than using any sequence, the trigger code should only be based on the table T_Q<HR></BLOCKQUOTE>
null

Similar Messages

  • I need to create RFC function module which creates the IDOC

    Hi-
    Any idea how to create RFC function module which creates the outbound IDOC. If you have any sample code please forward to me.
    Thanks,
    Sony

    My Problem is
    Whenever they create Invoice using T-code's like FV65(Parked Document), automatically should create IDOC's...
    I have used message type FIDCC1 but this message type is usefull only for Posting documents.
    1. Whenever they create parked document, entries will be stored in BKPF(Parked Document-Filed-BKPF-BSTAT = 'V') and Bseg....
    2. I have to read entries from those tables and should create IDOC...
    3. I checked FM's(FI_IDOC_CREATE_FIDCC1, FI_IDOC_PREPARE) but are not useful...
    4. Now I need to write one RFC function module and that FM should create the IDOC's....
    Can anyone please help me out?
    Thanks,
    Sony

  • How to set default value of a table using sequence number

    Dear all,
    Does any body know that how to set default value of a table
    using sequence number.
    But I don't want to use trigger to do that.
    Please help!!!!
    Eldon

    Andrew is essentially correct. You can get around the trigger,
    but not the sequence, if (and this may be a very big if) you can
    guarantee that every time an insert is done into the table, from
    whatever source, the statement looks something like
    INSERT INTO tbl VALUES (sequence.nextval,other_columns_values)

  • How to locate the source code which populate the SO number?

    Hi,
    For example:
    In T-code: VA01
    Put your cusor on the screen field : Standard Order
    Then press F1, get the technical info of this field as below shows:
    Screen field     VBAK-VBELN
    Program name     SAPMV45A
    Screen no.       4001
    So my question is, how to locate the source code which exactly to populate the SO number into VBAK-VBELN by the system automaticallly.
    As assumed that the system is generate this kind of SO autuomatically, and its number range is defined in SPRO.
    I just want to find out the coding part which gengerate the SO number.
    Want to see the source code of that...
    How to find it???
    Thanks.

    Hi Deepak,
    Thanks for the info..
    But i think i am also know that.
    Questions is dont know how to find the KEY statements that exactlly to generate the number...
    Anyway, 2 points to you.

  • How to change a labels text which created at runtime?

    hi,
    i am creating label controls in runtime dynamically and adding them to a group component. this group component is in another custom component and i have lots of custom comp. in my app.
    my question is how can access (via id) and change a labels text whict created at runtime?
    i can change like this but i am setting id's and want to reach via id.
    var lbl:mx.controls.Label = mx.controls.Label(subMenu5.group_subMenu5.getElementAt(1));
    lbl.text = "good job";
    thank you, have a good day.

    First off, if you are already using a Spark Group, I would suggest you use a Spark Label instead of an MX Label. If you want to reference the Labels from the group, loop through the group's elements and check the if the element id matches the Label you want to assign text to.
    var lbl:Label;
    var n:int = myGroup.numElements;
    for (var i:int = 0; i < n; i++)
         lbl = myGroup.getElementAt(i) as Label;
         if (lbl && lbl.id == "myLabel")
              lbl.text = "newText";

  • A function to insert SQL which creates insert SQL

    I realise this is a bit recursive, but my users are a demanding lot! We want to store in a table the instruction to check if AUDIT_SYS_OPERATIONS is TRUE and to store the result of that check in some sort of an audit table.
    In other words, the basic SQL you'd run directly might be:
    select case when value='TRUE' then 1 else 0 end as passfail
    from v$parameter where upper(name)='AUDIT_SYS_OPERATIONS';But we want to convert this into something which will generate an INSERT statement and which itself can be inserted into a table full of these sorts of audit checks:
    insert into myaudit_checks values ('select ''insert into myaudit_table values (''||case when value=''TRUE'' then 1 else 0 end ||'');'' as passfail
    from v$parameter where upper(name)=''AUDIT_SYS_OPERATIONS'';');I find the rules for doing this to be quite easy:
    1. Add 'insert into myaudit_test values ('|| before the original CASE keyword
    2. Add ||');' before the original 'AS PASSFAIL' keywords
    3. Wrap the whole lot in single quotes
    4. Double up any quotes inside those new ones
    5. Wrap the new statement inside a standard INSERT statement.
    My users don't think that's easy, though. So I thought I'd write them a function which would return the double-quoted insert statement when fed the non-quoted basic select. It works OK, on the whole, except that calling it involves... doubling up the quotes. That is:
    select create_insert_stmt('select case when value=''TRUE'' then 1 else 0 end as passfail
    from v$parameter where upper(name)=''AUDIT_SYS_OPERATIONS'';') from dual;...works OK, but the parameter being passed to the CREATE_INSERT function requires the 'TRUE' and 'AUDIT_SYS_OPERATIONS' strings to be double-single-quoted up-front, which defeats the purpose a bit. I want them to be able to feed the completely original select statement, with single-quoted strings, into the function... but, syntactically, this looks impossible.
    Anyone got any ideas on how to spit out the final 'select 'insert...'' given the original, single-quoted select statement, without requiring too much from my users by way of thought or effort?
    The only thing I thought of was to have them store the original select in a text file and read it via UTL_FILE... but if anyone's got any better ideas, I'd be pleased to hear them.

    >
    Anyone got any ideas on how to spit out the final 'select 'insert...'' given the original, single-quoted select statement, without requiring too much from my users by way of thought or effort?
    >
    For anything that might include quotes use alternative quoting. See Text Literals in the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements003.htm
    >
    In the bottom branch of the syntax:
    •Q or q indicates that the alternative quoting mechanism will be used. This mechanism allows a wide range of delimiters for the text string.
    •The outermost ' ' are two single quotation marks that precede and follow, respectively, the opening and closing quote_delimiter.
    •c is any member of the user's character set. You can include quotation marks (") in the text literal made up of c characters. You can also include the quote_delimiter, as long as it is not immediately followed by a single quotation mark.
    •quote_delimiter is any single- or multibyte character except space, tab, and return. The quote_delimiter can be a single quotation mark. However, if the quote_delimiter appears in the text literal itself, ensure that it is not immediately followed by a single quotation mark.
    If the opening quote_delimiter is one of [, {, <, or (, then the closing quote_delimiter must be the corresponding ], }, >, or ). In all other cases, the opening and closing quote_delimiter must be the same character.
    Here are some valid text literals:
    'Hello'
    'ORACLE.dbs'
    'Jackie''s raincoat'
    '09-MAR-98'
    N'nchar literal'
    Here are some valid text literals using the alternative quoting mechanism:
    q'!name LIKE '%DBMS_%%'!'
    q'<'So,' she said, 'It's finished.'>'
    q'{SELECT * FROM employees WHERE last_name = 'Smith';}'
    nq'ï Ÿ1234 ï'
    q'"name like '['"'
    {quote}

  • How to customize my edit region which create from template page?

    I created a set of templates. It contains a edit region in each template. There's a problem when I create a new page from templates, I can't add tables in it. It says "Making this change would require changing code that is locked by a template or a translator. The change will be discarded." I need to open all liberty for my clients to customize their edit region. How can I solve the problem? Thanks

    Thanks for your reply.
    I have already try your method, but the problem still there. When I create a table, it says "Making this change would require changing code that is locked by a template or a translator." again.

  • How do I call a SP that returns a sequence number from CMD

    Hi ,  I have a requirement to call Sequence.NEXTVAL function from CMD . I believe I would have to call a SP to acheiev this I was also told that there is a generic mapplet for invoking SP from CMD  Could somebody please point me to the right place Thanks. -Bhim

    Using the Cloud / PowerCenter hybrid approach, one can cleanse address data by calling the AddressDoctor webservice. The attached sample code ( PowerCenter workflow XML ) leverages AddressDoctor's Batch Mode to cleanse individual address components ( Discrete ). The mapplet in the code can be uploaded into the Cloud platform and be used in a DSS or MCT task. Here is an example illustrating address data in a flat file being cleased and written to another flat file in a Cloud mapping. Note, in this mapping the AddressDoctor login credentials are sourced from a properties file via a lookup. The data flows from source -> expression(1) --> lookup(2) --> mapplet(3) --> target:      (1) expression - The expression sets an output port to a default value equal to 1 for use in the lookup join condition.     (2) lookup - The lookup gets the login credentials from a file on the secure agent host machine. Sample file:                         (3) mapplet - The mapplet, imported from the PowerCenter XML, calls the Address Doctor webservice and returns the process status codes, the original input data and a new cleansed data set. Note, the RecordID must be mapped and unique for each source row.

  • How to create an ADF table which has a command button column?

    Hi
    Thank you for reading my post
    how i can create a tabl that one of its column is a command button.
    when i press the command button it will , for example delete that row or do some action.
    indeed i want to know
    -how to have a command button column
    -how to find the rowID or some row identifier that help me locate that row in the database.
    thanks

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Rainer Wagner ([email protected]):
    Imagine a table T_Q with columns C_1, C_2, C_3 and UN_123.
    C_1, C_2 and C_3 are all numeric and given by the user.
    UN_123 has to be a calculated sequence number starting by 1 and incremented by 1 for each combination of C_1, C_2 and C_3, i.e., the sequence number depends on the key values C_1, C_2 and C_3.
    Could anybody provide a code sample on how to create a BEFORE INSERT trigger , which calculates the value of the column UN_123 based on the values of C_1, C_2 and C_3 ??
    Premise: Rather than using any sequence, the trigger code should only be based on the table T_Q<HR></BLOCKQUOTE>
    null

  • How Can i create a package/trigger

    Hi Every1,
    I want to create a database trigger which act on entering the charahters and count the characters.
    e.g
    you can understand with the example
    if i press 01 in a specific column the length of characters is two after this automatically the character sign i.e. / ( forward slash ) appers and then i can write 03 again the month and then again automatically / slash appers and i press 2009 and then go on
    then the filed will look likes 01/03/2009
    simply i dont want to press the / sign in the date fileld or place sign after ENTER through format mask property in forms 6i
    can any1 please help me
    Regards
    M. Laeeque A.

    I want to create a database trigger which act on entering the charahters and count the characters.I guess you're talking about a forms-trigger, not a database-trigger.
    if i press 01 in a specific column the length of characters is two after this automatically the character signi don't think thats possible in 6i. In 10g you could write a java-bean for that.

  • Using sequence in insert trigger?

    Hi all,
    I'm new to this forum, and for that matter, any forums related to computers.
    I would appreciate it if anyone would give me some hinters.
    I created a table with an ID column of type "Number." And I want to populate that column with a sequence number everytime I insert into that table.
    I have a sequence named "sequence1_account."
    Below is my insert trigger code:
    create TRIGGER system.trigger1_account
    BEFORE INSERT ON system.table_account
    for each row
    BEGIN
    :new.id := sequence1_account.NextVal;
    END;
    Note:
    user is "system"
    table is "table_account"
    The error that I get when I try to compile this is
    PLS-00357: Table,View Or Sequence reference 'SEQUENCE1_ACCOUNT.NEXTVAL' not allowed in this context
    So, does that mean I cannot use a sequence in a trigger?
    Thanks in advance!
    in His love,
    HS

    Hello,
    Hoping for some help with sequence triggers as well.
    CREATE TRIGGER "SCALS"."TRIGGER_CALL_NUM"
    BEFORE INSERT ON "CALLLOG" FOR EACH ROW
    BEGIN
    select num_callers.NextVal into : new.callernumber from dual;
    END;
    Problem is that the trigger status is invalid ??
    The error I get is in German (German installation)
    Zeilen-# = 0 Spalten-# = 0 Fehlertext = PLS-00801: internal error [ph2csql_strdef_to_diana:bind]
    Zeilen-# = 2 Spalten-# = 57 Fehlertext = PL/SQL: ORA-06544: PL/SQL: internal error, arguments: [ph2csql_strdef_to_diana:bind], [], [], [], [], [], [], []
    Zeilen-# = 2 Spalten-# = 1 Fehlertext = PL/SQL: SQL Statement ignored
    But perhaps something looks familiar???

  • [php+mysql] how to get the inserted record ID?

    Hi all,
    I have a standard php page that inserts a record in a mysql
    db.
    is there a way to save the record ID on a session variable
    just after
    storing the new record on the db? I would like to be able to
    get this
    record ID on a specific page where I would allow the user to
    print
    this specific record, by filtering the db by this session
    variable.
    I can use MX Kollection (last version, not PRO).
    TIA
    tony

    >...
    >mysql_query(...);
    >$_SESSION['lastId'] = mysql_insert_id();
    >HTH
    >Micha
    Hi Micha,
    I think that it a bit more complicated.
    I can't find any occurrence of that mysql call.
    I used MX Kollection INSERT FORM function.
    here is the code (partially):
    ===============================
    <? // Load the common classes
    require_once('../includes/common/KT_common.php');
    // Load the tNG classes
    require_once('../includes/tng/tNG.inc.php');
    // Make a transaction dispatcher instance
    $tNGs = new tNG_dispatcher("../");
    // Make unified connection variable
    $conn_test_conn = new KT_connection($tes_conn,
    $database_test_conn);
    // Start trigger
    $formValidation = new tNG_FormValidation();
    $tNGs->prepareValidation($formValidation);
    // End trigger
    // Make an insert transaction instance
    $ins_rl_test = new tNG_insert($conn_test_conn);
    $tNGs->addTransaction($ins_rl_test);
    // Register triggers
    $ins_rl_test->registerTrigger("STARTER",
    "Trigger_Default_Starter", 1,
    "POST", "KT_Insert1");
    $ins_rl_test->registerTrigger("BEFORE",
    "Trigger_Default_FormValidation", 10, $formValidation);
    $ins_rl_test->registerTrigger("END",
    "Trigger_Default_Redirect", 99,
    "2.php?idp1={id_rl}");
    // Add columns
    $ins_rl_test->setTable("rl_test");
    $ins_rl_test->addColumn("nome_rl", "STRING_TYPE", "POST",
    "nome_rl");
    $ins_rl_test->addColumn("cognome_rl", "STRING_TYPE",
    "POST",
    "cognome_rl");
    $ins_rl_test->addColumn("datanascita_rl", "DATE_TYPE",
    "POST",
    "datanascita_rl");
    $ins_rl_test->addColumn("cancellato_rl", "STRING_TYPE",
    "POST",
    "cancellato_rl");
    $ins_rl_test->addColumn("cancellato_data_rl", "DATE_TYPE",
    "POST",
    "cancellato_data_rl");
    $ins_rl_test->setPrimaryKey("id_rl", "NUMERIC_TYPE");
    // Execute all the registered transactions
    $tNGs->executeTransactions();
    // Get the transaction recordset
    $rsrl_test = $tNGs->getRecordset("rl_test");
    $row_rsrl_test = mysql_fetch_assoc($rsrl_test);
    $totalRows_rsrl_test = mysql_num_rows($rsrl_test);
    ?>
    ===========================
    as you can see, all data is processed by other functions in
    other
    included files.... :(.
    I think I need to better understand the TNG engine and try to
    create a
    little trigger that creates a session variable just after
    inserting
    the record in the db.
    I already tried to do so, honestly, but with really poor
    results.
    Ciao Micha. ;).
    tony

  • Insert trigger with if condition

    Hi.
    I am new sql programming and I am trying to write a insert trigger.
    I have created an insert-trigger that inserts into another table(p_person) whenever the trigger table (p_personmds) gets insterted:
    CREATE OR REPLACE TRIGGER INSERT_P_PERSON_TG
    AFTER INSERT ON P_PERSONMDS
    FOR EACH ROW
    BEGIN
    insert into P_PERSON (person,person_id,person_name,email_address,disabled)
    values (seq_p_person.nextval,:new.person_id,:new.person_name,:new.email_address,:new.disabled);
    END INSERT_P_PERSON_TG;
    After testing the trigger I discovered that I need to add some checking to the trigger:
    If person_id already exists in the p_person table I need to just update the 'DISABLED' column and set it to 'null' value.
    So I tried modifying the trigger:
    CREATE OR REPLACE TRIGGER TESTMDS.INSERT_P_PERSON_TG
    AFTER INSERT ON TESTMDS.P_PERSONMDS
    FOR EACH ROW
    BEGIN
    IF :new.disabled is not null
    THEN
    update p_person set disabled=NULL where person_id=:old.person_id;
    ELSE
    insert into P_PERSON (person,person_id,person_name,email_address,disabled)
    values (seq_p_person.nextval,:new.person_id,:new.person_name,:new.email_address,:new.disabled);
    END IF;
    END INSERT_P_PERSON_TG;
    Hovewer the triggers seems to ignore the first if update condition and only inserts another row with mulitiple values.
    Anyone know what I am doeing wrong here?

    user12064835 wrote:
    so if I use: 'IF :OLD.Disabled is not NULL then' ,
    will :OLD:Disabled represent the p_person table or do I have to come up with something new?if you use :old.Disable, it will run always the ELSE-block.
    you should write your block as same thing like follows:
    IF :new.disabled is not null THEN
      update p_person set disabled=NULL where person_id=:old.person_id;
      IF SQL%ROWCOUNT = 0 THEN --this block will be executed if there was no row updated in table p_person
        insert into P_PERSON (person,person_id,person_name,email_address,disabled)
        values (seq_p_person.nextval,:new.person_id,:new.person_name,:new.email_address,:new.disabled);
      END IF;
    ELSE
      insert into P_PERSON (person,person_id,person_name,email_address,disabled)
      values (seq_p_person.nextval,:new.person_id,:new.person_name,:new.email_address,:new.disabled);
    END IF;but
    user12064835 wrote:
    if DISABLED column is not null in p_person table I want to insert a null value in the DISABLED column in p_person
    where the person_id that gets inserted in p_personmds table = person_id in p_person table.means
      update p_person set disabled=NULL where person_id=:old.person_id AND disabled is not NULL; 

  • How can i set a column which would show me the name of the user

    how can i write a trigger which would show me the name of the user now make changes in the table.

    872959 wrote:
    how can i write a trigger which would show me the name of the user now make changes in the table.I think what sb is trying to say is: if you mean the database user, you can use the USER session variable to identify the database user:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions227.htm#SQLRF06156
    you would write a before each row trigger to update an "updated_by" column on your table to be USER.
    e.g.:
    :new.updated_by := USER;

  • Sequence number in Trigger

    I'm trying to create an insert trigger that will do the following:
    1.) Grab the next sequence number from a sequence and use it as the value for the id_number column.
    2.) Grab the SYSDATE and use it as the value for the create_date column.
    I'm using Oracle 8.1.6 on HP-UX. Here's my syntax, so far:
    CREATE OR REPLACE TRIGGER tI_GRANT_TEST_CHILD before INSERT on GRANT_TEST_CHILD for each row
    declare curDate DATE;
    declare idNumber NUMBER;
    begin
         SELECT SYSDATE into curDate FROM DUAL;
         SELECT GRANT_TEST_SEQ.NEXTVAL into idNumber FROM DUAL;
         :new.CREATE_DATE := curDate;
         :new.ID_NUMBER := idNumber;
    end;
    I'm pretty new to Oracle, so I've probably got a syntax error. The trigger worked fine when I just had the create date functionality; but, I can't get the sequence stuff to work.
    Also, anyone know any good links for Oracle syntax standards?
    Thanks for the help.

    I don't see anything wrong with the syntax in your example, but the trigger can be simplified to:
    create or replace trigger ti_grant_test_child
    before insert on grant_test_child
    for each row
    begin
      select grant_test_seq.nextval
        into :new.id_number
        from dual;
      :new.create_date := sysdate;
    end;
    /You can type SHOW ERRORS after compiling in SQL*Plus to see the actual errors.

Maybe you are looking for