Skip to Main Content
  • Questions
  • Oracle identity column failed to generate auto value while triggering from Oracle Stored Procedure

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Ifta.

Asked: February 05, 2021 - 10:38 am UTC

Last updated: February 09, 2021 - 4:47 pm UTC

Version: Oracle 12C

Viewed 1000+ times

You Asked

I'm using Oracle 12C.

All of my stored procedures worked so far for the last 6 months but from today some of them are not working.

create table Table1
(
 ID NUMBER generated by default on null as identity
  constraint FGEN_PAY_FLEX_PK
   primary key,
 CARD_NO VARCHAR2(19) not null
);

Use Case-1

Expectation:
The following statement will work without error -
Insert Into Table1(Card_No) value('12345');

Actual:
Yes, it is working. Oracle is generating an id for the identity column.

Use Case-2

Expectation:
The following statement will work without error -

create PROCEDURE        MY_SAMPLE_PROCEDURE(I_CARD_NUMBER IN VARCHAR2)
AS

BEGIN

    INSERT into Table1 (Card_No)
    select '12345' FROM DUAL;
     
END LOAD_SINGLE_PAYFLEX_DATA;
/


declare

   I_CARD_NUMBER VARCHAR2(100) := '12345';
         begin
                MY_SAMPLE_PROCEDURE(
                  I_CARD_NUMBER=> I_CARD_NUMBER
                 );
         end;




Actual:
No, it's not working now. It worked 2 days ago.

I'm getting the following exception while trying to execute the procedure -

ORA-01400: cannot insert NULL into ("STATEMENT"."Table1"."ID")

and Chris said...

It looks fine to me...

create table table1 (
 id number generated by default on null as identity
  constraint fgen_pay_flex_pk
  primary key,
 card_no varchar2(19) not null
);

create or replace procedure my_sample_procedure(i_card_number in varchar2)
as
begin

    insert into table1 (card_no)
    select '12345' from dual;
     
end my_sample_procedure;
/

declare
   i_card_number varchar2(100) := '12345';
begin
   my_sample_procedure(
     i_card_number=> i_card_number
   );
end;
/

select * from table1;

ID    CARD_NO   
    1 12345      


No, it's not working now. It worked 2 days ago.

So what changed?

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.