Im getting an Warning: Procedure created with compilation errors - plsql

I'm beginner of pl/sql and I'm learning.
This is my table.
select * from s;
SLNO ENAME SAL
------ -------------------- ----------
1 Shiv 8000
2 Pankaj 9000
3 Prasath 10000
This is my procedure:
set serveroutput on
create or replace procedure p1(n number)
is wname varchar(20);
begin
select ename into wname from s where eid=n;
dbms_output.put_line('------');
dbms_output.put_line('employee name:='||wname);
dbms_output.put_line('------');
end;
I'm getting a warning:
Procedure created with compilation errors.
If I execute the above query. Can anyone please suggest where I'm going wrong please..

You can use the following command.
show errors procedure procedure_name;
to get the list of errors and check that.

There is no column named EID on your table S.

put parameter type IN.
Give procedure like create or replace procedure p1(n IN s.eid%TYPE)
It will work.

I think there's a typo in your program,
try
SET SETVEROUTPUT ON
all in capitals.

Related

What is causing the syntax error in my sql stored procedure?

I'm pretty new at stored procedures and I get the following syntax error in my code:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER //CREATE PROCEDURE sp_create_probe(IN matrix_id INT, IN oligo_id IN...' at line 2
Here's the code for my procedure:
DELIMITER //
CREATE PROCEDURE sp_create_probe(IN matrix_id INT, IN oligo_id INT)
BEGIN
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO Probes (oligo, microarray) VALUES (oligo_id, matrix_id);
SET FOREIGN_KEY_CHECKS=1;
END //
DELIMITER ;
Hope someone can help me out
EDIT:
Well I ended up fixing it. Classic noob mistake.
I had this line before the code you see above:
DROP PROCEDURE IF EXISTS sp_create_probe
Didn't copy that line into the post for some reason but it's missing the ";" at the end. That fixed it.

validate_conversion does not compile in package but as standalone procedure

I'm getting an compilation error, when I try to use validate_conversion in plsql.
Error: PLS-00801: Interner Fehler [*** ASSERT at file pdz2.c, line 5361; The_Exp is null.; TEST__DBNAME__B__2920081[10, 3]]
Line: 10
Text: END;
Funny thing is, this error only occurs if compiled in a package. An MWE is:
CREATE OR REPLACE PACKAGE test IS
PROCEDURE my_VALIDATE_CONVERSION(asNbr VARCHAR2);
END test;
/
CREATE OR REPLACE PACKAGE BODY test IS
PROCEDURE my_VALIDATE_CONVERSION(asNbr VARCHAR2) IS
BEGIN
CASE VALIDATE_CONVERSION(asNbr AS NUMBER, '999999D99', ' NLS_NUMERIC_CHARACTERS = '',.''')
WHEN 1 THEN
DBMS_OUTPUT.PUT_LINE('He');
ELSE
DBMS_OUTPUT.PUT_LINE('Cu');
END CASE;
END;
BEGIN
NULL;
END test;
/
If compiled as standalone procedure my_VALIDATE_CONVERSION it works just fine.
CREATE OR REPLACE PROCEDURE my_VALIDATE_CONVERSION(asNbr VARCHAR2) IS
BEGIN
CASE VALIDATE_CONVERSION(asNbr AS NUMBER, '999999D99', ' NLS_NUMERIC_CHARACTERS = '',.''')
WHEN 1 THEN
DBMS_OUTPUT.PUT_LINE('He');
ELSE
DBMS_OUTPUT.PUT_LINE('Cu');
END CASE;
END;
What's going on here?
Im using:
PL/SQL Developer Version 13.0.6.1911 (64 bit)
Oracle Database 18c Standard Edition 2 Release 18.0.0.0.0
Seems like a bug in the database. I would try upgrading to Oracle 19c or apply the latest patch set to your database. I was able to compile your package in my database (version 19.6.0.0.0) without any errors.
This internal failure for sure will happen with the procedure compilation. The fact that it did not suggests that the compilation of the package was done with PLSQL_DEBUG turned on, and the compilation of the procedure was done without.
When you use this function in package in
Select Validate_Conversion(String AS Number) Into variable From Dual, is compiled successful.
Select Validate_Conversion(p_Oran AS Number) Into IsNumeric From dual; --COMPILED
IsNumeric := Validate_Conversion(p_Oran AS Number); --FAILURE
If Validate_conversion(p_Oran AS Number) = 0 Then --FAILURE
enter image description here

pljson_util_pkg sql_to_json doesn't work if values are less than 1

I have a problem with pljson_util_pkg.sql_to_json
declare
-- Local variables here
tstjson_list pljson_list;
l_Result_json_clob clob;
begin
-- Test statements here
tstjson_list := pljson_list();
dbms_lob.createtemporary(l_Result_json_clob, true);
tstjson_list := pljson_util_pkg.sql_to_json('SELECT 0.1 as tmp from dual');
tstjson_list.to_clob(l_Result_json_clob);
end;
When I execute this code I am getting error message:
Scanner problem with the following input: {"ROWSET":{"ROW":{"TMP":.1}}}
It looks like that if value is less than 1, then this error occurs because instead of 0.1 the result is .1!
Any idea why?
Thank you,
Zoran
Already closed, sorry
I think the reason is how oracle handle numbers in xml...
If you try this:
select xmlelement("tmp",0.1) from dual
you're going to receive the same result...
So, in order to achieve your gol just format the number via to_char function:
select xmlelement("tmp",to_char(0.1,'FM0.00')) from dual
Bye
Nicola

Keep getting an error and do not understand why

sales_heads will compile with no errors but when I try to compile sales_lines it comes up with 2 errors which are:
Error(3,1): PL/SQL: SQL Statement ignored
Error(3,111): PL/SQL: ORA-02289: sequence does not exist
could someone tell me where I am going wrong.
drop sequence nsale_seq;
CREATE SEQUENCE nsale_seq
START WITH 1000000000
INCREMENT BY 1
NOCACHE
NOCYCLE;
create or replace PROCEDURE sale_heads (staffID_new number, customerID_new number)
is begin
insert into SALE_HEAD (sale_num, sale_date, status, staff_id, customer_id) values (nsale_seq.NEXTVAL, sysdate, 'P', staffID_new, customerID_new);
end sale_heads;
/
create or replace PROCEDURE sales_lines (productCode_new number, quantity_new number, actualPrice_new number) is
begin
insert into SALE_LINE (actual_price, quantity, sale_num, product_code) values (actualPrice_new, quantity_new, nsale_seg.CURRVAL, productCode_new);
end sales_lines;
/
You have placed / this after your first procedure as well as after second procedure. / is used to show the end of the file or the statements to be executed!Hence, it's unable to find second procedure!!!
That's why your second procedure is getting ignored.
Please remove the / first slash after first procedure sale_heads.
I believe it'll work perfectly!

Define Procedures inside Packages

I have created some Procedures in SQL Developer, and they are working fine. However I am now creating a Package to include all those Procedures, and can't seem to figure out the right way to code the Package as it returns the following error (refering to the PACKAGE BODY's CREATE):
PLS-00103: Encountered the symbol "CREATE"
Here is my code:
CREATE OR REPLACE PACKAGE package_test AS
PROCEDURE copy_object;
END package_test;
CREATE OR REPLACE PACKAGE BODY package_test AS
PROCEDURE copy_object IS
CURSOR object_cursor IS
SELECT COD_OBJECT, OBJECT_NAME FROM OBJECT;
object_rec object_cursor%rowtype;
BEGIN
EXECUTE IMMEDIATE 'TRUNCATE TABLE DATABASE2.D_OBJECT';
FOR object_rec IN object_cursor
LOOP
INSERT INTO DATABASE2.D_OBJECT (COD_OBJECT,OBJECT_NAME) VALUES (object_rec.OOD_OBJECT,object_rec.OBJECT_NAME);
END LOOP;
COMMIT;
END copy_object;
END package_test;
I have done some searching and the only thing I can think of is maybe some problem related to the definition on the CURSOR...not sure though. Thanks in advance
I successfully ran this in sqlplus and sqldeveloper (F5 in sqldeveloper: "Run Script"). I changed the two dml statements since my schema is different.
SQL> CREATE OR REPLACE PACKAGE package_test AS
2
3 PROCEDURE copy_object;
4
5 END package_test;
6 /
Package created.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY package_test AS
2
3 PROCEDURE copy_object IS
4 CURSOR object_cursor IS
5 SELECT * from dual;
6
7 object_rec object_cursor%rowtype;
8
9 BEGIN
10 EXECUTE IMMEDIATE 'TRUNCATE TABLE DATABASE2.D_OBJECT';
11 FOR object_rec IN object_cursor
12 LOOP
13 NULL; --INSER INTO DATABASE2.D_OBJECT (COD_OBJECT,OBJECT_NAME) VALUES (object_rec.OOD_OBJECT,object_rec.OBJECT_
NAME);
14 END LOOP;
15 COMMIT;
16 END copy_object;
17 END package_test;
18 /
Package body created.
SQL>

Resources