By Creating this Strored Procedure i am getting error dont know how to fix it
Here is my sql
DROP PROCEDURE IF EXISTS Sp_Reservation;
DELIMITER $$
CREATE PROCEDURE Sp_Reservation
(
IN name VARCHAR(150),
IN email VARCHAR(100),
IN mobile VARCHAR(15),
IN cninc VARCHAR(15),
IN cityID INT(10),
IN checkin Date,
IN checkout Date,
IN noOfRooms INT(5),
IN RoomID INT(10),
IN RoomCategoryID INT(10),
IN noOfChilds INT(5),
IN noOfAdults INT(5),
IN message VARCHAR(500),
IN reservationStatus vARCHAR(10)
)
BEGIN
DECLARE CusID INT DEFAULT 1;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
END;
START TRANSACTION;
BEGIN
SET CusID =(
SELECT
IF(Max(customers.CustomerID) IS NULL,CUstID,customers.CustomerID) as
CutomID FROM customers);
INSERT INTO `customers` (customers.CustomerName,
customers.CustomerNID,
customers.CustomerEmail,
customers.CutomerMobile,
customers.CityID)
VALUES(name,
cnic,
email,
Mobile,
CityID);
INSERT INTO `roomreservation`(roomreservation.CustomerID,
roomreservation.RoomID,
roomreservation.CheckIn,
roomreservation.CheckOut,
roomreservation.NoOfAdults,
roomreservation.NoOfChildrens,
roomreservation.Message,
roomreservation.ReservationStatus)
SELECT 1,RoomID,checkin,checkout,noOfAdults,noOfChilds,message,reservationStatus
FROM rooms WHERE RoomID NOT IN
(
SELECT RoomID FROM roomreservation WHERE ReservationStatus = 'Reserved'
AnD roomreservation.CheckIn BETWEEN checkIn AND checkout
) ;
-- LIMIT (noOfRooms);
COMMIT;
END;
END$$
DELIMITER ;
ERROR:
SQL query:
DELIMITER ;
MySQL said:
1064 - 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' at line 1.
Note: I am using Phpmyadmin
Well, I don't see any issue with your procedure code except that you can try changing the statement END$$ to END $$. If still doesn't work then there is problem with your Phpmyadmin client and somehow it's not happy with the statement DELIMITER $$. Try using a different client (or) a different version of current client.
Related
I'm working on this procedure but I'm not too familiar with writing a stored procedure in MySQL, when I try to create the stored procedure as shown here, it keeps telling me that a syntax is incorrect at line 9
DELIMITER//
CREATE PROCEDURE InsertUser (
IN new_USER_ID BIGINT,
IN new_USER_NAME VARCHAR(36),
IN new_ENCRYTED_PASSWORD VARCHAR(128),
IN new_ENABLED BIT,
IN select_Role_ID BIGINT)
BEGIN
DECLARE user_role_id BIGINT
SET user_role_id = (SELECT max(id) from USER_ROLE);
Insert into App_User(USER_ID, USER_NAME, ENCRYTED_PASSWORD, ENABLED)
values(new_USER_ID, new_USER_NAME, new_ENCRYTED_PASSWORD, new_ENABLED);
INSERT INTO USER_ROLE(ID, USER_ID, ROLE_ID)
values(user_role_id+1, new_USER_ID, select_Role_ID);
END;//
DELIMITER;
Can someone show me how the correct syntax should be?
Here's the correct way of using delimiter. See mysql documentation
DELIMITER //
CREATE PROCEDURE InsertUser (
IN new_USER_ID BIGINT,
IN new_USER_NAME VARCHAR(36),
IN new_ENCRYTED_PASSWORD VARCHAR(128),
IN new_ENABLED BIT,
IN select_Role_ID BIGINT)
BEGIN
Insert into App_User(USER_ID, USER_NAME, ENCRYTED_PASSWORD, ENABLED)
values(new_USER_ID, new_USER_NAME, new_ENCRYTED_PASSWORD, new_ENABLED);
INSERT INTO USER_ROLE(ID, USER_ID, ROLE_ID)
values(user_role_id+1, new_USER_ID, select_Role_ID);
END //
DELIMITER ;
I have the following procedure that when I manually import this is breaking for some unknown reason.
CREATE PROCEDURE `register_house`(
IN UID CHAR(17),
IN new_username VARCHAR(16),
IN new_signature CHAR(64),
IN email VARCHAR(128),
IN postcode VARCHAR(16),
IN customer_name VARCHAR(45),
IN phone_number VARCHAR(16)
)
BEGIN
UPDATE bb.checkin SET username = new_username, signature = new_signature WHERE _site = UID;
END
I'm getting the following error in Mysql Workbench -
Error Code: 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 '' at line 11
Can someone suggest what the problem is?
UPDATE
As suggested i've amended to include the DELIMITER and now get the following error:
Error Code: 1728. Cannot load from mysql.proc. The table is probably corrupted
The tables all appear to look correct is the way to 'de-corrupt' them if they have corrupted somehow?
Based on https://stackoverflow.com/a/639356/2381157, try this
delimiter //
CREATE PROCEDURE `register_house2`(
IN UID CHAR(17),
IN new_username VARCHAR(16),
IN new_signature CHAR(64),
IN email VARCHAR(128),
IN postcode VARCHAR(16),
IN customer_name VARCHAR(45),
IN phone_number VARCHAR(16)
)
BEGIN
UPDATE bb.checkin SET username = new_username, signature = new_signature WHERE _site = UID;
END
//
delimiter ;
It worked for me in MySQL 5.5
This worked for me...
Added this to the start of the statement on line 1;
DELIMITER $$
then on the ver
END $$
Then finally to fix the 'corrupted' message I simply ran the following file:
C:\xampp\mysql\bin\mysql_upgrade.exe
I have the following SQL code:
EXECUTE userAanmaken
#domeinNummer=1,
#gebruikerNaam='Jansen',
#gebruikerPass='Jaap',
#gebruikerEmail='jan#piet.nl',
#gebruikerVN='Joop',
#gebruikerTV='van',
#gebruikerAN='Heha',
#gebruikerGS='M',
#gebruikerOL='Hoog',
#gebruikerGD=2011-11-11
This code affects the following procedure:
CREATE PROCEDURE userAanmaken
(
IN domeinNummer INT(11),
IN gebruikerNaam VARCHAR(45),
IN gebruikerPass VARCHAR(45),
IN gebruikerEmail VARCHAR(45),
IN gebruikerVN VARCHAR(50),
IN gebruikerTV VARCHAR(10),
IN gebruikerAN VARCHAR(50),
IN gebruikerGS VARCHAR(1),
IN gebruikerOL VARCHAR(30),
IN gebruikerGD DATE
)
BEGIN
DECLARE lastID INT;
INSERT INTO Gebruiker(Domein_idDomeint)
VALUES (domeinNummer);
SET lastId=LAST_INSERT_ID();
INSERT INTO Inlog (Gebruiker_idGebruiker,UserName,UserPass)
VALUES (lastId,gebruikerNaam,gebruikerPass);
INSERT INTO GGevens (Gebruiker_idGebruiker,Email,Voornaam,Tussenvoeg,Achternaam,Geslacht,Opleiding,GebDatum)
VALUES (lastId,gebruikerEmail,gebruikerVN,gebruikerTV,gebruikerAN,gebruikerGS,gebruikerOL,gebruikerGD);
END$$
When i run the execute statement it returns with a syntax error.
How do i define the parameters in the SQL execute statement?
Seems that you missing date quotation marks '' on DATE:
#gebruikerGD='2011-11-11'
Maybe you need to use DELIMITER // in beggining of procedure and DELIMITER; in end of procedure. Check documentation.
I am new to MySQL. I have two tables posts and notification. I am trying to create a trigger for every new row added in posts, I would to add that new row to notification_id.
its working properly on mysql but in phpmyadmin trigger won't execute , it gives an error
1064 - 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 11
Here how my tables look like:
posts table
create table posts
(
id int,
topic_id tinyint,
post_creator int,
post_date datetime,
post_content text
);
notification table
create table notification
(
not_id int ,
top_id tinyint,
p_creator int,
p_date datetime,
p_content text
);
notification_id trigger
delimiter $$;
create trigger notification_id before Insert on posts
for each row
begin
declare id int;
declare topic_id int;
declare post_creator int;
declare post_date datetime;
declare post_content text;
insert into notification(not_id,top_id,p_creator,p_date,p_content) values(new.id,new.topic_id,new.post_creator,new.post_date,new.post_content);
end$$;
create the tables first normally
Change the default delimiter in phpmyadmin interface [it is just under the textbox where you enter your query]
Run the create trigger script separately, without the lines of changing delimiter
So, your trigger's code should not have delimiter $$;
i have this table
create table eveniment( +
evenimentId bigint not null auto_increment primary key,
evenimentDenumire varchar(500),
adresaId int not null);
create table adresa(
adresaId bigint not null auto_increment primary key,
localitate varchar(500),
judet varchar(500),
codPostal varchar(50),
strada varchar(500),
nr varchar(50),
bl varchar(50),
ap varchar(5),
email varchar(500),
www varchar(500));
and this procedure
DELIMITER //
drop procedure IF EXISTS insertEveniment;
CREATE PROCEDURE insertEveniment()
BEGIN
DECLARE vAdresaEvenimentId int DEFAULT 0
insert into adresa(judet,localitate,codPostal,strada,nr,bl,ap,email,www)
values('judet','localitate','cod postal','strada','numar','bloc','ap','email','www');
select last_insert_id() into vAdresaEvenimentId;
DECLARE vEvenimentId int DEFAULT 0
insert into eveniment(evenimentDenumire,adresaId) values('concurs informatic 1',vAdresaEvenimentId);
select last_insert_id() into vEvenimentId;
END //
DELIMITER ;
call insertEveniment();
and i get this error
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 'insert into adresa(judet,localitate,codPostal,strada,nr,bl,ap,email,www) values(' at line 4
if i try the insert into adresa ... separately in mysql command i don't get error , what i do wrong?
Try like this (tried and it works for me):
drop procedure IF EXISTS insertEveniment;
DELIMITER //
CREATE PROCEDURE insertEveniment()
BEGIN
DECLARE vAdresaEvenimentId int DEFAULT 0;
DECLARE vEvenimentId int DEFAULT 0;
insert into adresa(judet,localitate,codPostal,strada,nr,bl,ap,email,www)
values('judet','localitate','cod postal','strada','numar','bloc','ap','email','www');
select last_insert_id() into vAdresaEvenimentId;
insert into eveniment(evenimentDenumire,adresaId) values('concurs informatic 1',vAdresaEvenimentId);
select last_insert_id() into vEvenimentId;
END //
DELIMITER ;
call insertEveniment();
You are using drop procedure statement with wrong delimiter (you were setting delimiter to // but then you put ; at the end of your statement. Put your drop procedure statement before you set the delimiter, and it will work just fine. Also, put delimiters after DECLARE
DECLARE is a separate statement, thus it needs to be delimited with a ;, like INSERT or SELECT or any other statement.
Also, move the first DELIMITER statement to just before the beginning of the procedure declaration.
So,
DELIMITER //
drop procedure IF EXISTS insertEveniment;
DELIMITER //
CREATE PROCEDURE insertEveniment()
BEGIN
DECLARE vAdresaEvenimentId int DEFAULT 0 ;
insert into adresa(judet,localitate,codPostal,strada,nr,bl,ap,email,www)
values('judet','localitate','cod postal','strada','numar','bloc','ap','email','www');
select last_insert_id() into vAdresaEvenimentId;
DECLARE vEvenimentId int DEFAULT 0 ;
insert into eveniment(evenimentDenumire,adresaId) values('concurs informatic 1',vAdresaEvenimentId);
select last_insert_id() into vEvenimentId;
END //
DELIMITER ;
call insertEveniment();