0

I have created one table in PL SQL Developer.

CREATE TABLE Patient_List
(
   Patient_ID number NOT NULL,
   Patient_Name varchar(50) NOT NULL,
   Patient_Address varchar(100) NULL,
   App_Date date NULL,
   Descr varchar(50),
   CONSTRAINT patient_pk PRIMARY KEY(Patient_ID)
);

I want to auto increment Patient_ID, I tried altering the table and modifying the Patient_ID column but it's showing an error "invalid ALTER TABLE option"

ALTER TABLE Patient_List
MODIFY Patient_ID NUMBER NOT NULL GENERATED ALWAYS AS IDENTITY;

Please help, Thanks in advance.

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
Shreyas Pednekar
  • 1,143
  • 5
  • 23
  • 53

2 Answers2

3

This is not possible.

Oracle 10g didn't even have identity columns, they were introduced in Oracle 12.1

But even with a current Oracle version, you can't convert a regular column to an identity column. You would need to add a new one.

Before identity columns, the usual way was to create a sequence and a trigger to populate the column.

See here: How to create id with AUTO_INCREMENT on Oracle?

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
0

If anybody wants to modify existing column as auto_increment use this three lines

alter table Product drop column test_id;

create sequence Product_test_id_seq INCREMENT BY 1 nocache;

alter table Product add test_id Number default Product_test_id_seq.nextval not null;