SQL Compound Statement - Declare a variable - sql

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

Related

Error when creating a stored procedure in MariaDB

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.

Incorrect Syntax near the keyword 'OR' in CREATE OR ALTER PROCEDURE

I have a master script that runs and create all stored procedures, but when I run the script I error out at the only two places that use the syntax CREATE OR ALTER PROCEDURE
The code is below:
CREATE OR ALTER PROCEDURE [dbo].[P_ReinitializeStorePlans]
#storeId INT
AS
BEGIN
RETURN;
END
GO
And the error is as follows, I have another CREATE OR ALTER PROCEDURE later at line 2713 as well with the same error.
I have checked my ##VERSION which returns SQL 2016 as well as 130 for the compatibility version. Any idea why this is giving me an error? I am assuming its a compatibility setting or flag for the syntax?
I believe this one comes with SP1 installed, this has a version of
13.0.4001.0 KB3182545
https://support.microsoft.com/en-us/help/3177312/sql-server-2016-build-versions
I suggest you go straight to SP2 you can get it from here https://go.microsoft.com/fwlink/?linkid=869608

Table-valued type as parameter

I'm trying to create the following stored proc with table-valued type as one of the parameter. However, I'm getting error as
Incorrect syntax near 'READONLY'.
I've checked many stackoverflow responses which mentions that the reasons could be sql server version. This is what my ##version tells me and looks fine to me
Microsoft SQL Server 2014 (RTM-CU14) (KB3158271)
Create PROCEDURE [dbo].[Customer_Select](
#variableTable dbo.CustomVariableType READONLY,
#return BIT = NULL OUTPUT)
AS
BEGIN
SELECT * FROM Customer
SET #return=1
END
Appreciate your help in this regard
It started to work after I restarted SSMS. Weird!!

Stored procedure weird error in oracle

I am new to the stored procedure in oracle and my simple code wont compile in oracle toad.
Here is my code:
code
There is a readline under the ALTER, and it says "Found: "ALTER", expecting select or (: BEGIN BASE COSE...) " why is that?
Oracle doesn't allow you to use DDL natively in PL/SQL. To work around this, you can use EXECUTE IMMEDIATE to run the DDL as a dynamic query.

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.