How to write DML operation in a function

Hi
Its very urgent for me.
I am writing DML operation directly in a function and is being called from select statement, it is getting error as "DML Operations cannot be performed inside a query".
How to write a DML operation inside a function.
My objective is to call that function from select statement.
Please help me out.
Thankd

No no no. You're committing after each row! soany
other session running the same query will see the
changes you're making. Your session will equallysee
changes caused by running this query in those
sessions.Other session, yes, but current session will only see
the changes once it has completed the current
statement. Otherwise my "rn" column would not have
gone up sequentially in the above example. it would
have gone
1st row rn = 1 (all rows get updated by 1:-
2,3,4,5,6,7,8,9,10,11)
2nd row rn = 3 (all rows get update by 1:-
3,4,5,6,7,8,9,10,11,12)
3rd row rn = 5 (all rows get update by 1:-
4,5,6,7,8,9,10,11,12,13)
4th row rn = 7 (all rows get update by 1:-
5,6,7,8,9,10,11,12,13,14)
5th row rn = 9 (all rows get update by 1:-
6,7,8,9,10,11,12,13,14,15)
6th row rn = 11 (all rows get update by 1:-
7,8,9,10,11,12,13,14,15,16)
7th row rn = 13 (all rows get update by 1:-
8,9,10,11,12,13,14,15,16,17)
8th row rn = 15 (all rows get update by 1:-
9,10,11,12,13,14,15,16,17,18)
9th row rn = 17 (all rows get update by 1:-
10,11,12,13,14,15,16,17,18,19)
10th row rn = 19 (all rows get update by 1:-
11,12,13,14,15,16,17,18,19,20)
So the fact the commit happens each time the rows get
updated, isn't effecting the currently running select
statement.
No, actually you DO see the other session changes. This is because it is AUTONOMOUS transaction, and this a function.
Test by adding:
create or replace function incvals return number as
pragma autonomous_transaction;
v_val number;
begin
update t set rn = rn + 1;
select max(rn) into v_val from t;
dbms_lock.sleep(1); --add this line
commit;
return v_val;
end;
And test in two sessions.
You will NOT get sequential ascending.
>
Think about the effect of two parallel sessionsboth
running this query at the same time, and ask isthis
sensible?Gawd, no, of course not. Like I said, I'd never use
this sort of thing myself. I'm just wondering what
on earth the OP is trying to achieve.
:)Glad to hear it.

Similar Messages

  • How to write Form - Endform in between Function - Endfunction

    Hi Experts,
    I need to write some code in between form & endform in an Include(User-exit)
    This form ---endform doesnot have perform [ Perform is inside a standard Code ] . I tried using Generate pool subroutine. It is also not helping.
    The call for this perform is inside Standard Code.Pls tell how to write Form-Endform between Function -
    Endfunction.
    thanks
    surbhi

    No no no. You're committing after each row! soany
    other session running the same query will see the
    changes you're making. Your session will equallysee
    changes caused by running this query in those
    sessions.Other session, yes, but current session will only see
    the changes once it has completed the current
    statement. Otherwise my "rn" column would not have
    gone up sequentially in the above example. it would
    have gone
    1st row rn = 1 (all rows get updated by 1:-
    2,3,4,5,6,7,8,9,10,11)
    2nd row rn = 3 (all rows get update by 1:-
    3,4,5,6,7,8,9,10,11,12)
    3rd row rn = 5 (all rows get update by 1:-
    4,5,6,7,8,9,10,11,12,13)
    4th row rn = 7 (all rows get update by 1:-
    5,6,7,8,9,10,11,12,13,14)
    5th row rn = 9 (all rows get update by 1:-
    6,7,8,9,10,11,12,13,14,15)
    6th row rn = 11 (all rows get update by 1:-
    7,8,9,10,11,12,13,14,15,16)
    7th row rn = 13 (all rows get update by 1:-
    8,9,10,11,12,13,14,15,16,17)
    8th row rn = 15 (all rows get update by 1:-
    9,10,11,12,13,14,15,16,17,18)
    9th row rn = 17 (all rows get update by 1:-
    10,11,12,13,14,15,16,17,18,19)
    10th row rn = 19 (all rows get update by 1:-
    11,12,13,14,15,16,17,18,19,20)
    So the fact the commit happens each time the rows get
    updated, isn't effecting the currently running select
    statement.
    No, actually you DO see the other session changes. This is because it is AUTONOMOUS transaction, and this a function.
    Test by adding:
    create or replace function incvals return number as
    pragma autonomous_transaction;
    v_val number;
    begin
    update t set rn = rn + 1;
    select max(rn) into v_val from t;
    dbms_lock.sleep(1); --add this line
    commit;
    return v_val;
    end;
    And test in two sessions.
    You will NOT get sequential ascending.
    >
    Think about the effect of two parallel sessionsboth
    running this query at the same time, and ask isthis
    sensible?Gawd, no, of course not. Like I said, I'd never use
    this sort of thing myself. I'm just wondering what
    on earth the OP is trying to achieve.
    :)Glad to hear it.

  • DML Operations in Stored Function

    Hi,
    I have used Update Statement in a function. Which is giving an errror (ORA-14551: cannot perform a DML operation inside a query).
    Can I use DML operations in a stored function ?
    (I need help on locking master/transaction tables, i.e if a one user locks a master another user should not get modify access to the master/transactions).
    Thanks
    Ramesh Ganji

    Someone who obviously din't read my previous post in this thread. You should pay attention, programming is all about the details.
    ORA-14551: cannot perform a DML operation inside a query).Then it obviously does more than just "returns a Table Type object". Why are you doing DML in a function?
    PLS-00653: aggregate/table functions are not allowed in PL/SQL scopeWe can only call pipelined functions from SQL queries. So you'll have to ditch the DML or make it an autonomous transaction. Be very careful if you adopt the latter approach.
    Cheers, APC

  • How to perform DML Operations on Spatial Table Using ADF

    Hi
    I have an urgent requirement. I have a table with Spatial column. I have generated Business components based on Spatial Table.
    Now I have to perform Create,Read,Update and Delete operations using ADF Business Components on Spatial Table.
    I have written custom create(),read(),update() and delete() methods in my Application Module and i have to implement those methods.
    Can any one help me out how to acheive above four functionalities using ADF Business Components.
    Thanks in Advance

    HI,
    see this example.
    u can do like this.
    DATA: BEGIN OF seats OCCURS 0,
            carrid   TYPE sflight-carrid,
            connid   TYPE sflight-connid,
            seatsocc TYPE sflight-seatsocc,
          END OF seats.
    DATA seats_tab LIKE HASHED TABLE OF seats
                   WITH UNIQUE KEY carrid connid with header line.
    SELECT carrid connid seatsocc
           FROM sflight
           INTO table seats.
    loop at seats.
      COLLECT seats INTO seats_tab.
    endloop.
    LOOP AT seats_tab.
    write:/ seats_tab-carrid,seats_tab-connid,seats_tab-seatsocc.
    ENDLOOP.
    rgds,
    bharat.

  • How to write oracle output in XML

    can any one please let me know how to write or covert procedure or function output in XML?

    845470 wrote:
    can any one please let me know how to write or covert procedure or function output in XML?What is that asking?
    Are you wanting to take output from a procedure/function that is in XML format and then convert it to something else?
    Are you wanting to get the procedure/function to produce output in XML format?
    Are you wanting to take an existing procedure/function and convert it so the code is stored in some XML structure for some purpose?
    How is anybody supposed to know what you're talking about if you don't explain it?
    {message:id=9360002}

  • How to Track DDL and DML Operations happening in Backend into Log Files....

    Hi I have one requirement for Tracking the DDL And DML Operation happening in Backend once the user Inserts or Updates any Table.How to Implement the same can anyone proviode the code for the same.
    Ex: I have multiple tables in my database if any user fires the DDL or DML it should make entry in the Log file as
    Name of the Table Operation Timestamp
    X Insert DD-MM-YYYY HH24:MM:SS
    Y Update DD-MM-YYYY HH24:MM:SS
    Z Delete DD-MM-YYYY HH24:MM:SS
    L Select DD-MM-YYYY HH24:MM:SS
    Is it Possible to Develop it through Procedure,Function or Package,please give me Idea,,,,,

    Please do not post same question in multiple forum. How to Track DDL and DML Operations happening in Backend into Log Files....
    What's wrong with the answers posted in the above forum ? Do you go through the "AUDIT" option as suggested in the above post by various members ?

  • How to write a java function for use in where clause in SQL statement

    Hi,
    Does anyone know a good tutorial on how to write and include a Java class/function into Oracle.
    I'd like to write mathematical function to use in my queries, but the resources available in PL/SQL are very limited.
    Many thanx

    Pim,
    I see you got an answer in the PL/SQL forum.
    But in case you haven't seen it, perhaps this Web page will help:
    http://www.oracle.com/technology/tech/java/jsp/index.html
    Good Luck,
    Avi.

  • How to write the exceptions in function module

    dear all,
         how to write the exceptions in function modules with example.
    thanq
    jyothi

    Hi,
    Raising Exceptions
    There are two ABAP statements for raising exceptions. They can only be used in function modules:
    RAISE except.
    und
    MESSAGE.....RAISING except.
    The effect of these statements depends on whether the calling program handles the exception or not. The calling program handles an exception If the name of the except exception or OTHERS is specified after the EXCEPTION option of the CALL FUNCTION statement.
    If the calling program does not handle the exception
    · The RAISEstatement terminates the program and switches to debugging mode.
    · The MESSAGE..... RAISING statement displays the specified message. Processing is continued in relation to the message type.
    If the calling program handles the exception, both statements return control to the program. No values are transferred. The MESSAGE..... RAISING statement does not display a message. Instead, it fills the system fields sy-msgid, sy-msgty, sy-msgno , and SY-MSGV1 to SY-MSGV4.
    Source Code of READ_SPFLI_INTO_TABLE
    The entire source code of READ_SPFLI_INTO_TABLE looks like this:
    FUNCTION read_spfli_into_table.
    ""Local Interface:
    *" IMPORTING
    *" VALUE(ID) LIKE SPFLI-CARRID DEFAULT 'LH '
    *" EXPORTING
    *" VALUE(ITAB) TYPE SPFLI_TAB
    *" EXCEPTIONS
    *" NOT_FOUND
    SELECT * FROM spfli INTO TABLE itab WHERE carrid = id.
    IF sy-subrc NE 0.
    MESSAGE e007(at) RAISING not_found.
    ENDIF.
    ENDFUNCTION.
    The function module reads all of the data from the database table SPFLI where the key field CARRID is equal to the import parameter ID and places the entries that it finds into the internal table spfli_tab. If it cannot find any entries, the exception NOT_FOUND is triggered with MESSAGE ... RAISING. Otherwise, the table is passed to the caller as an exporting parameter.
    Calling READ_SPFLI_INTO_TABLE
    The following program calls the function module READ_SPFLI_INTO_TABLE:
    REPORT demo_mod_tech_fb_read_spfli.
    PARAMETERS carrier TYPE s_carr_id.
    DATA: jtab TYPE spfli_tab,
    wa LIKE LINE OF jtab.
    CALL FUNCTION 'READ_SPFLI_INTO_TABLE'
    EXPORTING
    id = carrier
    IMPORTING
    itab = jtab
    EXCEPTIONS
    not_found = 1
    OTHERS = 2.
    CASE sy-subrc.
    WHEN 1.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno.
    WHEN 2.
    MESSAGE e702(at).
    ENDCASE.
    LOOP AT jtab INTO wa.
    WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
    ENDLOOP.
    The actual parameters carrier and jtab have the same data types as their corresponding interface parameters in the function module. The exception NOT_FOUND is handled in the program. It displays the same message that the function module would have displayed had it handled the error.
    Or
    just have to decide what exceptions u want and under what conditions.
    then declarethese exeptions under the exceptions tab.
    in the source code of ur function module.
    if
    like this u can code .
    now when u call the function module in tme mainprogram.
    if some error occurs and u have declared a exception for this then it will set sy-subrc = value u give inthe call of this fm.
    in the fm u can program these sy-subrc values and trigger the code for ur exception.
    Please reward if useful
    Regards,
    Ravi
    Edited by: Ravikanth Alapati on Mar 27, 2008 9:36 AM

  • How to find last DML operation in oracle ADF

    how to find last DML operation in oracle ADF
    Please help me
    Thanks
    Damby

    In the base EntityIml class, just override doDML() method as I said.
    (see http://docs.oracle.com/cd/E16162_01/web.1112/e16182/appendix_mostcommon.htm
    "Methods for Creating Your Own Layer of Framework Base Classes")
    So, put a some flag in the session.
    You should not call doDML() method in backing bean, it will be called by framework.
    In the backing bean, you only have to get that information from the session, as follows:
    String last_dml_op = (String)ADFContext.getCurrent().getSessionScope().get("last_dml_op");And voila...

  • How to know which DML operation is taking place on a table within a procedu

    Hii all,
    My DB Version
    SQL> select *
      2  from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - ProductionHow to find what DML Operation is taking place on a particular table within a procedure??
    For suppose I've the below procedure
    create table r_dummy
    name varchar2(4000),
    emp_id number
    Create or replace procedure r_dummy_proc
    p_name          in     varchar2,
    p_emp_id     in     number
    is
    Begin
              Update r_dummy
              set name = p_name
              where emp_id = p_emp_id;
              if sql%rowcount > 1 then
                   dbms_output.put_line('Successfully updated employee name');
              end if;
    End;Here from the code I can identify that an update operation is taking place on table 'R_DUMMY'
    But how to find that without actually viewing the code?? I've hundreds of procedures in my DB and would like to find what DML is taking place on which table and in which procedure.
    Please help with some suggestions.

    And here is the solution
    with t as
      select distinct name,type,text,line
      from user_source s
      where regexp_like(s.text,'cp_ca_dtls','i')
    x as
      select name,line,text
      from
      select name,case when (regexp_instr(text,'(update)|(insert)|(delete)',1,1,1,'i') >0) and regexp_instr(ld,'CP_CA_DTLS',1,1,1,'i') >0
             then line
             else null
             end as line,text
      from
      Select   name,text,line,lead(text) over(partition by name order by line) ld
      from user_source
      where name in
          select distinct name
          from user_source
          where upper(text) like '%CP_CA_DTLS%'
      order by 1 nulls last
      )where line is not null
    select name,line,text
    from t t1
    where regexp_instr(text,'(update)|(insert)|(delete)',1,1,1,'i') >0
    and exists
         select 1
         from t t2
         where t1.name = t2.name
            and t1.type = t2.type
            and t1.line = t2.line
    union
    select name,line,text
    from x

  • How to write a function block?

    Hi There,
    Does anybody know how to write a function block with LabVIEW?  Something like those in Real-Time VIs>>Function Blocks>>.
    Thank you very much in advance?
    Solved!
    Go to Solution.

    I don't want to overwelm you but there is tons of free training material online.  One of these is the one already mentioned.
    NI Learning Center
    NI Getting Started
    -Hardware Basics
    -LabVEW Basics
    -DAQ Application Tutorials
    3 Hour LabVIEW Introduction
    6 Hour LabVIEW Introduction
    Self Paced training for students
    Self Paced training beginner to advanced, SSP Required
    LabVIEW Wiki on Training
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • How to write a function generator

    How to write a function generator from labview and using PCI-MIO-16

    Hallo, [email protected],
    Du (x) meintest am 27.07.01 zum Thema How to write a function generator:
    > How to write a function generator from labview and using PCI-MIO-16
    Look to the examples - there are many VIs with that function.
    Viele Gruesse!
    Helmut

  • Which planning function i have to use and how to write this planning fucnti

    Hi Bi Guru's,
    I have rolled out  BW SEM-BPS Planning Layout's for the Annual Budget in my organistaion.
    There are two levels of layout given for the each sales person.
    1)  Sales quantity to be entered Material and  country wise for all 12 months ( April 2009 to March 2010)
    2)  Rate per unit and to entered in second sheet, Material and country wise for the total qty entered in the first layout.
    Now i need to calculate the sales vlaue for each period and for the each material.
    Which planning function i have to use and how to write this planning fucntion.
    Please suggest me some solution ASAP.
    Thanks in Advance,
    Nilesh

    Hi Deepti,
    Sorry to trouble you...
    I require your help for the following scenario for caluclating Sales Value.
    I have Plan data in the following format.
    Country   Material    Customer    Currency    Fiscyear    Fiscper           Qty         Rate        Sales Value
    AZ          M0001      CU001          #             2009          001.2009        100.00                        
    AZ          M0001      CU002          #             2009          001.2009        200.00                        
    BZ          M0001      CU003          #             2009          001.2009        300.00
    BZ          M0001      CU003          #             2009          002.2009        400.00
    BZ          M0002      CU003          #             2009          002.2009        300.00
    AZ          M0001       #               USD          2009             #                                 10.00
    BZ          M0001       #               USD          2009             #                                 15.50
    BZ          M0002       #               USD          2009             #                                 20.00
    In the Above data the Rate lines are entered in the Second Layout, Where the user enters on the Country Material Level with 2009 value for FISCYEAR.
    I am facing problem with this type of data. 
    I want to store the sales value for each Material Qty.
    Please suggest some solution.
    Re
    Nilesh

  • Sir,how to find the last DML operations

    Hi,
    Please tell me how to find the last DML Operations at least minimum 30 queries.
    Thanks in advance,

    Shared Pool is a memory location in SGA that contains SQL Statement that are submitted to Oracle for execution. This area is common to the entire database. Its not specific to user.
    So what ever Unique SQL statement that is submitted to the SQL Engine will be available here. Shared Pool has a size limit. That is defined by the parameters SHARED_POOL_SIZE and SHARED_POOL_RESERVED_SIZE. So when the Shared pool becomes full the data needs to be removed from it. That is done in FIFO basis.
    Oracle provides a visibility to this area through dictionary view V$SQLAREA. So this view will not only contain the SQL executed by you but also by every one. Even the one executed by oracle itself.
    So in my opinion what you are asking is not possible to get. You must have some logging mechanism in your application to get this information.

  • How to write the sql statement of my finder function in cmp?

    hi,
    I create a cmp ejb from table INFOCOLUMN,and I create a my finder function ,which sql statement is :
    select * from INFOCOLUMN WHERE employee_id=id
    employee_id is a column of the table,and id is the finder function parameter.
    The error is : invalid column name
    So,how to write the sql statement.
    Thanks .

    Mole-
    Bind variables are of the form $1, $2, etc., so your query stmt should look like:
    select * from INFOCOLUMN WHERE employee_id=$1
    -Jon

Maybe you are looking for

  • Premiere Elements 10 64 bit GUI refresh slow

    Hello All, Before I start talking about the issue, I want to take this opportunity to thank Adobe for an amazingly feature rich Elements product pair.  Both Photoshop and Premiere Elements 10 are chalk full of unexpected features that can be useful f

  • How to use content code to redeem mountain lion

    when i had enter content code in redeem option its showing i have to make a payment method. tell me how to use content code to redeem mountain lion osx

  • How to use custom thumbnail for video

    Hi guys, Wonder if there is a way to embed a custom picture file to become the thumbnail of your video but not be part of the video when it's playing. Just a picture with whatever text you want on it? thanks.

  • Trace not working in air / as3

    Hi, this may be something obvious but after installing adobe air, trace no longer works to my output window. I've checked the publish settings and 'omit traces' is unchecked. thanks

  • Why does my Imessage not receive or send messages

    When someone else messages me on Imessage i do not receive the message although on their Ipod it says delivered, and i also cannot send a message.