PLS-00201: identifier 'EMPNO' must be declare [message #606712] |
Tue, 28 January 2014 06:06 |
|
mist598
Messages: 1195 Registered: February 2013 Location: Hyderabad
|
Senior Member |
|
|
Hi all,
Can you please help me how to remove these error's.
1 CREATE OR replace PROCEDURE Validate_emp_id_yn
2 IS
3 CURSOR cu_emp_count(in_emp_id VARCHAR2) IS
4 SELECT Count(*)
5 FROM emp
6 WHERE empno = in_emp_id;
7 lv_count NUMBER;
8 v_message varchar2(1000);
9 BEGIN
10 IF empno IS NULL THEN
11 v_message:='empno error';
12 dbms.output.put_line(v_message);
13 RAISE form_trigger_failure;
14 ELSE
15 OPEN cu_emp_count(empno);
16 FETCH cu_emp_count INTO lv_count;
17 CLOSE cu_emp_count;
18 IF ( lv_count > 0 ) THEN
19 v_message:='empno error';
20 dbms.output.put_line(v_message);
21 RAISE form_trigger_failure;
22 END IF;
23 END IF;
24* END;
SQL> /
Warning: Procedure created with compilation errors.
SQL> show error
Errors for PROCEDURE VALIDATE_EMP_ID_YN:
LINE/COL ERROR
-------- --------------------------------------------------
10/5 PL/SQL: Statement ignored
10/8 PLS-00201: identifier 'EMPNO' must be declared
SQL>
Thank You
[Updated on: Tue, 28 January 2014 06:08] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606724 is a reply to message #606721] |
Tue, 28 January 2014 06:35 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
SQL> CREATE OR REPLACE PROCEDURE VALIDATE_EMP_ID_YN(IN_EMP_ID NUMBER) AS
2 CURSOR CU_EMP_COUNT(IN_EMP_ID VARCHAR2) IS
3 SELECT COUNT(*) FROM EMP WHERE EMPNO = IN_EMP_ID;
4 LV_COUNT NUMBER;
5 V_MESSAGE VARCHAR2(1000);
6 EMP_NO NUMBER;
7 BEGIN
8 IF IN_EMP_ID IS NULL THEN
9 V_MESSAGE := 'empno error';
10 DBMS_OUTPUT.PUT_LINE(V_MESSAGE);
11 --RAISE FORM_TRIGGER_FAILURE;
12 ELSE
13 OPEN CU_EMP_COUNT(IN_EMP_ID);
14 FETCH CU_EMP_COUNT
15 INTO LV_COUNT;
16 CLOSE CU_EMP_COUNT;
17 IF (LV_COUNT > 0) THEN
18 V_MESSAGE := 'empno error';
19 DBMS_OUTPUT.PUT_LINE(V_MESSAGE);
20 --RAISE FORM_TRIGGER_FAILURE;
21 END IF;
22 END IF;
23 END;
24 /
Procedure created
SQL> sho err;
No errors for PROCEDURE VALIDATE_EMP_ID_YN
SQL> set serveroutput on;
SQL> BEGIN
2 VALIDATE_EMP_ID_YN(NULL);
3 END;
4
5 /
empno error
PL/SQL procedure successfully completed
Problems with your code :
1. It's DBMS_OUTPUT and not DBMS.OUTPUT
2. You need to have an IN parameter for the employee number which you want to check.
3. Why PL/SQL for this? Is it something related to FORMS? Else you could achieve it through plain SQL too.
[Updated on: Tue, 28 January 2014 06:37] Report message to a moderator
|
|
|
|
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606728 is a reply to message #606725] |
Tue, 28 January 2014 06:46 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
It's still overcomplicated, empno is not needed, the explicit cursor is not needed, v_message is not needed and the code doesn't actually check for the emp not existing. This would be closer:
CREATE OR REPLACE PROCEDURE validate_emp_id_yn(in_emp_id emp.empno%TYPE) AS
lv_count NUMBER;
BEGIN
IF in_emp_id IS NULL THEN
dbms_output.put_line('empno error');
ELSE
SELECT COUNT(*) INTO lv_count;
FROM emp
WHERE empno = in_emp_id;
IF lv_count != 1 THEN
dbms_output.put_line('empno error');
END IF;
END IF;
END;
/
|
|
|
|
|
|
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606862 is a reply to message #606847] |
Thu, 30 January 2014 02:50 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Except that doesn't work. Ignoring the obvious typo there is no point checking %notfound after a select into. If the select fails to find any rows then a no_data_found error is raised and the if statement is never executed.
You can do it without the count but you need to add the appropriate exception handlers.
|
|
|
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606863 is a reply to message #606862] |
Thu, 30 January 2014 02:59 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
cookiemonster wrote on Thu, 30 January 2014 08:50Except that doesn't work. Ignoring the obvious typo there is no point checking %notfound after a select into. If the select fails to find any rows then a no_data_found error is raised and the if statement is never executed. Doh. More coffee needed (actually, I haven't had any yet, that's my excuse, I'm sticking to it.
|
|
|