Home > Blockchain >  Bind variable not declared
Bind variable not declared

Time:10-27

I am an absolute begginer to PL/SQL, and I was solving some simple exercises like this. Why do I get the error:

Bind Variable "RESS," is NOT DECLARED
Bind Variable "MAXX" is NOT DECLARED

and how can I make it work?

VARIABLE ress VARCHAR2(35)
VARIABLE maxx INT
BEGIN
    SELECT department_name, count(*)
    INTO :ress, :maxx
    FROM employees e, departments d
      WHERE e.department_id=d.department_id
    GROUP BY department_name
    HAVING COUNT(*) = (SELECT MAX(COUNT(*))
                       FROM employees
                       GROUP BY department_id);

    END;
/
PRINT ress, maxx;

CodePudding user response:

PL/SQL means Oracle.

I'm running this (similar to your code, only simplified) in SQL*Plus, Oracle's command line tool:

SQL> var ress varchar2(10);
SQL> begin
  2    select 'a' into :ress from dual;
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> print ress

RESS
--------------------------------
a

SQL>

As you can see, no such error.


Which tool do you use?

CodePudding user response:

The ";" is missing after the variable declaration.

Maybe try it like this:

VARIABLE ress VARCHAR2(35);
VARIABLE maxx INT;
BEGIN
    SELECT department_name, count(*)
    INTO :ress, :maxx
    FROM employees e, departments d
      WHERE e.department_id=d.department_id
    GROUP BY department_name
    HAVING COUNT(*) = (SELECT MAX(COUNT(*))
                       FROM employees
                       GROUP BY department_id);

    END;
/
PRINT ress, maxx;
  • Related