How to use primary key in Oracle Apex form multiple ways.
( "STUDENT_ID" NUMBER,
"STUDENT_NAME" VARCHAR2(250),
"ADDRESS" VARCHAR2(250),
"PHONE" NUMBER,
"DATE1" DATE,
CONSTRAINT "STUDENT_CON" PRIMARY KEY ("STUDENT_ID")
USING INDEX ENABLE
)
/
1st ..................way
Create a Dynamic Action >> Name- PRIMARY KEY
Action >> Execute Server-side code >>
SELECT NVL(MAX(STUDENT_ID),0)+1 INTO :P9_STUDENT_ID
FROM STUDENT;
Items to Return- P9_STUDENT_ID
Action >> Execute Server-side code >>
SELECT NVL(MAX(STUDENT_ID),0)+1 INTO :P9_STUDENT_ID
FROM STUDENT;
Items to Return- P9_STUDENT_ID
Client-side Condition >> Type >> Item is null.
2nd ..................way
Create a Process >> Name- PRIMARY KEY
PL/SQL Code >>
BEGIN
SELECT NVL(MAX(STUDENT_ID),0)+1 INTO :P9_STUDENT_ID
FROM STUDENT;
END;
PL/SQL Code >>
BEGIN
SELECT NVL(MAX(STUDENT_ID),0)+1 INTO :P9_STUDENT_ID
FROM STUDENT;
END;
When Button Pressed >> Create.
3rd ..................way
Create a Process >> Name- PRIMARY KEY
PL/SQL Code >>
declare
function get_pk return varchar2
is
begin
DECLARE
L_PRIMARY_KEY NUMBER;
BEGIN
SELECT NVL(MAX(STUDENT_ID),0) + 1
INTO L_PRIMARY_KEY
FROM STUDENT;
RETURN L_PRIMARY_KEY;
END;
end;
begin
:P9_STUDENT_ID := get_pk;
end;
When Button Pressed >> Create.
4th...................way
CREATE SEQUENCE >>
CREATE SEQUENCE "STUDENT_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 301 CACHE 20 NOORDER NOCYCLE NOKEEP NOSCALE GLOBAL
/
Create a Process >> Name- PRIMARY KEY
PL/SQL Code >>
SELECT STUDENT_SEQ.NEXTVAL INTO :P9_STUDENT_ID FROM DUAL;
5th ..................way
Create a Dynamic Action >> Name- PRIMARY KEY
Action >> Execute Server-side code >>
SELECT STUDENT_SEQ.NEXTVAL INTO :P9_STUDENT_ID FROM DUAL;
Items to Return- P9_STUDENT_ID
Client-side Condition >> Type >> Item is null.
6th..................way
CREATE TRIGGER
PL/SQL Code >>
CREATE OR REPLACE EDITIONABLE TRIGGER "STUDENT"
before insert on "STUDENT"
for each row
begin
if :NEW."STUDENT_ID" is null then
select "STUDENT_SEQ".nextval into :NEW."STUDENT_ID" from sys.dual;
END IF;
END;
/
ALTER TRIGGER "STUDENT" ENABLE
/