PLS-00103: Encountered the symbol - plsql

i am trying to compile this function
CREATE OR REPLACE FUNCTION sql_error_msg (err_num PLS_INTEGER)
RETURN VARCHAR2 IS
BEGIN
RETURN sqlerrm(-err_num);
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END sql_error_msg
/
but i am getting this error:
FUNCTION SQL_ERROR_MSG
On line: 8
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
;
The symbol ";" was substituted for "end-of-file" to continue.

Just add ; at the end of the function.
END sql_error_msg;
/

I was trying to execute PL/SQL that "creates or replaces" a function, using <jdbc:initialize-database> tag. I was given the PLS-00103 and it turned out PL/SQL is not currently supported this way.
You have to execute the script in a different way.
I am going to try directly with JDBC as per http://www.coderanch.com/t/298532/JDBC/databases/run-SQL-Script-file-JDBC
and work out a solutiom from there.

Related

CREATE FUNCTION throws SQL Error (1064) (42000)

I'm trying to create a stored function in a MariaDB database.
I copied the function I'm trying to create from the MariaDB Docs:
DELIMITER //
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DECLARE x TINYINT;
SET x = 42;
RETURN x;
END
//
DELIMITER ;
Unfortunately, I get the following error:
SQL Error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
What baffles me most is that the given code is supposed to resolve the very error code I'm getting according to the MariaDB docs
The solution is to specify a distinct delimiter for the duration of the process, using the DELIMITER command
It turned out, the client I used to issue the command, DBeaver, was causing the trouble.
After switching over to MySqlWorkbench everything worked as expected.
Apparently, DBeaver didn't recognise the delimiters correctly..
I think you may have forgotten to select the database you want this routine to be stored into.
So try adding a use as the first line
use `test`;
DELIMITER //
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DECLARE x TINYINT;
SET x = 42;
RETURN x;
END
//
DELIMITER ;

oracle plsql stored procedure error handling ora-6502

create procedure about_emp(p_empno in number,p_ename out varchar2)
is
begin
select ename into p_ename from emp
where empno=p_empno;
exception
when no_data_found then
dbms_output.put_line('your id not available');
when value_error then
dbms_output.put_line('enter exact data');
end;
execution
variable x varchar2(10);
exec about_emp(4520,:x);
X
michel
exec about_emp(1111,:x);
you id not available
exec abot_emp('a',:x);
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at line 1
but normally in store procedure are display like
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "SCOTT.about_emp", line 4
ORA-06512: at line 1
please find the error and give me the solution
Well, either you have declared X variable too small to hold the value of empno.ename, so make it larger. If you also want to see the output from dbms_output in sqlplus, you need to enable: "set serveroutput on"
Procedure about_emp expects number data type as first formal parameter and varchar as second formal parameter.
create procedure about_emp(p_empno in number,p_ename out varchar2)
But while executing you are supplying varchar data type for the first formal parameter (where number is expected)
exec abot_emp('a',:x);
Oracle can't do implicit conversion of a to a number, so that is why you are getting error ERROR at line 1: ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at line 1
You should call this procedure supplying first actual parameter as number and second parameter as varchar (or compatible (or convertable) data types )
As per exec about_emp(1111,:x); you id not available
This is just output from trapped exception
exception
when no_data_found then
dbms_output.put_line('your id not available');
It mean's that SELECT returned empty result set, there is no such data in the table.
UPDATE OP asked how to handle errors in PL/SQL
1st option - You need to associate error with the definition
PRAGMA EXCEPTION_INIT(invalid_implicit_conversion, -6789);
and then trap error in EXCEPTION section.
EXCEPTION
WHEN invalid_implicit_conversion
THEN ...
2nd option -
EXCEPTION
WHEN OTHERS // this will trap any exception
IF SQLCODE = -6789 THEN ...

procedure created with compilation error

CREATE OR REPLACE PROCEDURE ex9a(n NUMBER ,c CHAR) IS
pi NUMBER(7,4):=3.14;
v_record Areas%rowtype;
BEGIN
IF c='R' THEN
DBMS_OUTPUT.PUT_LINE('CHOICE : R');
v_record.Input_Value:= n;
v_record.Circle_Area:=pi*n*n;
v_record.Square_Area:=null;
v_record.Sphere_Area:=2*pi*n;
v_record.Sphere_Volume:=(3/4)*r*r;
v_record.Cube_Volume:=null;
END IF;``
END;
/
I am getting procedure created with compilation errors.I want to compute area of a circle and insert it into the table .
When I give SHOW ERRORS , it lists the errors as
1) plsql statement
2) 'R' must be declared .
(Even after I gave 'then'. I forgot the line number)
It would help if you would list the errors, and the lines on which they occur.
However, one obvious issue is that your IF statement has no THEN. It should be:
IF c = 'R' THEN

PLS-00103 error when creating object type

I am trying to create and assign variables using following code to create object types in plsql (11g) but facing some errors:
begin
execute immediate 'drop type picu_obj force';
execute immediate 'drop type picu_obj_tab force';
execute immediate 'create type picu_obj as object(Customer_ID varchar2(32767),Customer_Name varchar2(32767),Server_Name varchar2(32767),Time_stamp varchar2(32767))';
execute immediate 'create type picu_obj_tab is table of picu_obj;';
picu_var picu_obj_tab;
picu_var := picu_obj_tab(picu_obj('101','xyz','pro-ssr-qr','12:13'));
end;
The above code gives following errors:
ERROR at line 6:
ORA-06550: line 6, column 10:
PLS-00103: Encountered the symbol "PICU_OBJ_TAB" when expecting one of the
following:
:= . ( # % ;
The symbol ":=" was substituted for "PICU_OBJ_TAB" to continue.
Please suggest what I am doing wrong here.
There are two problems with this code:
First: In Oracle 11g you can not use varchar2(32767) the maximum length is 4000 for a varchar there. So even if the code did run, it wouldn't create the types.
Secondly: the PL/SQL code is validated/compiled when you run it. But as you use dynamic SQL to create the types, the PL/SQL compiler can't see those types when it tries to compile the lines:
picu_var picu_obj_tab;
picu_var := picu_obj_tab(picu_obj('101','xyz','pro-ssr-qr','12:13'));
and that's the error you are seeing.
You have to create the types before you run PL/SQL code that uses them.

PL/SQL script giving errors

I've to work on some older EDW scripts, which I think are in PL/SQL and queries fech data from Oracle table as well. But there is some problem with them, the part which declares variables, as shown in the image gives error. I'm unable to understand why?
Below is some part of script,
VARIABLE begin_exp_date varchar2(8)
VARIABLE end_exp_date varchar2(8)
VARIABLE begin_cal_key number
Declare
begin
:begin_exp_date := 'begin_exp_date';
:end_exp_date := 'end_exp_date';
:begin_cal_key := 'begin_cal_key';
end;
These lines produce error ORA-00900: Invalid SQL statement.
Any help?
If you plug the script in SQL*Plus, it will be executed without the ORA-00900 error. I guess you received the error when it was run in Toad.
If it is indeed PL/SQL, it should be more like this
DECLARE
begin_exp_date varchar2(8);
end_exp_date varchar2(8);
begin_cal_key number;
BEGIN
begin_exp_date := 'begin_exp_date';
-- and so on
END;
You can set constant values to the variables in the DECLARE section if you want. Note that you've defined begin_cal_key as a NUMBER so cannot assign the string 'begin_cal_key'

Resources