Home » Developer & Programmer » Forms » what's wronge with this procedure ?
what's wronge with this procedure ? [message #453855] Sun, 02 May 2010 08:43 Go to next message
ahmed_samir
Messages: 61
Registered: January 2009
Location: EGYPT
Member
hi there

i made this procedure on the DB :

CREATE OR REPLACE PROCEDURE ACCURATE.items_control (
   pram_store_id   IN       NUMBER,
   pram_item_id    IN       NUMBER,
   pram_what       IN       NUMBER,
   pram_amount     IN       NUMBER,
   pram_result     OUT      VARCHAR2
)
IS
/******************************************************************************
   NAME:       items_control
   PURPOSE:

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        02/05/2010          1. Created this procedure.

   NOTES:

   Automatically available Auto Replace Keywords:
      Object Name:     items_control
      Sysdate:         02/05/2010
      Date and Time:   02/05/2010, 03:18:40 م, and 02/05/2010 03:18:40 م
      Username:         (set in TOAD Options, Procedure Editor)
      Table Name:       (set in the "New PL/SQL Object" dialog)

******************************************************************************/
BEGIN
   IF pram_what = 1
   THEN
      UPDATE accurate.wh_startyear
         SET sy_start_amount = pram_amount
       WHERE finance_year = 2010
         AND store_id = pram_store_id
         AND item_id = pram_item_id;

      pram_result := 'Saved .. ';
   END IF;
EXCEPTION
   WHEN NO_DATA_FOUND
   THEN
      NULL;
   WHEN OTHERS
   THEN
      -- Consider logging the error and then re-raise
      RAISE;
END items_control;
/


and fire this procedure by this code ::

when_bitton_press :
declare
	var_r varchar2(50);
begin
	
ITEMS_CONTROL(1,1,1,20,var_r);
:TEXT_ITEM5:=var_r;

end;


but the problem no update happen to the field .. the system every time hangs ... in toad .. or in sql plus

what's the problem ..
thanks

Re: what's wronge with this procedure ? [message #453871 is a reply to message #453855] Sun, 02 May 2010 13:14 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Remove the whole EXCEPTION section as it is completely useless. Then run the procedure again. Hopefully, you'll see some more information. By the way, NO_DATA_FOUND can't be raised by an UPDATE statement - it simply won't update anything. WHEN OTHERS, as you put it, is stupid; why raising something that will be raised by Oracle by default?

Furthermore, the fact that "pram_what" is 1 doesn't mean that any record will actually be updated. You should rather check SQL%ROWCOUNT.

Here's an example; more or less, it simulates your procedure with one difference - it works.
SQL> l
  1  create or replace procedure prc_test
  2    (par_empno in number,
  3     par_msg   out varchar2
  4    )
  5  is
  6  begin
  7    update emp set
  8      comm = -comm
  9      where empno = par_empno;
 10
 11    if sql%rowcount > 0 then
 12       par_msg := 'Updated!';
 13    else
 14       par_msg := 'Better luck next time';
 15    end if;
 16* end;
SQL> /

Procedure created.

SQL> declare
  2    l_msg varchar2(50);
  3  begin
  4    prc_test (1111, l_msg);
  5    dbms_output.put_line(l_msg);
  6  end;
  7  /
Better luck next time

PL/SQL procedure successfully completed.

SQL> select empno, comm from emp where comm is not null and rownum = 1;

     EMPNO       COMM
---------- ----------
      7499        300

SQL> declare
  2    l_msg varchar2(50);
  3  begin
  4    prc_test (7499, l_msg);
  5    dbms_output.put_line(l_msg);
  6  end;
  7  /
Updated!

PL/SQL procedure successfully completed.

SQL> select empno, comm from emp where empno = 7499;

     EMPNO       COMM
---------- ----------
      7499       -300

SQL>

Now try to create a procedure that will look like mine and try again. Make sure that no other session is holding a table you are updating - that might be a reason for your session to "hang".
Re: what's wronge with this procedure ? [message #453919 is a reply to message #453855] Mon, 03 May 2010 01:42 Go to previous messageGo to next message
ahmed_samir
Messages: 61
Registered: January 2009
Location: EGYPT
Member
hi there

thanks Littlefoot

for your help and you important tips .. but why u don't use ' commit ' after made update .. coz am changed my code by add ' commit' in the code and worked well now ..

why u don't use it .. ?

or am mistaken again ??

my code now :
/* Formatted on 2010/05/03 09:41 (Formatter Plus v4.8.8) */
CREATE OR REPLACE PROCEDURE accurate.items_control (
   pram_store_id   IN       NUMBER,
   pram_item_id    IN       NUMBER,
   pram_what       IN       NUMBER,
   pram_amount     IN       NUMBER,
   pram_result     OUT      VARCHAR2
)
IS
BEGIN
   IF pram_what = 1
   THEN
      UPDATE accurate.wh_startyear
         SET sy_start_amount = pram_amount
       WHERE finance_year = 2010
         AND store_id = pram_store_id
         AND item_id = pram_item_id;

      COMMIT;

      --pram_result := 'Saved .. ';
      IF SQL%ROWCOUNT = 1
      THEN
         pram_result := 'Saved .. ';
      ELSE
         ROLLBACK;
         pram_result := 'more than one record ';
      END IF;
   END IF;
END items_control;
/

Re: what's wronge with this procedure ? [message #453945 is a reply to message #453919] Mon, 03 May 2010 02:28 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I don't think that commit (where you put it) has anything to do with a "hanging" form.

Besides, COMMIT should be done once the transaction is complete. Is it complete when your stored procedure ends? If so, commit. If not (who is to decide? A caller - form in your case), then procedure should NOT commit, but caller - once the transaction is over.
Re: what's wronge with this procedure ? [message #453976 is a reply to message #453855] Mon, 03 May 2010 04:38 Go to previous messageGo to next message
ahmed_samir
Messages: 61
Registered: January 2009
Location: EGYPT
Member
no . the problem of hang like what u say before:

Quote:
Make sure that no other session is holding a table you are updating - that might be a reason for your session to "hang".


but about the commit .. i don't understand what u say .. but .. when i try to run the procedure with commit word .. nothing happen

do u have any sound ..
Re: what's wronge with this procedure ? [message #453978 is a reply to message #453976] Mon, 03 May 2010 05:12 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
"Nothing happens" probably means that you (actually, your other SQL*Plus (or TOAD or Forms or ...) session) can't see changes made by an UPDATE statement until you commit.

That's expected.

There's no doubt that you, eventually, *must* commit if you want those changes to be permanent. Question is only when to commit. It is to be done once the transaction is over.

A form button calls a stored procedure that does the update. But, there might also be some code that follows procedure call - some computations, validations, whatever. If this part of code fails, you must rollback all you did so far (otherwise, consistency is just a word). How can you rollback the whole transaction if procedure already commited its update? You can't!

Once again: commit after the transaction is finished - not in the middle of it.
icon14.gif  [ solved ] Re: what's wronge with this procedure ? [message #453981 is a reply to message #453855] Mon, 03 May 2010 05:33 Go to previous message
ahmed_samir
Messages: 61
Registered: January 2009
Location: EGYPT
Member
thanks .. Littlefoot

i get it ..

i understand now .. and made all changes ..

thanks
Previous Topic: How to get next value in froms
Next Topic: frm-18108 unable to load the following objects
Goto Forum:
  


Current Time: Fri Sep 20 08:42:03 CDT 2024