Error when creating a stored procedure in MariaDB - sql

I am trying to create a stored procedure in MariaDB, and I keep getting the error
#1064 - 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 'END' at line 9
DELIMITER $$
Create procedure patientcheck(IN hospitalcode int(11))
BEGIN
Select Staff1.First_name, Staff1.Surname, Staff1.Dep1
From Patient1, Staff1, Staff_allocator
Where Patient1.PatientID1=Staff_allocator.PatientID1 and Staff1.StaffID1=Staff_allocator.StaffID1
And Patient1.PatientID1=hospitalcode
END $$
DELIMITER ;
any help will be appreciated thanks

im not sure how or why my issue was solved, but after rewriting my code character by character, even without changing anything ( and re adding the ";"), the code finally ran. (ive been told that phpmyadmin is very buggy and unstable and is prone to silly issues like this)

You are missing a semicolon at the end of your select statement. You changed the delimiter to $$, but you still need to add the semicolon to the end of the query. I ran this exact code on a MariaDB instance with the semicolon added and it ran without error.

Related

Oracle dynamic sql, works everywhere but at customers

I have a stored procedure which executes some dynamic sql, shown below. I've tried to cut it down as much as possible so ignore any little errors.
In the office it works, everytime, on 11.2, 10.2, 10.1. At the customers it fails with a message:
Unexpected Error
Error Message = "Msg:
MyProc
ORA-06550: line 1, column 1:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for function goto if loop mod null
If I capture the dynamic sql that the customer is generating and place it in a variable like below, running on work machines, it works, so it's not that dodgy sql is getting generated. Normally the sql comes from the client so here I've doubled the to_date quotes.
mySQL := '
declare
pADMINDATE DATE := :1;
pEMPLOYEEIDLIKE VARCHAR2(40) := :2;
pINCLUDEEMPLOYEE number := :3;
begin
BEGIN OTHERPROC.OTHERPROC (1,TO_DATE(''2012-10-03'', ''YYYY-MM-DD''),TO_DATE(''2012-10-03'', ''YYYY-MM-DD''),0);
END;
INSERT INTO TP_EMPLOYEES (
ID,
EMPLOYEECODE
)
SELECT ROWNUM,
EMPLOYEECODE
FROM (
SELECT EMPLOYEECODE
FROM (SELECT DISTINCT EMPLOYEECODE FROM TP_EEF_TEMP) DISTINCTEMPCODES) A;
end; ';
EXECUTE IMMEDIATE
mySQL
using
pADMINDATE,
pEMPLOYEEIDLIKE,
pINCLUDEEMPLOYEE;
It's not the database version that causes the problem, could it be permissions? It calls another stored procedure within itself which we do regularly in non dynamic sql, could it be that?
At a loss here
Thanks
I have found the "works in this server but doesn't work on that server" type of problems before.
Usually it's related to implicit date <-> varchar conversions: since different database servers can have different default formats, it's possible for a statement with an implicit conversion to work in one place and fail in another.
I suggest you to try running your example removing the pADMINDATE date variable.
It was carriage returns! Adding this line fixed the problem
pQUERY2 := REPLACE(pQUERY, chr(13));
A similar problem was highlighted here
https://forums.oracle.com/forums/thread.jspa?threadID=1117462
Thanks for the answers anyway, if anyone knows I would be interested in knowing what setting/patch/whatever makes Oracle sensitive to this, i.e. I tried this on 3 different versions of oracle including the one the customer was on, -but- I didn't patch my 10.2.1 version.
Is it something that is fixed in a patch? Is it a setting?

SQL Compound Statement - Declare a variable

I'm trying to write a small SQL in mySQL but I get an error code whenever I try and run it. I'm using the following guide to help with this coding, but I'm not sure if mySQL and this are compatible (pg 287):
http://download.oracle.com/otn_hosted_doc/rdb/pdf/gsp.pdf
BEGIN
DECLARE :mgrid CHAR(5) DEFAULT;
END;
The error code that mySQL gives me when I try and run this is: Error Code: 1064: "You have an error in your SQL syntax; check that manual that corresponds to your MySQL syntax..."
Any thougts would be much appreciated!
Cheers
EDIT: Further - I can't even run the BEGIN - END; part, with no code in the middle...
Dude, you're using an Oracle manual to code up some MySql sql?
That's like using your Ford manual to work on your Prius.
Try the MySql manuals!
Here's the bit about DECLARE

Oracle 10gR2 trigger error

I have Oracle 10gR2. I am trying to create autoincrement trigger.
Here is the sample:
CREATE SEQUENCE TEST_SEQ
INCREMENT BY 1
START WITH 1
NOMAXVALUE
/
CREATE TABLE TESTER (
ID_TESTER INTEGER NOT NULL,
VAL VARCHAR2(20) NOT NULL
)
/
CREATE OR REPLACE TRIGGER TIB_TESTER BEFORE INSERT
ON TESTER FOR EACH ROW
BEGIN
SELECT TEST_SEQ.NEXTVAL
INTO :NEW.ID_TESTER
FROM DUAL;
END;
/
Trigger creation gives warning:
warning : ORA-24344: success with
compilation error
And when I get error value:
select OCI_SUCCESS_WITH_INFO;
/
It gives error:
error : ORA-00923: FROM keyword not
found where expected
What client are you using to issue these commands? ORA-24344 is a perculiar error.
In SQL*PLus we can get more information about compilation errors like this:
SQL> show errors
As for the ORA-00923 error, that is because in Oracle's version of SQL we always have to select from a table. So you should execute
select OCI_SUCCESS_WITH_INFO
from dual
/
I'm not sure how much sense that makes, but at least you won't get the error.
"It was Navicat problem"
That doesn't surprise me, as I ran your code against my database and it built without a hitch.
Maybe it will be useful for somebody:
If you are using Oracle 10g and OCI driver, ORA-24344 shows when trigger have carriage return sign (\r) in code eg. file was created with Windows end of line style.

ORA:00900 Invalid sql statement

i created a procedure with 32 in argument,it sucessfully created.but when i am executing this in back end oracle the errror came ORA:00900 Invalid sql statement
Use:
SQL> alter procedure [your procedure name here] compile;
SQL> show errors
...to be able to diagnose the issue from the resulting error output.
Also look at view USER_ERRORS.
Sometimes, show errors does not show anything when in fact there are errors. Especially after alter compile.
Finally, re-compile in TOAD or SQL Developer and you can easily navigate to the error.
In Oracle SQL Developer you should execute it this way:
BEGIN
YOUR_PROCEDURE(PARAM1, PARAM2);
END;
If you use EXECUTE or EXEC (which work in SqlPlus) you get the ORA-00900 error.

MySQL DELIMITER syntax errors

This MySQL script installs multiple triggers.
It works on one machine running MySQL 5.0.51b-community. On another machine running MySQL 14.12 Distrib 5.0.45, for redhat-linux-gnu (i386) it fails, with this error message, which seems to be related to the DELIMITER // ... // DELIMITER; syntax :
ERROR 1064 (42000) at line 272: 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 'DELIMITER; DROP TRIGGER IF EXISTS trigger_name; DELIMITER' at line 1
The script syntax (summarised) is:
DROP TRIGGER IF EXISTS trigger_name;
DELIMITER //
CREATE TRIGGER trigger_name BEFORE UPDATE ON table
FOR EACH ROW BEGIN
-- Trigger logic goes here
END //
DELIMITER;
-- More trigger drop/create statements follow
What is wrong with the script, and how can I correct it?
Try
DELIMITER ;
not
DELIMITER;
You're actually specifying ; as an argument to the DELIMITER command, so not having the space there may be confusing it.
You need a space between 'DELIMITER' and ';'
DELIMITER ;
# not:
DELIMITER;
Just as an add-on, for someone else:
The delimiter is required to enable the entire definition to be passed to the server as a single statement.
Try the below.
I am sure it should solve the purpose.
DELIMITER +
CREATE TRIGGER STUDENT_INSERT_TRIGGER BEFORE INSERT ON FSL_CONNECTIONS
FOR EACH ROW BEGIN
INSERT INTO STUDENT_AUDIT
SET STUDENT_ID = NEW.STUDENT_ID,
MAC_ADDRESS = NEW.MAC_ADDRESS,
IPADDRESS = NEW.IPADDRESS,
EMAIL_ID = NEW.EMAIL_ID ,
START_TIME=NEW.START_TIME,
END_TIME=NEW.END_TIME,
STATUS=NEW.STATUS;
END; +
From the above when we use a DELIMITER. It should be in the form of
DELIMITER +
--
BLOCK OF SQL WHATEVER YOU WANT TO MENTION
--
+
In the version of MySql I use the same error occurs when using the delimiter command, but this version handles the delimiter ";" for statements and delimiter "|" for stored procedures and functions, which i think solves the problem; try this:
DROP TRIGGER IF EXISTS trigger_name;
CREATE TRIGGER trigger_name BEFORE UPDATE ON table
FOR EACH ROW BEGIN
-- Trigger logic goes here
END |
-- other statements or functions here
Hmm I'm having similar problems. I do a mysqldump from Debian Lenny running 5.0.51 and try importing to OpenSolaris running 5.0 and get the same error. And I have DELIMITER ;
Version conflict?