Re: Generation of automatic unique identifier such as CUSTOMER_ID

From: DA Morgan <damorgan_at_exxesolutions.com>
Date: Sun, 16 Mar 2003 09:28:00 -0800
Message-ID: <3E74B420.2BD3ACA3_at_exxesolutions.com>


Tim Corke wrote:

> Hi,
>
> I cannot seem to get this function to work on my database. Once alert
> button1 is selected I want to get a unique indentifier to appear in my
> forms.
>
> This PL/SQL runs from a WHEN-BUTTON-PRESSED trigger from my MENU block
> to P_CUST block.
>
> declare
>
> alert_button NUMBER;
> X NUMBER;
> BEGIN
> alert_button := Show_Alert('CHOOSE_CUSTOMER');
>
>
>
> IF alert_button = ALERT_BUTTON1 THEN
>
> SELECT COUNT(*)
> INTO X
> FROM P_CUST;
>
> IF X = 0 THEN
> :P_CUST.PC_ID := 1;
>
> END IF;
> GO_ITEM('P_CUST.PC_FNAME');
>
>
>
> ELSE IF alert_button = ALERT_BUTTON2 THEN
> GO_ITEM('C_CUST.CC_NAME');
>
> END IF;
> END IF;
>
>
> END;
>
> I am running a PRE-BLOCK trigger that is
> SELECT MAX('PC_ID')+1
> INTO :P_CUST.PC_ID
> FROM P_CUST;
>
> This will be repeated for C_CUST also.
>
> Any ideas???
>
> Many Thanks
> Tim

Follow Sybrand's advice but take a good look at your code.

A little formatting would go a long way to making it more readable.

DECLARE alert_button NUMBER;

x                NUMBER;

BEGIN
   alert_button := SHOW_ALERT('choose_customer');

   IF alert_button = ALERT_BUTTON1 THEN

      SELECT sequence_name.NEXTVAL
      INTO x
      FROM dual;

      :P_CUST.PC_ID := x;

      GO_ITEM('P_CUST.PC_FNAME');
   ELSIF alert_button = ALERT_BUTTON2 THEN
      GO_ITEM('C_CUST.CC_NAME');

   END IF;
END; Daniel Morgan Received on Sun Mar 16 2003 - 18:28:00 CET

Original text of this message