Providing bind variables as values in an insert statement inside PL/SQL block not working ? [message #520612] |
Tue, 23 August 2011 12:30 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](//www.gravatar.com/avatar/9b7e2c0ac90e50a012af74d7651cff53?s=64&d=mm&r=g) |
daudiam
Messages: 51 Registered: June 2011
|
Member |
|
|
I executed the following PL/SQL block in SqlDeveloper :
VARIABLE max_dept_no NUMBER
DECLARE
v_dept_name VARCHAR2(30) := '&p_dept_name';
v_max NUMBER(4,0);
BEGIN
SELECT MAX(department_id) INTO v_max FROM departments;
:max_dept_no := v_max + 20;
INSERT INTO departments VALUES (:max_dept_no,v_dept_name, NULL,NULL) ;
END;
/
And it gave the error : Quote:Error report:
ORA-01400: cannot insert NULL into ("HR"."DEPARTMENTS"."DEPARTMENT_ID")
ORA-06512: at line 7
01400. 00000 - "cannot insert NULL into (%s)"
The same code when executed in iSqlPlus gave no error. I can't understand why.
|
|
|
|
|
|
|
|
|
Re: Providing bind variables as values in an insert statement inside PL/SQL block not working ? [message #520624 is a reply to message #520622] |
Tue, 23 August 2011 13:45 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
John Watson
Messages: 8964 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
I get the same effect as OP. In SQL*Plus:orcl> VARIABLE max_dept_no NUMBER
orcl> DECLARE
2 v_dept_name VARCHAR2(30) := '&p_dept_name';
3 v_max NUMBER(4,0);
4 BEGIN
5 SELECT MAX(department_id) INTO v_max FROM departments;
6 :max_dept_no := v_max + 20;
7 INSERT INTO departments VALUES (:max_dept_no,v_dept_name, NULL,NULL) ;
8 END;
9 /
Enter value for p_dept_name: new
old 2: v_dept_name VARCHAR2(30) := '&p_dept_name';
new 2: v_dept_name VARCHAR2(30) := 'new';
PL/SQL procedure successfully completed.
orcl> And running it in SQLDeveloper, this is the output:Error starting at line 2 in command:
DECLARE
v_dept_name VARCHAR2(30) := '&p_dept_name';
v_max NUMBER(4,0);
BEGIN
SELECT MAX(department_id) INTO v_max FROM departments;
:max_dept_no := v_max + 20;
INSERT INTO departments VALUES (:max_dept_no,v_dept_name, NULL,NULL) ;
END;
Error report:
ORA-01400: cannot insert NULL into ("HR"."DEPARTMENTS"."DEPARTMENT_ID")
ORA-06512: at line 7
01400. 00000 - "cannot insert NULL into (%s)"
*Cause:
*Action:
This is database 11.2.0.2, SQL Developer 1.5.5
I reckon we don't understand how to use SQL Developer.
|
|
|
|
|
|
|
|
|