Skip to Main Content

Oracle Forms

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Id sequence generator

user626836Mar 23 2015 — edited Mar 24 2015

Hi everyone,

I have Forms 6i and one of you colleague have send me the following code to generate Id's and I have insert this code in my program unit

as a Function Body, but when I compile the program I receive the following error:

PDE-PPU017 The program unit source must define a Subprogram Body or Package.

CREATE OR REPLACE FUNCTION generated_id (p_table VARCHAR2) RETURN NUMBER IS

   l_generated_id NUMBER;

   l_table_name VARCHAR2 (30) := UPPER (p_table);

BEGIN

   BEGIN

     SELECT id INTO l_generated_id

        FROM my_table

       WHERE NOMBRE_TABLE = l_table_name

         FOR UPDATE; -- this locks current row

      l_generated_id := l_generated_id + 1;

      UPDATE my_table

         SET id = l_generated_id

       WHERE NOMBRE_TABLA = l_table_name;

   EXCEPTION

      WHEN NO_DATA_FOUND THEN

         l_generated_id := 1;

         INSERT INTO my_table (NOMBRE_TABLA, id)

              VALUES (l_table_name, l_generated_id);

   END;

   RETURN l_generated_id;

END;

Can anyone please help me solve this issue?

This post has been answered by CraigB on Mar 23 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 21 2015
Added on Mar 23 2015
13 comments
2,495 views