Error 1064 (42000) on create procedure MySQL - mysql

I'm having this specific error when trying to create a stored procedure on MySQL database:
CREATE PROCEDURE GET_COLUMNS(TABLENAME VARCHAR(50))
BEGIN
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'SolarTV' AND TABLE_NAME=TABLENAME;
END

All you should need to do here is temporarily change the delimiter while defining the procedure, then set it back to ; after the procedure has been created. Otherwise it'll get confused when it sees the first ; from within the procedure definition. Example:
DELIMITER //
CREATE PROCEDURE GET_COLUMNS(TABLENAME VARCHAR(50))
BEGIN
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'SolarTV' AND TABLE_NAME=TABLENAME;
END//
DELIMITER ;

Related

Create temporary table in procedure, MySql

I need create a simple procedure, but after create a temporary table, mysql wants put 'end' after semicolon.
CREATE procedure zad2()
begin
drop temporary table if exists temp;
create temporary table temp as (select table_name, column_name
from information_schema.columns where table_schema = 'lista3' and table_name not like 'lista');
declare i int default 0;
end$$
SQL Stored procedure have a block where you will put all code/logic .. and that block is BEGIN and END , if you have an opening block which is BEGIN , you need to close it with END, that's why MySql wants you to put END after semi colon.
Below link can help with the syntax:
CREATE PROCEDURE and CREATE FUNCTION Syntax
I think that what is missing is to declare the DELIMITER $$ at the start of the statement:
DELIMITER $$ /*To tell MySQL that your delimiter is now '$$' */
CREATE procedure zad2()
begin
drop temporary table if exists temp;
create temporary table temp as (select table_name, column_name
from information_schema.columns where table_schema = 'lista3' and table_name not like 'lista');
declare i int default 0;
end$$
DELIMITER ; /*To tell your MySQL that you delimiter is back ';' */

How can i insert a information_schema inside a stored proceedure

guys im quite new to stored proceedures. can anyone guide me on how to put the following simple sql query inside a stored proceedure
$tables = mysql_query("SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'Fogdb' AND table_name LIKE 'fdb_table_%' ");
i tried like below but it dint work
DELIMITER $$
DROP PROCEDURE IF EXISTS `alter_test_1`$$
CREATE DEFINER=`Fogdb`#`10.%` PROCEDURE `alter_test_1`()
BEGIN
SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'Fogdb' AND table_name LIKE 'fdb_table_%'
END$$
DELIMITER ;
try this:
create procedure test()
begin
SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'Fogdb' AND table_name LIKE 'fdb_table_%';
end
In your script, You have forget to put ';' at end of query;
Now try
DELIMITER $$
DROP PROCEDURE IF EXISTS `alter_test_1`$$
CREATE DEFINER=`adtracker`#`10.%` PROCEDURE `alter_test_1`()
BEGIN
SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'Fogdb' AND table_name LIKE 'fdb_table_%' ;
END$$
DELIMITER ;

MySQL IF THEN condition to Drop a table

I am trying to use stored procedure and check on a particular table and use IF THEN condition to drop the table. Is it possible to issue the DROP statement in the conditional block?
delimiter $$
CREATE PROCEDURE FC_SQLF()
BEGIN
DECLARE SQLFOUND int;
SET #SQLFOUND = (select count(table_name) from information_schema.tables where table_schema = 'testdb' and table_name = 'temp_table');
IF #SQLFOUND = 1 THEN DROP TABLE testdb.abcd;
END IF;
END $$

MySQl navicat :: Error in adding parameters

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 ;

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 ;