Simple task
variable dept_id NUMBER
DECLARE
max_deptno NUMBER;
dept_name departments.department_name%TYPE := 'Education';
BEGIN
select max(department_id)
into max_deptno
from departments;
:dept_id := max_deptno + 10;
insert into departments (department_id, department_name, location_id)
values (:dept_id, dept_name, null);
DBMS_OUTPUT.PUT_LINE('The maximum department id is ' || max_deptno);
DBMS_OUTPUT.PUT_LINE('Rows made by insert: ' || SQL%ROWCOUNT);
END;
max_deptno is not NULL. Why dept_id is NULL after assignment? What am I doing wrong?
script output:
MAX(DEPARTMENT_ID)
------------------
520
Error starting at line 10 in command:
DECLARE
max_deptno NUMBER;
dept_name departments.department_name%TYPE := 'Education1';
BEGIN
select max(department_id)
into max_deptno
from departments;
:dept_id := max_deptno + 10;
insert into departments (department_id, department_name, location_id)
values (:dept_id, dept_name, null);
DBMS_OUTPUT.PUT_LINE('The maximum department id is ' || max_deptno);
DBMS_OUTPUT.PUT_LINE('Rows made by insert: ' || SQL%ROWCOUNT);
END;
Error report:
ORA-01400: невозможно вставить NULL в ("ANDKOM"."DEPARTMENTS"."DEPARTMENT_ID")
ORA-06512: на line 9
01400. 00000 - "cannot insert NULL into (%s)"
*Cause:
*Action:
MAX_DEPTNOis NOT NULL? Can you show us the results ofSELECT MAX(department_id) FROM andkom.departments?DEPT_ID, 2)set serveroutput on, 3)SELECT MAX(department_id) from andkom.departments, and then 4) run the PL/SQL block you posted? Something doesn't make sense.