Home » SQL & PL/SQL » SQL & PL/SQL » PLS-00201: identifier 'EMPNO' must be declare
PLS-00201: identifier 'EMPNO' must be declare [message #606712] Tue, 28 January 2014 06:06 Go to next message
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 #606714 is a reply to message #606712] Tue, 28 January 2014 06:08 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
So, what is EMPNO in line 10?
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606715 is a reply to message #606714] Tue, 28 January 2014 06:10 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
EMPNO is a number data type
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606716 is a reply to message #606715] Tue, 28 January 2014 06:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

No, it is not as it is declared nowhere.

Re: PLS-00201: identifier 'EMPNO' must be declare [message #606717 is a reply to message #606716] Tue, 28 January 2014 06:17 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi
Michel Cadot,

I declared empno emp%rowtype; I got PLS-00306: wrong number or types of arguments in call to 'IS
NULL'

Thank You
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606718 is a reply to message #606717] Tue, 28 January 2014 06:18 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Looking at the code it seems that empno needs to a parameter.
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606719 is a reply to message #606718] Tue, 28 January 2014 06:20 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Once you've fixing that:
dbms.output.put_line

should be:
dbms_output.put_line

but you shouldn't use dbms_output for anything other than debugging.

And form_trigger_failure is a forms thing. The DB has no idea what it is.
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606720 is a reply to message #606719] Tue, 28 January 2014 06:26 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Please how to remove this error..

  1  CREATE OR replace PROCEDURE Validate_emp_id_yn
  2  IS
  3    CURSOR cu_emp_count(v_empno number) IS
  4      SELECT Count(*)
  5      FROM   emp
  6      WHERE  empno = v_empno;
  7    lv_count NUMBER;
  8    v_empno emp.empno%type;
  9    v_message varchar2(1000);
 10  BEGIN
 11      IF v_empno IS NULL THEN
 12        v_message:='empno error';
 13        dbms_output.put_line(v_message);
 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        END IF;
 22      END IF;
 23* END;
SQL> /

Warning: Procedure created with compilation errors.

SQL> show error
Errors for PROCEDURE VALIDATE_EMP_ID_YN:

LINE/COL ERROR
-------- --------------------------------------------------------------
15/7     PL/SQL: SQL Statement ignored
15/25    PLS-00201: identifier 'EMPNO' must be declared
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606721 is a reply to message #606720] Tue, 28 January 2014 06:29 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
sorry to all , now i got it.. Smile

OPEN cu_emp_count(empno);
--> At 15 line

Modify as

OPEN cu_emp_count(v_empno);


Once again sorry.. Smile
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606723 is a reply to message #606721] Tue, 28 January 2014 06:34 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Ok Now how can i call this procedure on TOAD, it directly display the eror as "empno error",
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606724 is a reply to message #606721] Tue, 28 January 2014 06:35 Go to previous messageGo to next message
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 #606725 is a reply to message #606724] Tue, 28 January 2014 06:37 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Thanks to all..Smile
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606728 is a reply to message #606725] Tue, 28 January 2014 06:46 Go to previous messageGo to next message
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 #606729 is a reply to message #606728] Tue, 28 January 2014 06:49 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Great cookiemonster.. Smile

Thank You
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606847 is a reply to message #606712] Thu, 30 January 2014 00:09 Go to previous messageGo to next message
subhra_88
Messages: 14
Registered: April 2007
Location: Bangalore
Junior Member
Another way of writing the SQL without using 'count' could be:

Select 1 INTO lv_count;
    FROM emp
    WHERE empno = in_emp_id;

IF SQL%NOTFOUND then
    dbms_output.put_line('empno error');
end if;


I think this would be a better way rather than counting to check if a record is there in the table or not.

[Updated on: Thu, 30 January 2014 00:46]

Report message to a moderator

Re: PLS-00201: identifier 'EMPNO' must be declare [message #606860 is a reply to message #606847] Thu, 30 January 2014 02:48 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
1. But your code ONLY caters for when in_emp_id doesn't exist in the table, it fails to cater for when there is more than one row.
2. In what way is it better, why do you think that it is better?

Swing and a miss
Re: PLS-00201: identifier 'EMPNO' must be declare [message #606862 is a reply to message #606847] Thu, 30 January 2014 02:50 Go to previous messageGo to next message
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 Go to previous message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
cookiemonster wrote on Thu, 30 January 2014 08:50
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.
Doh. More coffee needed (actually, I haven't had any yet, that's my excuse, I'm sticking to it.
Previous Topic: Convert date format for easier lookup
Next Topic: How to store the table data(Backup)
Goto Forum:
  


Current Time: Fri Apr 26 07:56:00 CDT 2024