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.
Related
I am trying to write a stored procedure in mysql using Heidisql. I keep getting the error. Below is the screen shot:
below is the script of the stored procedure.
CREATE PROCEDURE index_insertPersonadata
(
IN p_firstName VARCHAR(50),
IN p_middleName VARCHAR(50),
IN p_lastName VARCHAR(50),
IN p_address VARCHAR(200),
IN p_City VARCHAR(50),
IN p_State VARCHAR(50),
IN p_ZIP VARCHAR(50)
)
BEGIN
INSERT INTO personalrecord(
FirstName,
MiddleName,
LastName,
Address,
City,
state,
ZIP
)
VALUES
(
p_firstName,
p_middleName,
p_lastName,
p_address,
p_City,
p_State,
p_ZIP
);
END;
any help will be highly appreciated.
As far as your question is concerned, you are just missing a delimiter command:
DELIMITER //
CREATE PROCEDURE index_insertPersonadata (
IN p_firstName VARCHAR(50),
IN p_middleName VARCHAR(50),
IN p_lastName VARCHAR(50),
IN p_address VARCHAR(200),
IN p_City VARCHAR(50),
IN p_State VARCHAR(50),
IN p_ZIP VARCHAR(50)
)
BEGIN
INSERT INTO personalrecord(FirstName, MiddleName, LastName, Address, City, state, ZIP)
VALUES(p_firstName, p_middleName, p_lastName, p_address, p_City, p_State, p_ZIP);
END;
//
DELIMITER ;
Why you need this is explained in the documentation:
If you use the mysql client program to define a stored program containing semicolon characters, a problem arises. By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.
To redefine the mysql delimiter, use the delimiter command.
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 ;
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.
I am creating a small (for now) stored procedure to insert some data. When I create this I get an error.
DROP PROCEDURE IF EXISTS InsertTESTData;
delimiter $$
CREATE PROCEDURE InsertTESTData (
p_pink_no VARCHAR,
p_carrier VARCHAR,
p_thisno INT
)
BEGIN
INSERT INTO RefDB (pink_no,carrier,thisno)
VALUES
(p_pink_no,p_carrier,p_thisno);
END $$
delimiter ;
And the error I always get is a 1064 SQL error as follows.
Error : 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 'p_carrier VARCHAR,p_thisno IN) BEGIN INSERT INTO RefDB (pink_no,carrier,t' at line 2
I thought I had everything covered and am now pulling my hair out!
You need to define a length for your varchar parameters like this
p_pink_no VARCHAR(100)
and change
p_thisno IN
to
p_thisno INT
Complete example:
DROP PROCEDURE IF EXISTS InsertTESTData;
delimiter $$
CREATE PROCEDURE InsertTESTData (
p_pink_no VARCHAR(100),
p_carrier VARCHAR(100),
p_thisno INT)
BEGIN
INSERT INTO RefDB (pink_no,carrier,thisno)
VALUES (p_pink_no,p_carrier,p_thisno);
END $$
delimiter ;
you have to declare the size of the data type ,after thal i am sure your code will be execute successfully.
follow this
DROP PROCEDURE IF EXISTS InsertTESTData;
delimiter $$
CREATE PROCEDURE InsertTESTData (
p_pink_no VARCHAR(20),
p_carrier VARCHAR(200),
p_thisno number(23))
BEGIN
INSERT INTO RefDB (pink_no,carrier,thisno)
VALUES (p_pink_no,p_carrier,p_thisno);
END $$
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();