MySQl navicat :: Error in adding parameters - mysql

CREATE DEFINER = CURRENT_USER PROCEDURE `NewProc`(IN `pName` varchar)
BEGIN
SELECT * from ss
END;;
when I try to save this SP using navicat to MySql Db i face syntax error problem at line number 1, when i delete the parameter, SP is saved

You have to specify the length of pName in your parameter.
Try this:
DELIMITER $$
DROP PROCEDURE IF EXISTS `NewProc`$$
CREATE DEFINER = CURRENT_USER PROCEDURE `NewProc`(IN `pName` VARCHAR(100))
BEGIN
SELECT * FROM ss;
END$$
DELIMITER ;

Related

Delete Stored Procedure not working in SQL

I'm trying to create a stored procedure for deleting a record in my table.
I have tried the following but it doesn't seem to work:
Delimiter //
CREATE PROCEDURE BIRD_STRIKE_INCIDENT_DELETE #row text
AS
BEGIN
DELETE FORM bird_strike.incidents WHERE row_names = #row
END
delimiter ;
Call BIRD_STRIKE_INCIDENT_DELETE('11')
Can someone provide pointers on what I might be doing wrong here?
Thanks!
Your code looks more like SQL Server than MySql
This should be so
Delimiter //
CREATE PROCEDURE BIRD_STRIKE_INCIDENT_DELETE (_row text)
BEGIN
DELETE FROM bird_strike.incidents WHERE row_names = _row;
END//
delimiter ;
You can consider this approach.
IF EXISTS(SELECT 1 FROM sys.procedures
WHERE Name = 'BIRD_STRIKE_INCIDENT_DELETE')
BEGIN
DROP PROCEDURE dbo.BIRD_STRIKE_INCIDENT_DELETE;
END;
else
BEGIN
CREATE PROCEDURE BIRD_STRIKE_INCIDENT_DELETE (_row text)
BEGIN
DELETE FROM bird_strike.incidents WHERE row_names = _row;
END
END;

#1305 - PROCEDURE does not exist in mysql

DELIMITER $$
DROP PROCEDURE IF EXISTS `insert_or_update`$$
CREATE PROCEDURE insert_or_update(
IN username VARCHAR(70),
IN score INT,
IN titlein VARCHAR(70)
)
begin
IF EXISTS (SELECT * FROM two_player WHERE title=titlein and user1!=username and user2='') THEN
UPDATE two_player SET score12=score , user2=username WHERE title=titlein and user1!=username and user2='' limit 1;
ELSE
INSERT INTO two_player (user1,score11,title) values (username, score, titlein);
END if;
END$$
DELIMITER ;
call insert_or_update('sara',20,'math');
I create a procedure. But when I try to call it I get this error message:
#1305 - PROCEDURE u941310304_menu.insert_or_update does not exist
What's wrong?
I tested you code and the call to procedure works.
Your default database is u941310304_menu, it seems you are creating the procedure in another db. You can create the procedure specifying the destination database.
DELIMITER $$
DROP PROCEDURE IF EXISTS `u941310304_menu`.`insert_or_update`$$
CREATE PROCEDURE `u941310304_menu`.insert_or_update(
[...]
If the procedure is in another database you must specify the db name as prefix:
call `another_database`.insert_or_update('sara',20,'math');

mysql stored procedure error: missing semicolon

I have following store procedure. It is give me some error
DROP procedure IF exists getQueueMessage;
DELIMITER $$
CREATE DEFINER=`root`#`localhost` PROCEDURE `getQueueMessage`(msg varchar(100))
BEGIN
SELECT `Name` FROM queues WHERE Id IN (
SELECT PhysicalQueueId FROM indexqueuemaps WHERE ConditionFieldValue = msg)
END
END$$
DELIMITER ;
It is giving me missing semicolon error. Don't know Why this error is getting. Can someone help me?
Try like this:
DROP procedure IF exists getQueueMessage;
DELIMITER $$
CREATE DEFINER=`root`#`localhost` PROCEDURE `getQueueMessage`(msg varchar(100))
BEGIN
SELECT `Name` FROM queues WHERE Id IN (
SELECT PhysicalQueueId FROM indexqueuemaps WHERE ConditionFieldValue = msg);
END$$
DELIMITER ;
There's only one BEGIN and two ENDs, remove the 2nd END and you should be fine.
Replace root#localhost with root#localhost

Stored Procedure using Select Error 1064

I have a simple procedure to select data from an column and show them
DELIMITER //
DROP PROCEDURE IF EXISTS `testing`
CREATE PROCEDURE `testing`(IN param1 VARCHAR(40))
BEGIN
SELECT * FROM testingdatabase,
END //
DELIMITER;
However I keep getting error 1064
SELECT * FROM testingdatabase;
use ; not ,
So it should be:
DELIMITER //
DROP PROCEDURE IF EXISTS `testing`//
CREATE PROCEDURE `testing`(IN param1 VARCHAR(40))
BEGIN
SELECT * FROM testingdatabase;
END //
DELIMITER ;
DELIMITER //
DROP PROCEDURE IF EXISTS `testing`//
CREATE PROCEDURE `testing`(IN param1 VARCHAR(40))
BEGIN
SELECT * FROM testingdatabase;
END //
DELIMITER ;
DELIMITER //
DROP PROCEDURE IF EXISTS testing//
CREATE PROCEDURE testing(IN param1 VARCHAR(40)) BEGIN
SELECT * FROM testingdatabase;
END //
DELIMITER ;
Check this
DELIMITER $$
CREATE
PROCEDURE `testing`(IN param1 VARCHAR(40))
BEGIN
SELECT * FROM `test_table` WHERE `test_cdeo` LIKE param1;
END$$
DELIMITER ;
You can call and check your procedure via sql command like below code
CALL testing('149514')

ERROR when send table as parameter in MySQL store procedure

I wrote a store procedure. It executes properly, but when I call the procedure, it shows the error:
Error Code : 1327 Undeclared variable:
Third
Please see my procedure below:
DELIMITER $$
USE `db_test`$$
DROP PROCEDURE IF EXISTS `test_proc`$$
CREATE DEFINER=`root`#`localhost` PROCEDURE `test_proc`(IN newsInfoTable VARCHAR(100))
BEGIN
SET #sql_stam = CONCAT('SELECT news INTO ', #news,' FROM ',newsInfoTable,' WHERE ',CURDATE(),'=?;');
PREPARE s1 FROM #sql_stam;
SET #where_param = DATE_FORMAT(date_time,'%Y-%m-%d');
EXECUTE s1 USING #where_param;
SELECT #news;
END$$
DELIMITER ;
Calling parameter:
USE db_test;
CALL test_proc('tbl_morning_news');
Change your code into:
DELIMITER $$
USE `db_test`$$
DROP PROCEDURE IF EXISTS `test_proc`$$
CREATE DEFINER=`root`#`localhost` PROCEDURE `test_proc`(IN newsInfoTable VARCHAR(100))
BEGIN
SET #sql_stam = CONCAT( 'SELECT news INTO #news FROM ',newsInfoTable
,' WHERE DATE(`date_time`) = CURDATE()' );
PREPARE s1 FROM #sql_stam;
SELECT #news;
END$$
DELIMITER ;