Cannot exeute DML in a function

I have a function as follows,
CREATE OR REPLACE FUNCTION get_cns(
sysc IN ib_fact_batchno.SYS_CODE%TYPE,
subc IN ib_fact_batchno.SUB_CODE%TYPE)
RETURN Varchar2 AS
rowcnt NUMBER;
curn varchar2(10);
BEGIN
LOCK TABLE ib_fact_batchno IN ROW EXCLUSIVE MODE;
SELECT COUNT(*) INTO rowcnt FROM ib_fact_batchno
WHERE SYS_CODE = sysc AND SUB_CODE = subc;
IF (rowcnt = 0) THEN
INSERT INTO ib_fact_batchno VALUES (sysc, subc, '1');
ELSE
UPDATE ib_fact_batchno SET CUR_NUM = TO_CHAR(TO_NUMBER(CUR_NUM)+1)
WHERE SYS_CODE = sysc AND SUB_CODE = subc;
END IF;
SELECT CUR_NUM INTO curn FROM ib_fact_batchno
WHERE SYS_CODE = sysc AND SUB_CODE = subc;
COMMIT;
RETURN
END;
the creation is success. But when I use it as
select get_cns('CUS', '807') from dual;
I have the following error:
ERROR 在行 1:
ORA-14551: 無法在查詢內執行 DML 作業
ORA-06512: 在 "ADMIN.GET_CNS", line 15
ORA-06512: 在 line 1
What's the problem? and How to fix it?
BR/Jean

Firstly, please post technical questions in the specific forums : General Database Discussions
To answer your question, The function is fine, the SELECT statement select get_cns('CUS', '807') from dual; is incorrect.
In case you are just trying to test if the function get_cns is working fine, you could use an anonymous PL/SQL block as follows :
set serveroutput on
declare
temp varchar2(100);
begin
temp := get_cns('CUS', '807');
dbms_output.put_line(temp);
end;

Similar Messages

  • DML statements in Function

    Hi,
    I have small question
    Why we should not written DML statements in Function ?
    Can any one explain that
    Thanks...

    971822 wrote:
    Hi,
    I have small question
    Why we should not written DML statements in Function ?
    Can any one explain thatThe answer is: "it depends".
    Functions are used for many many different purposes, and it is the purpose that determines whether it's a good idea to write DML statements in a function.
    As already mentioned, there are the purity rules, that basically say "if you're going to be calling the function from queries etc. then it cannot do DML, otherwise you'll get an exception"
    But there are also functions that are intended to be used within PL/SQL code for other purposes. It may be that you need something that updates some data and returns a result from that updated data, or it returns how much data was effected, in which case it's perfectly ok to have a function do some DML.
    As long as the code is well modularised and makes sense for the purpose for which it is intended, then you are doing the right thing. Where it goes wrong is when people lack design in their applications, and try to write 'generic' functions to be used in PL/SQL or SQL, or fail to modularise code so a function is doing the task of several things based on some parameters etc. when really each task should seperated to it's own functions/procedures etc.
    So we cannot just say that we "should not" write DML inside functions; but we can say that there are design considerations (or lack of) when it would be bad practice to do so.

  • Cannot perform dml operation inside a query

    I have created a function which does some dml opration.
    when I use it in a through a transformation operator, and execute the map,
    it throws the following error:
    cannot perform dml operation inside a query
    how to handle this?

    Hi,
    if you want to execute the dml within a mapping, use the pre or post mapping procress operator. Or use a sql*plus activity in the process flow.
    Regards,
    Carsten.

  • If we use DML statement in function then that function can be used inside s

    if we use DML statement in function then that function can be used inside select query or any DML query?

    select f from t2;I think you meant to query t1.
    It works if the function is an autonomous transaction:
    create or replace function f return number
    is
    PRAGMA AUTONOMOUS_TRANSACTION;
    begin
        update t1 set c=2;
        commit;
        return 1;
    end;
    select f from t1But as Billy said why would you want to do DML this way. And this is not the way autonomous procedures should be used either.
    An an answer to an interview question though nothing wrong with it.

  • I think I finished installing Mountain Lion, and am at the "log in" page with my name and the Lion icon, but I cannot do any of the functions on screen. That is, I cannot log in, sleep, restart, or shut down. I am running it on an Early 2009 Macbook Pro

    I think I finished installing Mountain Lion, and am at the "log in" page with the Mountain Lion icon, but I cannot do any of the functions on screen. That is, I cannot log in, sleep, restart, or shut down. I am running it on an Early 2009 Macbook Pro, which is said to have the capabilities of running Mountain Lion.

    BrettGoudy wrote:
    ...Is there any way I can install a partition that runs snow leopard on my early 2011 MB pro with what I have (new SSD, New RAM, Current version Lion running, no external drive, lack of original snow leopard disks [I lost them ] and the general 10.6.3 snow leopard boot disks)...
    As the last post suggests, call Apple and order a replacement original disc for about $17.  They will ask you the model and serial numbers.
    Your retail version of Snow Leopard OS 10.6.3 will not work on that Mac as it requires a minimum of OS X 10.6.7 to boot and operate.
    Another alternative is to again borrow another Mac to install your retail Snow Leopard into an external HD or partition, upgrade it to 10.6.8 and then clone it back to a partition on your MBP.

  • Cannot use the F1-12 functions on my Satellite C55-A-19K

    Hello there
    Satellite C55-A-19K have an keyboard drivers?
    I cannot use the F1-12 functions and cannot get the wireless on since its on the keyboard...
    Can some 1 help please?

    Hi
    The basic setting on these models is that the special functions on the [F1]-[F12] keys are used without [FN].
    So for example activating / deactivating the touchpad is done from [F5] (not [FN] [F5])
    It is also possible to change this behaviour. Setting the Function-keys to traditional mode in the BIOS will revert back to the keys used along with [FN].
    So activating / deactivating the touchpad in traditional function key mode, requires [FN] [F5].
    So be sure to check your function key behavoiur - if you have set it to use [FN] first or not.
    And keep in mind that in case the current mode is not what you want, you may change it.
    Hope this helps
    BR Tom
    Message was edited by: MannerhagenVPO

  • Why we cannot perform DML operations against complex views directly.

    hi
    can any tell me why we cannot perform DML operations against complex views directly.

    Hi,
    It is not easy to perform DML operations on complex views which involve more than one table as said by vissu. The reason being you may not know which columns to be updated/inserted/deleted on the base tables of the views. If it is a simple view containing a single table it is as simple as performing actions on the table.
    For further details visit this
    http://www.orafaq.com/wiki/View
    cheers
    VT

  • You cannot maintain the address (partner function 'Ship-to party' is empty)

    Dear Experts,
          I create one outbound delivery but when I click on address ( Symbol next to ship to party) it is showing below error.
    You cannot maintain the address (partner function 'Ship-to party' is empty)
    Message no. VPD017
    I also check customer master , address is maintain properly.
    in partner functions Sold-to party , Bill-to party , Payer , Ship-to party all are same. ( example: if bill to party is ABC then payer , ship to pary , bill to party all are ABC).
    Please help.
    Regards,
    Nirav Desai

    Hii Nirav Desai,
    You do correctly "configure automatic partner determination". The steps are as below -
    Customer Master
    Sales Document Header
    Sales Document Item
    Delivery Type
    Shipment Type
    Billing Header
    Billing item
    Sales Activities
    1.     How to define partner?
    A grouping of partner functions. The procedure specifies which partner functions are allowed for a particular business transaction (for example, for processing a sales order) and which of those partner functions are mandatory.
    Use
    You define partner determination procedures in SD Customizing through Functions -> Partner determinat.
    u2022     In sales documents, for example, you can specify the partner determination procedure according to sales document type and item category. During order entry, the system first proposes partners from the customer master record of the sold-to party. If this information does not exist in the customer master, the system automatically proposes the mandatory partners from the partner determination procedure that you specify in the document header.
    u2022     For billing documents, for example, you can specify a partner determination procedure where the sold-to party, bill-to party, and payer are mandatory but the ship-to party is not (for billing, you are more interested in who orders and pays for the goods than in who receives them).
    Thanks and Regards,
    Santanu

  • We have a Canon SX40Hs and cannot activate the digital zoom function. can you help?Thanks

    We have a Canon SX40Hs and cannot activate the digital zoom function.  I have tried changing the mode from Auto to "P" to "Tv" etc and the dig zoom function is greyed out and not accessible.  Any help?
    Thanks

    Actually, this is a friend's camera, but yes, I went to the menu and when I got to the digital zoom option, it is greyed out (not accessible).  That is the problem.  I shoot in the EOS line so figured maybe there was a custom function somewhere that was causing the problem, but Power shot line apparentley doesn't have custom functions.  Thought maybe digital zoom is only availabel in certain modes (pernaps not available in "green square"), but changing mode didn't seem to make it accessible either.  I am just not familiar with the powershot cameras so ...  any other suggestions?

  • My ipad is disabled and I cannot restore it because the Function Find My Ipad setting was on, and I cannot get in the ipad to turn off the setting in order to restore the ipad. Does anyone know how to solve the problem

    My ipad is disabled and I cannot restore it because the Function Find My Ipad setting was on, and I cannot get in the ipad to turn off the setting in order to restore the ipad. Does anyone know how to solve the problem

    Force iPad into Recovery Mode. Follow step 1 to 5 very closely.
    http://support.apple.com/kb/HT1808
    Note: You may have to repeat the above a few times.

  • Executing DML-ing stored function from EntityManager

    Hi,
    Is there some way of getting the result from a DML-ing stored function from the EntityManager? I can use a native query and just select the function from dual if it doesn't do any DML but when it does, it is not permitted. I can't use getDelegate() to get the raw connection either :-/
    Edited by: nickarls on Sep 25, 2007 2:19 AM
    Edited by: nickarls on Sep 25, 2007 2:20 AM
    Hmmm. the *** should be "ing". Probably looks like a curse

    anyone, anyone?

  • My notification center (windows 7 64 bit) disappear from time to time, any idea? (When it disappears, I cannot use the special keyboard functions like sound...

    My notification center (windows 7 64 bit) disappear from time to time, any idea?
    When it disappears, I cannot use the special keyboard functions like sound,brightness...
    Thanks!

    How is Acrobat 8 not fully Windows 7 compatible?  I see discussions on this Adobe Community saying how Acrobat 8 does work on Windows 7 and with 64-bit.  It appears that if Acrobat 8 is updated to the latest version, then this should fix AA8-Win7 issues.  And I am at the latest AA8 version, 8.3.1. 
    And how are Acrobat 8 and Reader XI are not compatible?  I have always had Acrobat and Reader installed on the same PC, without ever having any issues.  And Adobe allows the installation of one after the other.  So apparently Adobe allows them both to exist together.  If they are incompatible, then why would Adobe allow them to exist together? 
    Anyway, I did uninstall the FileOpen Plug-in and the Reader XI, then reinstalled the FileOpen Plug-in.  So now Reader is not installed and only Acrobat 8 is installed.  I then tried to load the PDF file, but I still get the Acrobat 8 error described above. 

  • Satellite R840-12C: cannot switch off the WiFi function manually

    I have recently purchased a brand new Toshiba Satellite R840-12C Notebook.
    The Wifi LED remains "on" and the function key does not work, in other words cannot switch off the WiFi function manually.
    Although the WiFi function remains 'on" I cannot connect to a wireless modem.
    When I go to device manager I find conflicts in "other devices" for
    1. Network Controller
    2. PCI Simple Communications Controller
    3. Unknown Device
    Tried updating drivers by connecting through ethernet cable to the modem but to no avail.
    Can someone help?

    Hi
    Did you install the WLan driver?
    The notebook seems to be equipped with the Atheros AR9285 Wlan card and in most cases the Fn + F8 button does not work because the Wlan driver is not installed or does not work properly.
    Recommend firstly deleting the WLan card from the device manager and then to reboot the notebook. After the new reboot install the new downloaded Atheros Wlan driver for this wlan card.
    Here you can find all the Wlan drivers published by Toshiba:
    http://aps2.toshiba-tro.de/wlan/?page=downloads

  • The custom code in the form cannot be run. This functionality may be deactivated on the server.

    Dears,
    I was written some C# code on Loading event of InfoPath 2010 form. and it successfully published but when i open the form through browser it shows warning error that: The custom code in the form cannot be run. This functionality may be deactivated on
    the server. For more information, contact the server farm administrator.
    As shown below image
    I am new to SharePoint

    As the error can be caused by various things .You need to check follow details:
    Open SharePoint Central Admin > System Settings > Services on Server .Make sure that ‘Microsoft SharePoint Foundation Sandboxed Code Service’ is running .
    When you publish a form with code behind ,you need to publish it either as a sandboxed solution or as an Administrator Approved Form .
    Check if there is code  in a sandbox which is partially trusted is calling a dll in GAC which is having full trust .
    For more information ,please refer to these sites:
    The custom code in the form cannot be run.:http://www.infopathdev.com/forums/p/19380/69465.aspx#69465
    Infopath publish error : http://social.technet.microsoft.com/Forums/en-US/sharepoint2010customization/thread/856042fc-6ee8-4eda-97f8-fea2d47636ba/
    Publish a form: http://office.microsoft.com/en-us/infopath-help/publish-a-form-HA101783381.aspx#_Toc262226389
    Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer.

  • Cannot perform DML inside a query

    Hi,
    I have a Function and I am trying to execute an "Insert" statement into the Function. It gives me an error saying that-
    ERROR:
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SCOTT.POP3", line 243
    I then tried adding : PRAGMA AUTONOMOUS_TRANSACTION to the Function and then it gives me an error saying-
    ERROR:
    ORA-06519: active autonomous transaction detected and rolled back
    ORA-06512: at "SCOTT.POP3", line 245
    My code snippet is as follows :
    CREATE OR REPLACE FUNCTION pop3 (
    username VARCHAR2,
    PASSWORD VARCHAR2,
    msgnum NUMBER
    RETURN tstrings PIPELINED
    IS
    --PRAGMA AUTONOMOUS_TRANSACTION;
    pop3_server CONSTANT VARCHAR2 (100) := 'pop.secureserver.net';
    pop3_port CONSTANT NUMBER := 110;
    pop3_ok CONSTANT VARCHAR2 (10) := '+OK';
    e_pop3_error EXCEPTION;
    socket UTL_TCP.connection;
    line VARCHAR2 (30000);
    line2                    VARCHAR2 (30000);
    BYTES INTEGER;
    msg_from varchar2(4000) := '';
    msg_to varchar2(4000) := '';
    msg_date varchar2(4000) := '';
    msg_sub varchar2(4000) := '';
    msg_body clob := NULL;
    hyphen_checker number := 0;
    msg_body_flag number := 0;
    crlf varchar2(2) := chr(13) || chr(10);
    -- send a POP3 command
    -- (we expect each command to respond with a +OK)
    FUNCTION writetopop (command VARCHAR2)
    RETURN VARCHAR2
    IS
    len INTEGER;
    resp VARCHAR2 (30000);
    BEGIN
    len := UTL_TCP.write_line (socket, command);
    UTL_TCP.FLUSH (socket);
    -- using a hack to check the popd response
    len := UTL_TCP.read_line (socket, resp);
    IF SUBSTR (resp, 1, 3) != pop3_ok
    THEN
    RAISE e_pop3_error;
    END IF;
    RETURN (resp);
    END;
    BEGIN
         DBMS_LOB.CREATETEMPORARY(msg_body,true);
    PIPE ROW ('pop3:' || pop3_server || ' port:' || pop3_port);
    -- Just to make sure there are no previously opened connections
    UTL_TCP.close_all_connections;
    -- open a socket connection to the POP3 server
    socket :=
    UTL_TCP.open_connection (remote_host => pop3_server,
    remote_port => pop3_port,
    --tx_timeout => POP3_TIMEOUT,
    CHARSET => 'US7ASCII'
    -- read the server banner/response from the pop3 daemon
    PIPE ROW (UTL_TCP.get_line (socket));
    -- authenticate with the POP3 server using the USER and PASS commands
         LOOP
    EXIT WHEN LENGTH (line) = 1 AND line = '.';
         END LOOP;
         INSERT INTO email (em_issue, em_date, em_from, em_to, em_subject, em_body)
         VALUES(seq_issue.nextval, msg_date, msg_from, msg_to, msg_sub, msg_body);
         DBMS_LOB.freetemporary(msg_body);
         msg_from := '';
         msg_to := '';
         msg_date := '';
         msg_sub := '';
         msg_body := NULL;
         -- close connection
         PIPE ROW ('QUIT');
         PIPE ROW (writetopop ('QUIT'));
         UTL_TCP.close_connection (socket);
    EXCEPTION
    WHEN e_pop3_error
    THEN
    PIPE ROW ('There are no mails !');
    END;
    Message was edited by:
    Monk
    Message was edited by:
    Monk

    See Note:313597.1 on MetaLink

Maybe you are looking for

  • XML Report Issue while generating the Report in EXCEL

    Hi All, I have Created the XML Report which will generate the output in EXCEL format. I am having the issue with the report output in EXCEL. In my Case, If I ran the concurrent it got completed normally and the output got completed normally and the o

  • I can't change print sizes in certain folders!

    This is a maddening problem! I have an HP 8750, which I have no problems with. I just got a Kodak 5100 printer. The problem is that in certain folders, if I try to change the print size of an image, say Letter to Borderless 4x6, it doesn't stick! In

  • Neo2-FR won't power up after sitting for ~3+ standby - if less, it does power up

    Hi all, I had my Neo2-FR for about three months and have been working well going into standby (S3) and restarting by pressing the power button, until last week when I replaced the CPU fan with 120mm Scythe Kama PWM fan.  I don't know why a fan would

  • I want to print mail from my ipad

    Where is the "action icon" to print mail from an ipad? I have the HP envy compatible printer.

  • BDLS performance - how to speed up BDLS run?

    Hi all, Although my database is not huge (1.5Tb), BDLS run takes a lot of time - 26 hours I found very nice blog - /people/hari.peruri/blog/2006/11/01/execute-conversion-of-logical-system-names-bdls-in-short-time-and-in-parallel--intermediate, but si