ERROR 1064 (42000): While Declaring a Cursor - mysql

I am Trying to create stored procedure in MYSQLand getting below error.
I googled about it but no solution found please help me in this.
DELIMITER //
CREATE OR REPLACE PROCEDURE P_PROCESS_USER_STG ( OUT O_error_msg VARCHAR(3000),
OUT O_status VARCHAR(300),
IN I_uploaded_by INT (10))
BEGIN
declare L_program_name VARCHAR(100);
declare L_login_id INT(10) ;
declare L_password VARCHAR(100);
declare L_first_name VARCHAR(100);
declare L_last_name VARCHAR(100);
declare L_privilege_group_id INT(10) ;
declare L_group_id INT(10) ;
declare L_message VARCHAR(100);
declare L_date_of_upload TIMESTAMP ;
declare L_date_of_update TIMESTAMP ;
declare L_uploaded_by INT(10) ;
declare L_status VARCHAR(10) ;
declare L_error_msg VARCHAR(100),
declare L_finished INT(1) DEFAULT 0;
declare C_user_stg CURSOR FOR
SELECT LOGIN_ID,
PASSWORD,
FIRST_NAME,
LAST_NAME,
PRIVILEGE_GROUP_ID,
GROUP_ID
FROM uploaded_user_stg
where UPLOADED_BY = I_uploaded_by
and status in ( 'NEW' , 'UPDATE' );
declare CONTINUE HANDLER
FOR NOT FOUND SET L_finished = 1;
OPEN C_user_stg;
get_user: LOOP
FETCH C_user_stg INTO L_login_id ,
L_password ,
L_first_name ,
L_last_name ,
L_privilege_group_id,
L_group_id ;
IF L_finished = 1 THEN
LEAVE get_user;
END IF;
-- build email list
CALL P_CREATE_USER ( L_message ,
L_status ,
L_login_id ,
L_password ,
L_first_name,
L_last_name ,
L_privilege_group_id,
L_group_id )
UPDATE uploaded_user_stg
SET status = L_status,
error_msg = L_message
date_of_update = now();
where login_id = L_login_id;
END LOOP get_email;
CLOSE get_user;
END//
DELIMITER ;
I am getting Below error :
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that on for the right syntax to use near '
declare L_finished INT(1) DEFAULT 0;
declare C_' at line 18

Change this from:
declare L_error_msg VARCHAR(100),
to
declare L_error_msg VARCHAR(100);

Related

What should I do with the unknown 'Col_name' column in field list in mysql trigger?

CREATE TABLE Bookinglog #########ROOMSTATE LOG TABLE
(
`Bookinglog_ID` INT NOT NULL AUTO_INCREMENT ,
`Booking_ID` INT NOT NULL ,
`time_stamp` DATETIME(6) NOT NULL ,
`Booking_CheckInDate` date NOT NULL ,
`Booking_CheckOutDate` date NOT NULL COMMENT ,
`Cust_ID` INT NOT NULL COMMENT ,
`booking_totalamount` INT NULL COMMENT,
`LOG` VARCHAR(1) NOT NULL,
CONSTRAINT PRIMARY KEY (Bookinglog_ID)
);
Mysql couldn't create a trigger for insert or delete, so I created one for each.
This is my trigger code :
select * from bookinglog;
drop table bookinglog;
drop trigger booking_trigger2;
############## Booking INSERT TRIGGER
delimiter $$
create trigger Booking_trigger
after insert on Booking
for each row
begin
declare booking_id int;
declare time_stamp timestamp;
declare booking_checkindate date;
declare booking_checkoutdate date;
declare cust_id int;
declare booking_totalamount int;
declare log varchar(1);
set booking_id = new.booking_id;
set time_stamp = current_timestamp();
set cust_id = new.cust_id;
set booking_checkindate = new.booking_checkindate;
set booking_checkoutdate = new.booking_checkoutdate;
set booking_totalamount = new.booking_totalamount;
set LOG = 'C';
insert into roomstatelog(booking_id,time_stamp,booking_checkindate,booking_checkoutdate,cust_id,booking_totalamount,log)
value (booking_id,time_stamp,booking_checkindate,booking_checkoutdate,cust_id,booking_totalamount,log);
end $$
delimiter ;
############## Booking DELETE TRIGGER
delimiter $$
create trigger Booking_trigger2
before delete on Booking
for each row
begin
declare booking_id int;
declare time_stamp timestamp;
declare booking_checkindate date;
declare booking_checkoutdate date;
declare cust_id int;
declare booking_totalamount int;
declare log varchar(1);
set booking_id = old.booking_id;
set time_stamp = current_timestamp();
set cust_id = old.cust_id;
set booking_checkindate = old.booking_checkindate;
set booking_checkoutdate = old.booking_checkoutdate;
set booking_totalamount = old.booking_totalamount;
set LOG = 'D';
insert into roomstatelog(booking_id,time_stamp,booking_checkindate,booking_checkoutdate,cust_id,booking_totalamount,log)
value (booking_id,time_stamp,booking_checkindate,booking_checkoutdate,cust_id,booking_totalamount,log);
end $$
delimiter ;
I want to log the data inserted or deleted from the reservation table in the bookinglog table.
When insert or delete is executed, these errors appear.
Error Code: 1054. Unknown column 'booking_checkindate' in 'field list'
I think there is a problem with the syntax in the trigger code
It was a really simple matter. I should write 'bookinglog' as the table name in insert into, but I wrote 'roomstate'.

How to make TWO loops in a UDF at mysql

similar to StackOverflowPosting I would like to calculate the Levenshtein Distance for a m x n matrix consisting of TITLE1 and TITLE2.
My Levenshtein Functions works fine and is from here: LD
But my Question is how can I loop through the m x n in a UDF?
The Result should be a table with m x n rows with LD, TITLE1 and TITLE2.
I have done this - BUT I ALWAYS GET AN ERROR
1338 Cursor Declaration after Handler Declaration
My UDF looks like this:
BEGIN
DECLARE bDone INT;
DECLARE bDone1 INT;
DECLARE var2 varCHAR(255); -- or approriate type
DECLARE Var1 INT;
DECLARE c1Var1 VARCHAR(250);
DECLARE curs CURSOR FOR SELECT recid as BIOTIrecid, replace(replace(BIOGRAPHYTITLE," [in SCOPUS]",""),"[SIMILAR]","") as bioti FROM BIO ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
DECLARE curs1 CURSOR FOR SELECT trim(concat(scopus.Titel," ",scopus.Untertitel)) as scopusti FROM scopus ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
DROP TABLE IF EXISTS LDResults;
CREATE TABLE `LDResults` (
`BIOGRAPHYTITLE` varchar(255) DEFAULT NULL,
`recid` int(11) NOT NULL AUTO_INCREMENT,
`BIOTIrecid` int(11) default NULL,
`LD` varchar(255) DEFAULT NULL,
`ScopusTI` varchar(255) DEFAULT NULL,
PRIMARY KEY (`recid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
OPEN curs1;
SET bDone1 = 0;
#---------------- run all rows for scopusti
REPEAT
FETCH curs1 into c1var1;
#-----------------------------------------
OPEN curs;
SET bDone = 0;
#----- run all COLUMNs for biographytitle
REPEAT
FETCH curs INTO var1, var2;
INSERT INTO LDResults (`BIOGRAPHYTITLE`, `BIOTIrecid`, `LD`, `ScopusTI`) VALUES (var2, var1, LEVENSHTEIN(var2,c1var1), c1var1);
UNTIL bDone END REPEAT;
#--------------------------------------------
CLOSE curs;
UNTIL bDone1 END REPEAT;
CLOSE curs1;
SELECT * FROM LDResults;
END
Is my way to solve this problem sophisticated or could this be done on a more faster and better solution ?
Thanks for all advices.
EDIT:
I could make it with a counter here: Any comments?
BEGIN
-- DECLARE bDone INT;
-- DECLARE bDone1 INT;
DECLARE i INT;
DECLARE var2 varCHAR(255); -- or approriate type
DECLARE Var1 INT;
DECLARE cVar1 VARCHAR(250);
DECLARE curs1 CURSOR FOR SELECT trim(concat(t.Titel," ",t.Untertitel)) as scopusti FROM tscopus t ;
DECLARE curs CURSOR FOR SELECT recid as BIOTIrecid, replace(replace(BIOGRAPHYTITLE," [in SCOPUS]",""),"[SIMILAR]","") as bioti FROM tBIO ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
#DECLARE curs1 CURSOR FOR SELECT trim(concat(t.Titel," ",t.Untertitel)) as scopusti FROM tscopus t ;
#DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
DROP TABLE IF EXISTS LDResults;
CREATE TABLE `LDResults` (
`BIOGRAPHYTITLE` varchar(255) DEFAULT NULL,
`recid` int(11) NOT NULL AUTO_INCREMENT,
`BIOTIrecid` int(11) default NULL,
`LD` varchar(255) DEFAULT NULL,
`ScopusTI` varchar(255) DEFAULT NULL,
PRIMARY KEY (`recid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
OPEN curs1;
SET i = 0;
SET bDone1 = 0;
-- ---------------- run all rows for scopusti
REPEAT
FETCH curs1 into cvar1;
set i=(i+1);
-- -----------------------------------------
OPEN curs;
SET bDone = 0;
-- ----- run all COLUMNs for biographytitle
REPEAT
FETCH curs INTO var1, var2;
INSERT INTO LDResults (`BIOGRAPHYTITLE`, `BIOTIrecid`, `LD`, `ScopusTI`) VALUES (var2, var1, LEVENSHTEIN(var2,cvar1), cvar1);
UNTIL bDone END REPEAT;
-- --------------------------------------------
CLOSE curs;
UNTIL (i >= 2) END REPEAT;
CLOSE curs1;
SELECT * FROM LDResults;
END
I mean you can do it by next way useng CROSS JOIN without loops in your code. CROSS JOIN by definition return product of two tables rows result.
So you can use this result and after some data manipulation insert the result into new table like:
DROP TABLE IF EXISTS LDResults;
CREATE TABLE `LDResults` (
`BIOGRAPHYTITLE` varchar(255) DEFAULT NULL,
`recid` int(11) NOT NULL AUTO_INCREMENT,
`BIOTIrecid` int(11) default NULL,
`LD` varchar(255) DEFAULT NULL,
`ScopusTI` varchar(255) DEFAULT NULL,
PRIMARY KEY (`recid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
INSERT INTO LDResults (`BIOGRAPHYTITLE`, `BIOTIrecid`, `LD`, `ScopusTI`)
SELECT bioti, BIOTIrecid, LEVENSHTEIN(bioti,scopusti), scopusti
FROM (
SELECT
replace(replace(BIO.BIOGRAPHYTITLE," [in SCOPUS]",""),"[SIMILAR]","") as bioti,
BIO.recid as BIOTIrecid,
trim(concat(scopus.Titel," ",scopus.Untertitel)) as scopusti
FROM scopus
CROSS JOIN BIO
) tbl;

Mysql 5.7 Issue in declare handler for duplicate key

We are facing an issue in declaring handlers in MYSQL 5.7 stored procedure.
Using the documentation present in https://dev.mysql.com/doc/refman/5.7/en/get-diagnostics.html, I'm trying to create handler in my stored procedure to do the following:
If a duplicate key appears, log it and move on insert good row.
End of the stored proc, get me all the error and success rows inserted.
As you can see below, we don't have primary key for table, however have the unique key constraint.
Input
CALL userTableInsert('{"userid":100, "username":"Hello"}, {"userid":102, "username":"World"}, {"userid":102, "username":"World"}', #got_dups)
Expected Output
100:Hello should get inserted and 102:World should get errored out and status needs to be corrected depicted in the output of the stored procedure.
Getting ERR : Error Code: 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 'DECLARE CONTINUE HANDLER FOR SQLEXCEPTION ...'
Table: user_table
CREATE TABLE `user_table` (
user_id int(20) NOT NULL,
user_name varchar(255) DEFAULT NULL,
created_by varchar(255) NOT NULL,
created_date date NOT NULL,
UNIQUE KEY `user_ukey` (user_id, user_name)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
===============================================
Stored Procedure
===============================================
DELIMITER $$
DROP PROCEDURE IF EXISTS schema.userTableInsert$$
CREATE PROCEDURE schema.userTableInsert(IN JSONArrayParam MEDIUMTEXT, OUT
got_dups INT)
SQL SECURITY INVOKER
BEGIN
DECLARE code CHAR(5) DEFAULT '00000';
DECLARE msg TEXT;
DECLARE rows INT;
DECLARE result TEXT;
DECLARE rowsJSON MEDIUMTEXT DEFAULT NULL;
SET rowsJSON = TRIM(JSONArrayParam);
SET rowsJSON = TRIM(LEADING '[' FROM rowsJSON);
SET rowsJSON = TRIM(TRAILING ']' FROM rowsJSON);
DROP TEMPORARY TABLE IF EXISTS rowsToUse;
CREATE TEMPORARY TABLE rowsToUse (
user_id INT NOT NULL,
user_name VARCHAR(255) DEFAULT NULL
) ENGINE=MEMORY;
WHILE (rowsJSON != '') DO
BEGIN
DECLARE rowJSON VARCHAR(4096) DEFAULT NULL;
DECLARE temp JSON;
DECLARE userid INT DEFAULT NULL;
DECLARE username VARCHAR(255) DEFAULT NULL;
SET rowJSON = CONCAT(SUBSTRING_INDEX(rowsJSON, '}', 1), '}');
SET temp = JSON_EXTRACT(rowJSON, '$.userid');
SET userid = COALESCE(IF(JSON_TYPE(temp) = 'NULL', NULL, REPLACE(temp, '\"', '')));
SET temp = JSON_EXTRACT(rowJSON, '$.username');
SET username = COALESCE(IF(JSON_TYPE(temp) = 'NULL', NULL, REPLACE(temp, '\"', '')));
INSERT INTO rowsToUse(user_id, user_name)
VALUES(userid, username);
IF LOCATE('{', rowsJSON, 2) > 0 THEN
SET rowsJSON = SUBSTRING(rowsJSON, LOCATE('{', rowsJSON, 2));
ELSE
SET rowsJSON = '';
END IF;
END;
END WHILE;
SET SQL_SAFE_UPDATES=0;
# Getting syntax error here
DECLARE CONTINUE HANDLER FOR 1062
BEGIN
GET DIAGNOSTICS CONDITION 1
code = RETURNED_SQLSTATE, msg = MESSAGE_TEXT;
END;
INSERT INTO user_table(user_id, user_name, created_by , created_date)
SELECT user_id, user_name, 'system', NOW()
FROM rowsToUse;
IF code = '00000' THEN
GET DIAGNOSTICS rows = ROW_COUNT;
SET result = CONCAT('insert succeeded, row count = ',rows);
ELSE
SET result = CONCAT('insert failed, error = ',code,', message = ',msg);
END IF;
DROP TEMPORARY TABLE IF EXISTS rowsToUse;
SET SQL_SAFE_UPDATES=1;
SELECT result;
END
$$
DELIMITER ;
==============================================================
Kindly help me on this.

nested cursor in mysql but showing syntax error

DELIMITER $$
USE `g4winners2`$$
DROP PROCEDURE IF EXISTS `wagerMigration`$$
CREATE DEFINER=`root`#`localhost` PROCEDURE `wagerMigration`()
BEGIN
DECLARE tbrace_done, tbrunner_done BOOLEAN DEFAULT FALSE;
DECLARE race_card_id INT(10);
DECLARE race_number INT(10);
DECLARE day_evening VARCHAR(10) ;
DECLARE locale_type VARCHAR(50) ;
DECLARE course_surface VARCHAR(8) ;
DECLARE distance_unit VARCHAR(8) ;
DECLARE race_type VARCHAR(50) ;
DECLARE sex_restriction VARCHAR(8) ;
DECLARE age_restriction VARCHAR(8) ;
DECLARE purse_usa DECIMAL(18,2) ;
DECLARE maximum_claim_price DECIMAL(9,2) ;
DECLARE race_name VARCHAR(120) ;
DECLARE race_condition VARCHAR(255) ;
DECLARE condition_text TEXT ;
DECLARE post_time TIME ;
DECLARE race_date TIMESTAMP;
DECLARE is_active TINYINT(1) ;
DECLARE race_status_type INT(11) ;
DECLARE gait VARCHAR(50) ;
DECLARE field_size SMALLINT(6);
DECLARE weather VARCHAR(25);
DECLARE comments VARCHAR(128);
DECLARE odds_updated DATETIME;
DECLARE pools_updated DATETIME;
DECLARE win_pool_total INT(11);
DECLARE plc_pool_total INT(11);
DECLARE shw_pool_total INT(11);
declare horse_name varchar(50);
declare foaling_area char(3);
declare color varchar(255);
declare sex varchar(255);
declare breeder_name varchar(255);
declare sire_name varchar(255);
declare post_position int(10);
declare program_number varchar(255);
declare weight_carried int(10);
declare scratch_indicator varchar(255);
declare trainer_first_name varchar(255);
declare owner_name varchar(255) ;
declare jockey_first_name varchar(255);
declare odds varchar(255) ;
declare owner_silks varchar(255);
declare live_odds varchar(255);
declare is_visible tinyint(10);
declare finish_position smallint(6);
declare dead_heat_flag smallint(6);
declare distance_from_winner smallint(6);
declare win_pool int(11);
declare plc_pool int(11);
declare shw_pool int(11);
DECLARE curRace CURSOR FOR SELECT ee.event_number,"wer",'en_us',ee.surface,ee.distance,ee.race_type_text,ee.sex_restriction ,ee.age_restriction,
ee.purse,ee.max_claiming_price,ee.event_name,ee.race_conditions1,ee.track_conditions,ee.post_time,ee.raceday,ee.confirmed_flag,ee.status,ee.gait,
ee.field_size,ee.weather,ee.comments,ee.odds_updated,ee.pools_updated,ee.win_pool_total,ee.plc_pool_total,ee.shw_pool_total
FROM ebet.events ee ,ebet.race_meetings trc
WHERE trc.meeting_number=ee.meeting_number
AND trc.raceday=ee.raceday;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET tbrace_done = TRUE;
OPEN curRace;
cur_race_loop: LOOP
FETCH FROM curRace INTO race_number ,day_evening ,locale_type,course_surface,distance_unit,race_type,sex_restriction ,age_restriction
,purse_usa ,maximum_claim_price ,race_name ,race_condition ,condition_text
,post_time ,race_date ,is_active ,race_status_type ,gait
,field_size,weather,comments,odds_updated,pools_updated,win_pool_total,plc_pool_total,shw_pool_total;
IF tbrace_done THEN
CLOSE curRace;
LEAVE cur_race_loop;
END IF;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO g4winners2.tb_races(race_number ,day_evening ,locale_type,course_surface,distance_unit,race_type,sex_restriction ,age_restriction
,purse_usa ,maximum_claim_price ,race_name ,race_condition ,condition_text
,post_time ,race_date ,is_active ,race_status_type ,gait
,field_size,weather,comments,odds_updated,pools_updated,win_pool_total,plc_pool_total,shw_pool_total)
VALUES (race_number ,day_evening ,locale_type,course_surface,distance_unit,race_type,sex_restriction ,age_restriction
,purse_usa ,maximum_claim_price ,race_name ,race_condition ,condition_text
,post_time ,race_date ,is_active ,race_status_type ,gait
,field_size,weather,comments,odds_updated,pools_updated,win_pool_total,plc_pool_total,shw_pool_total);
SET FOREIGN_KEY_CHECKS=1;
SET #ID:=(SELECT LAST_INSERT_ID());
SELECT CONCAT ("Result :**", #ID, " ") AS '';
SET FOREIGN_KEY_CHECKS=0;
BLOCK2: BEGIN
DECLARE curRunner CURSOR FOR SELECT er.runner_name,er.area_foaled,er.color,er.sex,er.breeder,er.sire,er.post_position,er.program_number ,er.weight,
er.scratched_flag,er.trainer,er.owner,er.jockey,er.morning_line_odds,er.silks,er.current_odds,'1', er.finish_position,er.dead_heat_flag
,er.distance_from_winner,er.win_pool,er.plc_pool,er.shw_pool FROM ebet.runners er ,ebet.events ee
WHERE
ee.meeting_number=er.meeting_number
AND ee.event_number=er.event_number
AND ee.raceday=er.raceday;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET tbrunner_done = TRUE;
OPEN curRunner;
cur_runner_loop: LOOP
FETCH curRunner INTO horse_name,foaling_area,color,sex,breeder_name,sire_name,post_position,program_number,weight_carried,scratch_indicator,trainer_first_name,owner_name,jockey_first_name,odds,owner_silks,live_odds,is_visible,finish_position,dead_heat_flag,distance_from_winner,win_pool,plc_pool,shw_pool;
IF tbrace_done THEN
set tbrace_done = false;
CLOSE curRunner;
LEAVE cur_runner_loop;
END IF;
INSERT INTO g4winners2.tb_race_runners(race_id,horse_name,foaling_area,color,sex,breeder_name,sire_name,post_position,program_number ,
weight_carried,scratch_indicator ,trainer_first_name ,owner_name ,jockey_first_name,odds ,owner_silks ,live_odds ,is_visible
,finish_position,dead_heat_flag,distance_from_winner,win_pool,plc_pool,shw_pool
) values(#ID,horse_name,foaling_area,color,sex,breeder_name,sire_name,post_position,program_number ,
weight_carried,scratch_indicator ,trainer_first_name ,owner_name ,jockey_first_name,odds ,owner_silks ,live_odds ,is_visible
,finish_position,dead_heat_flag,distance_from_winner,win_pool,plc_pool,shw_pool);
END LOOP cur_runner_loop;
END BLOCK2;
END LOOP cur_race_loop;
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 118 (0 ms taken)
Could it be a false error as it can not compile as you have no "END" to the overall procedure?. You close out your loops and block, but not the procedure.

MySQL syntax error with declarations

I am trying to create a transaction procedure in MySQL and I keep receiving the following syntax error which is occurring in my variable declarations:
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 ';
DECLARE emp_duplicate INT DEFAULT 0;
DECLARE old_empnum INT DEFAULT 0;
DECL' at line 6
Below is my procedure:
DELIMITER $$
DROP PROCEDURE IF EXISTS new_employee$$
CREATE PROCEDURE new_employee(in_Fname VARCHAR(15),in_Lname VARCHAR(15),
in_hire DATE, in_DOB DATE, in_sal Numeric(7,2))
BEGIN
DECLARE out_message VARCHAR;
DECLARE emp_duplicate INT DEFAULT 0;
DECLARE old_empnum INT DEFAULT 0;
DECLARE out_empnum INT DEFAULT 0;
DECLARE time_created DATETIME;
DECLARE user_var VARCHAR;
DECLARE age_var Int DEFAULT 0;
START TRANSACTION;
Select MAX(Empno)
Into old_empnum
From emp;
Select COUNT(*)
Into emp_duplicate
From emp
Where (in_Fname=Fname AND in_Lname=Lname AND in_hire=HireDate AND in_DOB=DOB);
IF emp_duplicate=0 THEN
SET out_message = 'New employee update successful';
SET out_empnum = old_empnum + 1;
SET time_created = CURRENT_TIMESTAMP();
SET user_var = USER();
SET age_var = DATEDIFF(CURRENT_DATE,in_DOB);
INSERT INTO emp(Empno,Fname,Lname,HireDate,DOB,SAL)
VALUES(in_Fname,in_Lname,in_hire,in_DOB,in_sal);
INSERT INTO log(Empno,DateCreated,Who)
VALUES(out_empnum,time_created,user_var);
SELECT out_message;
SELECT Empno, Fname, Lname, DATEDIFF(CURRENT_DATE,DOB), HireDate
From emp;
ELSE
SET out_message = 'Employee already exists';
SELECT out_message;
END IF;
COMMIT;
END$$
DELIMITER ;
I am using cmd and notepad to execute my code (just in case that's helpful). For the life of me, I cannot see the error with my declarations?????
you need to define the VARCHAR size like this
DECLARE out_message VARCHAR(20);
try this
BEGIN
DECLARE out_message VARCHAR(20); // // varchar size here
DECLARE emp_duplicate INT DEFAULT 0;
DECLARE old_empnum INT DEFAULT 0;
DECLARE out_empnum INT DEFAULT 0;
DECLARE time_created DATETIME;
DECLARE user_var VARCHAR(20); // varchar size here
DECLARE age_var Int DEFAULT 0;
you forget to datatype size for DECLARE out_message VARCHAR (30) and DECLARE user_var VARCHAR(30);
DECLARE out_message VARCHAR (30); <------------- here
DECLARE emp_duplicate INT DEFAULT 0;
DECLARE old_empnum INT DEFAULT 0;
DECLARE out_empnum INT DEFAULT 0;
DECLARE time_created DATETIME;
DECLARE user_var VARCHAR(30); <------------- here
DECLARE age_var Int DEFAULT 0;
In insert statement you are missing value for Empno
INSERT INTO emp(Empno,Fname,Lname,HireDate,DOB,SAL)
VALUES(in_Fname,in_Lname,in_hire,in_DOB,in_sal);