ERROR: The symbol "(" was substituted for "VARCHAR2" to continue - plsql

I am trying to compile this package body:
CREATE OR REPLACE PACKAGE BODY package_1 AS
PROCEDURE procedure_1 (P_HOST IN VARCHAR2, P_USER IN VARCHAR2, P_NAME IN VARCHAR2)
IS
BEGIN
SELECT HOSTNAME, USERS, PS_NAME
INTO P_HOST, P_USER, P_NAME
FROM PS_COLLECT
WHERE NOT EXISTS
(
SELECT HOSTNAME, USERS, PS_NAME
FROM PS_MASTER
WHERE PS_MASTER.HOSTNAME = PS_COLLECT.HOSTNAME
AND PS_MASTER.USERS = PS_COLLECT.USERS
AND PS_MASTER.PS_NAME = PS_COLLECT.PS_NAME
);
END procedure_1;
END package_1;
But I am getting this error
The symbol "(" was substituted for "VARCHAR2" to continue.
I am a newbie int PL/SQL..please help :)

I wouldn't expect this to cause the exact error you're seeing, but one definite problem with your code is that you are specifying IN mode for the parameters, but then trying to assign values to them inside the procedure. It looks like you should change the mode to OUT for all three parameters (in both the header and the body).
If that alone does not resolve your issue, I suggest posting the modified text of both the CREATE PACKAGE and CREATE PACKAGE BODY statements.

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

ORA-00900: invalid SQL statement when using loop to insert rows

I'm trying to insert multiple rows into an Oracle 11g table by running the following in Aqua Data Studio (version 15.0.11), using this:
BEGIN
FOR i IN 1..700 LOOP
INSERT INTO lims.stock_template (
stock_template_id,
name,
group_id,
version,
version_status,
workflow_id,
amount,
stock_type_id,
aliquot_template_id,
auto_authorise,
reorder_amount
)
VALUES (
lims.sq_stock_template.nextval,
lims.sq_stock_template.currval,
21,
1,
'A',
51881,
0,
103,
2362,
'F',
0
);
END LOOP;
END;
/
but I get the following error:
>[Error] Script lines: 30-30 ------------------------
ORA-00900: invalid SQL statement
Script line 30, statement line 1, column 0
If I run just the INSERT statement by itself, it works just fine, but I want to be able to insert multiple rows in one operation.
I'm sure that I've run something similar in the past, but I can't see what the problem is.
Any help much appreciated.
Thanks
In your example, you included a BEGIN and END clause, which turns this into a "Anonymous PL/SQL Block"
http://docstore.mik.ua/orelly/oracle/prog2/ch15_03.htm
Within a PL/SQL block you can't execute a SQL statement directly. You have to use only PL/SQL. See attached example.
Now you can create a stored procedure to execute your insert and use Script Object to Window As -> Execute or Execute Bind. See below screenshot.
In a stored procedure or a stored procedure within a package you can do whatever you like!
create or replace procedure testMe as
begin
FOR i IN 1..700 LOOP
INSERT INTO lims.stock_template (
stock_template_id,
name,
group_id,
version,
version_status,
workflow_id,
amount,
stock_type_id,
aliquot_template_id,
auto_authorise,
reorder_amount
)
VALUES (
lims.sq_stock_template.nextval,
lims.sq_stock_template.currval,
21,
1,
'A',
51881,
0,
103,
2362,
'F',
0
);
END LOOP;
end;
This is EXACTLY analogous to typing every line in at the SQL prompt form the word begin to the word end;.
What is more then likely tripping you up is the slash at the bottom. In the CLI sqlPlus the end of the line with the semicolon ( ; ) causes it to run the process, hence :
select 'A' from dual;
The semicolon tells it to execute.
IF on the other hand you type in the word begin then it shifts mode and will accept semicolons anywhere and just keep adding your strings to the buffer. ON A BLANK LINE the type the / and return and it will try and execute your code.
I think if you remove the slash it will execute quite nicely.

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!

cant compile plsql package in sqldeveloper 4.0

I have to use sqldeveloper 4.0. But i cant compile single package in it. It compiles in other programs, but i have to use sqldeveloper. I tryed to compile oracle tutorial package:
CREATE OR REPLACE PACKAGE emp_actions AS -- spec
TYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);
CURSOR desc_salary RETURN EmpRecTyp;
PROCEDURE hire_employee (
ename VARCHAR2,
job VARCHAR2,
mgr NUMBER,
sal NUMBER,
comm NUMBER,
deptno NUMBER);
PROCEDURE fire_employee (emp_id NUMBER);
END emp_actions;
CREATE OR REPLACE PACKAGE BODY emp_actions AS -- body
CURSOR desc_salary RETURN EmpRecTyp IS
SELECT empno, sal FROM emp ORDER BY sal DESC;
PROCEDURE hire_employee (
ename VARCHAR2,
job VARCHAR2,
mgr NUMBER,
sal NUMBER,
comm NUMBER,
deptno NUMBER) IS
BEGIN
INSERT INTO emp VALUES (empno_seq.NEXTVAL, ename, job,
mgr, SYSDATE, sal, comm, deptno);
END hire_employee;
PROCEDURE fire_employee (emp_id NUMBER) IS
BEGIN
DELETE FROM emp WHERE empno = emp_id;
END fire_employee;
END emp_actions;
And i get Error(14,1): PLS-00103: Encountered the symbol "CREATE" - on create package body line
I tryed to put "/" in front of it but i get Error(13,1): PLS-00103: Encountered the symbol "/".
I dont know the version of the database.
Thank you for help
If you want to run both statements together then you need to put a / after each of them, by itself on a new line:
CREATE OR REPLACE PACKAGE emp_actions AS -- spec
...
END emp_actions;
/
CREATE OR REPLACE PACKAGE BODY emp_actions AS -- body
...
END emp_actions;
/
... and then do 'Run Script' (F5, or the button with an icon of a green arrow over a document), rather than 'Run Statement' (Ctrl-Enter, or the button with just a green arrow). The output will go in the 'Script Output' pane.
You can't run multiple statements with 'Run Statement', although you can still select the text of one statement from a script and run that on its own - if it's a query then the output will still appear in the 'Query Result' pane.
If you've created a new package from the 'File->New' menu item, or by right-clicking the 'Package' header in the object browser and selecting 'New Package', then you can only enter the specification in the window that's displayed (the tab has the package name and an icon of a wrapped present). That does actually make more sense - I thought the line number on your second error was wrong, but that matches working in this window.
So enter just the package specification in that window and compile. Then back in the object browser, refresh the package list, right-click your new package name and select 'Create Body'. You'll get a second tab which looks very similar but the tab name will say ' body'. You can put the package body in there and compile it.
Using these views you always have the specification and body in separate tabs. Once both exist each has a button to open the other - the specification window has a button to open the body, and vice versa.

Resources