Encountered the symbol "=" - oracle

I'm getting an error when using the below PL/SQL:
1 DECLARE
2 var_salary number(6);
3 var_emp_id number(6) =7788;
4 BEGIN
5 SELECT sal
6 INTO var_salary
7 FROM emp
8 WHERE emp.empno =var_emp_id;
9 dbms_output.put_line(var_salary);
10* end;
SQL> /
var_emp_id number(6) =7788;
*
ERROR at line 3:
ORA-06550: line 3, column 23:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
:= ; not null default character
The symbol ":= was inserted before "=" to continue.
I'm a beginner and can't work out why I'm getting an error

= is an equality operator, but you're using it in an assignment. The assignment operator is :=.
Change:
var_emp_id number(6) =7788;
to
var_emp_id number(6) := 7788;
It's worth noting that the error message you got gave you a few hints about what's wrong; it told you the line and column and then that you'd got the operator incorrect:
The symbol ":= was inserted before "=" to continue.

Use assignment operator (:=) instead of equality operator (=) in line number 3

Related

ORACLE PLS-00103:, ORA-06550: := . ( # % ;

I've got a problem with procedure:
create or replace
PROCEDURE SOLVER AS
IS_ACTIVE "Parameter"."Value"%TYPE;
BEGIN
BEGIN
SELECT "Value" INTO IS_ACTIVE from "Parameter" WHERE "Name" = 'ARCHIVER';
EXCEPTION
WHEN OTHERS THEN
IS_ACTIVE:='OFF';
END;
When I try to run it, I gets an Error:
Error report:
ORA-06550: line 3, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
:= . ( # % ;
The symbol ";" was substituted for "END" to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
Version 3.2.09
Main Build 09-30
The error message strongly suggests you are getting the error when you call the procedure, not when you create it (and you did refer to 'when I try to run it'); so you are doing this:
begin
solver
end;
/
which generates exactly that error.
If you add a semicolon it will work:
begin
solver;
end;
/
db<>fiddle

Exception PL/SQL

Caution my english is horrible.
No one answers in the spanish forum.
doubts :
¿How can I control the exception of a empty entry? (Explanation following)
¿What value is saved in the variable if there's an empty entry?
I created this variable:
DECLARE
v_input NUMBER(8) := &entry;
I don't give a value, I mean in the pop up I accept directly without writing anything.
POPUP IMG
when I read the error code ( that I will leave at the end), I came across this line.
PLS-00103: Encountered the symbol ' ; ' when expecting one of the following :
So I guess the variable default value if you do a empty entry is -> ;
then I thought of controling the exception creating a IF, this if compares my variable (with empty entry/value) to ' ; ' you can see below.
BEGIN
DBMS_OUTPUT.PUT_LINE(v_codigo);
IF(v_codigo = ';')THEN
RAISE v_excepcion;
END IF;
EXCEPTION
when v_excepcion then
DBMS_OUTPUT.PUTLINE('No has insertado un valor válido');
END;
ERROR CODE
Informe de error -
ORA-06550: línea 2, columna 32:
PLS-00103: Se ha encontrado el símbolo ";" cuando se esperaba uno de los siguientes:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an al
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
sorry for my grammar mistakes, If it does not clear I will follow the post for give you more information.
thx
Exception handlers are for exceptions (errors) encountered during execution of your function or procedure or anonymous block. They don't handle syntax errors - where the function or procedure won't even compile.
You are using a substitution variable - one that is "substituted" (replaced) by your editor BEFORE the code is ever presented to the PL/SQL parser. THAT kind of error can't be anticipated and handled in the code - if you return nothing (an empty string) when prompted, the code itself will receive "nothing" in that place, and the syntax of your function or procedure will be incorrect, so you will get the syntax error you received. Your code looks exactly like this after the substitution:
v_input NUMBER(8) := ;
resulting exactly in the syntax error you have seen.
The correct way to pass in a value at run time is to use parameters (for functions or procedures), or bind variables in an anonymous block. The variable must be declared and initialized before executing the block (in a command line environment like SQL*Plus); or, in a GUI like Toad or SQL Developer, you will be prompted for a value for the bind variable. If you press Enter without giving a value, that is interpreted as NULL, which is perfectly valid. (Whether it is what you want or not, that's a different question.)
The code would have to look something like this:
declare
v_input number(8) := :entry; -- notice the leading colon :
begin
dbms_output.put_line(v_input);
end;
/
If you want to handle the case of NULL input, you would do it in code:
declare
v_input number(8) := :entry;
begin
if v_input is null then
-- handle it here
else
dbms_output.put_line(v_input); -- or whatever else you need to do
end if;
end;
/
You don't need exception to handle that; you could dbms_output.put_line (note that you used putline, which is wrong) within IF, or even raise_application_error if you want to stop execution. For example (valid value first):
SQL> declare
2 v_codigo varchar2(20) := '&entry';
3 begin
4 if v_codigo = ';' or v_codigo is null then
5 raise_application_Error(-20000, 'Invalid value');
6 else
7 dbms_output.put_line('You entered ' || v_codigo);
8 end if;
9 end;
10 /
Enter value for entry: Littlefoot
You entered Littlefoot
PL/SQL procedure successfully completed.
Invalid values: empty string and ;;
SQL> /
Enter value for entry:
declare
*
ERROR at line 1:
ORA-20000: Invalid value
ORA-06512: at line 5
SQL> /
Enter value for entry: ;
declare
*
ERROR at line 1:
ORA-20000: Invalid value
ORA-06512: at line 5
SQL>
Or, to reuse your own code: declare the exception first (line #3), then use it:
SQL> declare
2 v_codigo varchar2(20) := '&entry';
3 v_excepcion exception;
4 BEGIN
5 DBMS_OUTPUT.PUT_LINE(v_codigo);
6 IF(v_codigo = ';' or v_codigo is null) THEN
7 RAISE v_excepcion;
8 END IF;
9
10 EXCEPTION
11 when v_excepcion then
12 DBMS_OUTPUT.PUT_LINE('No has insertado un valor válido');
13 END;
14 /
Enter value for entry: Littlefoot
Littlefoot
PL/SQL procedure successfully completed.
SQL> /
Enter value for entry:
No has insertado un valor válido
PL/SQL procedure successfully completed.
SQL> /
Enter value for entry: ;
;
No has insertado un valor válido
PL/SQL procedure successfully completed.
SQL>

Warning: Function created with compilation errors

im having a error im so frustrate right now. I think due to this error im also having another error of cannot reference other columns while adding a check constraint in the table. I have to use this function in check constraint to compare with end time.
1 create or replace function timing(dat in date, bran in varchar2(30), audi in number)
2 return number is time number
3 begin
4 select s_end into time from checking
5 where s_date=dat and branch=bran and a_id = audi;
6 return time;
7* end timing
SQL> /
and my table is
Name Null? Type
----------------------------------------- -------- -------------
S_ID NOT NULL NUMBER
M_ID NUMBER
A_ID NUMBER
S_DATE DATE
S_START NUMBER
S_END NUMBER
BRANCH VARCHAR2(30)
The error is:
1/46 PLS-00103: Encountered the symbol "(" when expecting following: := . ) , # % default character The symbol ":=" was substituted for "(" to continue.
3/1 PLS-00103: Encountered the symbol "BEGIN" when expecting the following: := . ( # % ; not null range default character
The symbol ";" was substituted for "BEGIN" to continue.
7/10 PLS-00103: Encountered the symbol "end-of-file" when expecting
You have posted this same question in a slightly different form. I'll answer here in slightly different form. A check constraint cannot reference a user defined function. Oracle does not permit it so your contention "have to use this function in check constraint" cannot be!
try like this
create or replace function timing(dat in date, bran in varchar2, audi in number)
return number
is
time number;
begin
select s_end into time
from checking
where s_date=dat and branch=bran
and a_id = audi;
return time;
end :
/

PL/SQL : i have a function but there is an error : "in a procedure,RETURN can not contain an expression"

Here is my code:
CREATE OR REPLACE FUNCTION customer_city_function(city_in IN VARCHAR2)
RETURN NUMBER
AS
number_cus NUMBER := 0;
CURSOR cus_cur IS
SELECT COUNT(*)
FROM customer
WHERE customer_city = city_in;
BEGIN
IF city_in IS NOT NULL THEN
OPEN cus_cur;
FETCH cus_cur INTO number_cus;
CLOSE cus_cur;
END IF;
RETURN number_cus;
END;
/
and here is warnings:
Error starting at line : 1 in command -
CREATE OR REPLACE FUNCTION customer_city_function(city_in IN VARCHAR2)
RETURN NUMBER
AS
number_cus NUMBER := 0
Error report -
SQL Command: functıon CUSTOMER_CITY_FUNCTION
Failed: Warning: executing is completed with a warning
Error starting at line : 5 in command -
CURSOR cur_cur IS
Error report -
Unknown Command
Error starting at line : 6 in command -
SELECT COUNT(*)
FROM costumer
WHERE customer_city=city_in
Error at Command Line : 8 Column : 25
Error report -
SQL Error: ORA-00904: "CITY_IN": undefined variable
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error starting at line : 9 in command -
BEGIN
IF city_in IS NOT NULL
THEN
OPEN cus_cur;
FETCH cus_cur INTO number_cus;
CLOSE cus_cur;
END IF;
RETURN (number_cus);
END;
Error report -
ORA-06550: row 2, column 6:
PLS-00201: 'CITY_IN' variable should been defined
ORA-06550: row 2, column 3:
PL/SQL: Statement ignored
ORA-06550: row 8, column 1:
PLS-00372: in a procedure, RETURN can not contain an expression
ORA-06550: row 8, column 1:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Where is my mistake? I can't find it, it doesn't make any sense.
(I translated this warning message from my language. I hope I did it right.)
I have just tried it in Command Window and it works. Why doensn't it work in Oracle SQL Developer sql worksheet?
There is nothing wrong with your posted code. The issue might be with your client or the way you are compiling the code.
As you have mentioned PL/SQL Developer in the tags, it might be possible that you have some extra characters in the SQL Worksheet and you are compiling the function as a script, thus the compiler finds it erroneous.
Here is a demo in SQL*Plus, and there is no error:
SQL> CREATE OR REPLACE FUNCTION customer_city_function(i_deptno IN number)
2 RETURN NUMBER
3 AS
4 number_cus NUMBER := 0;
5 CURSOR cus_cur IS
6 SELECT COUNT(*)
7 FROM emp
8 WHERE deptno=i_deptno;
9 BEGIN
10 IF i_deptno IS NOT NULL
11 THEN
12 OPEN cus_cur;
13 FETCH cus_cur INTO number_cus;
14 CLOSE cus_cur;
15 END IF;
16 RETURN number_cus;
17 END;
18 /
Function created.
SQL> sho err
No errors.
SQL> SELECT customer_city_function(10) FROM DUAL;
CUSTOMER_CITY_FUNCTION(10)
--------------------------
3
SQL>
The only difference in my code is that I have used EMP table instead of CUSTOMERS table and the input parameter is DEPTNO instead of CITY_IN. Rest everything is same and function compiles and executes without any errors.

PL/SQL Procedure is not running properly

Please consider the following code (query.sql):
create or replace function age (dateOfBirth date)
return number
is
mAge number(5,2);
begin
mAge:=(sysdate-dateOfBirth)/365.25;
return mAge;
end;
SQL> #query.sql
13
14
15 /
Warning: Function created with compilation errors.
And when I click on Show error, I get the following:
Code:
SQL> show error
Errors for FUNCTION AGE:
LINE/COL ERROR
-------- -----------------------------------------------------------------
5/8 PL/SQL: Item ignored
5/15 PLS-00325: non-integral numeric literal 5.2 is inappropriate in
this context
8/8 PL/SQL: Statement ignored
8/8 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
9/5 PL/SQL: Statement ignored
9/12 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
LINE/COL ERROR
-------- -----------------------------------------------------------------
I tried to do the following from : Oracle Procedure
1) SQL> set role none;
and
2) SELECT ON DBA_TAB_COLUMNS;
But the second query above is throwing error : Missing expression.
Please let me know what's wrong with all of the above stuff.
Thanks
You're missing a BEGIN and your NUMBER variable should be declared with a comma not a period.
create or replace function age (
pDateOfBirth date ) return number is
l_age number(5,2);
begin
l_age := ( sysdate - pDateOfBirth ) / 365.25;
return l_age;
end;
/
You've now edited the question to include the BEGIN but you haven't fixed your declaration of the variable. As your error message says:
PLS-00325: non-integral numeric literal 5.2 is inappropriate in this context
Personally, I believe you're calculating age incorrectly. There are 365 or 366 days in a year. I'd do this instead, which uses internal Oracle date functions:
function get_age (pDOB date) return number is
/* Return the the number of full years between
the date given and sysdate.
*/
begin
return floor(months_between(sysdate, pDOB)/12);
end;
That is if you only want the number of full years.

Resources