Creating a simple stored procedure reaching max execution time - mysql

I am trying to create a simple stored procedure in phpmyadmin.
But the page is taking for long time and reaches the maximum execution time which results in an error.
This is the table structure:
id usr_id message
1 1 dfsfa
2 2 fd
3 1 fsdfsdf
4 1 fsd
5 1 fsdvxc
This is the store procedure query I am trying to execute:
delimiter //
create procedure myProc()
begin
select message from consecutive;
end //
delimiter ;
This is the error I am getting:
Fatal error: Maximum execution time of 300 seconds exceeded in
D:\wamp\apps\phpmyadmin3.2.0.1\libraries\import\sql.php on line 119

Try this:
DELIMITER $$
CREATE PROCEDURE `myProc`()
BEGIN
select message from consecutive;
END

If that is your entire stored procedure then the reason is as simple as you're not doing anything. If we go through the thing line by line:
Create the procedure
create procedure myProc()
Indicate the start of code
begin
Select every row from consecutive
select message from consecutive;
The end
end
As you can see you're not actually doing anything other than selecting everything from a single table, which is why it's taking so long.
It would be normal if your query was something like:
select message
from consecutive
where id = my_passed_variable
-- do something else...

Related

Call a stored procedure every 5 seconds in MySQL

I have written a stored procedure in MySQL and I want to execute it every 5 seconds, but when I simply run the stored procedure, it doesn't add any records to another table. But if I run the query separately, it works fine but in stored procedure it doesn't.
And how can I call it every 5 seconds.
Here is the stored procedure
DELIMITER //
CREATE PROCEDURE ctrdata2.call_detail()
begin
INSERT INTO ctrdata2.reporting_call_detail
SELECT *
FROM ctrdata2.call_detail
WHERE EXISTS
(
SELECT end_time
FROM ctrdata2.transactions_reporting_call_detail
WHERE call_detail.initiationtimestamp > transactions_reporting_call_detail.end_time);
END
Try adding the below code too.
CREATE EVENT runEveryFiveSeconds
ON SCHEDULE EVERY 5 SECOND
DO
CALL ctrdata2.call_detail();

MySQL query does not execute if i use the Stored Procedure parameter in the query

I am creating a very simple store procedure with a query, but when i use the store procedure IN parameter in the query it gets stuck and does not execute the query, but if i put the value direct to the query it works.
This works:
CREATE PROCEDURE `cap-reports`.ffap_test()
BEGIN
select * FROM students WHERE name='Fernando';
END
This does not, i spent 10 minutes and it never returned
CREATE PROCEDURE `cap-reports`.ffap_test(IN pName VARCHAR(10))
BEGIN
select * FROM students WHERE name=pName;
END
call `cap-reports`.ffap_test('Fernando');
What mistake i am doing here? I never had this problem before
This procedure works for me. Maybe it's the difference in database of the procedure and the students table? Or a missing semi-colon?
CREATE PROCEDURE `cap-reports`.ffap_test(IN pName VARCHAR(10))
BEGIN
select * FROM `cap-reports`.members m WHERE m.Username = pName;
END
;
CALL `cap-reports`.ffap_test('winkbrace');

Matlab and MySQl, inconsistent results

I am having a problem loading data from MySQL into Matlab.
I am just running a stored procedure. When I run it from MySQL it returns 1,500 rows.
When I run it from Matlab, it will return 1 record when I first start up Matlab. If I re-run it a few times I might eventually get 1,500 rows. Earlier it took 30 minutes before it would return 1,500 rows.
My store procedure is:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`#`localhost` PROCEDURE `latest_hl_tradables`()
BEGIN
DECLARE latest_date DATE ;
SELECT max(available_on_platform.on_date)
FROM available_on_platform
INNER JOIN platform ON (available_on_platform.platform_id=platform.id)
where platform.name='aaa'
INTO latest_date;
SELECT fund_id,fund_class_id,fund_class.name as fund_class_name,sedol,isin,max(on_date) as on_date
FROM available_on_platform
INNER JOIN fund_class ON (fund_class.id=available_on_platform.fund_class_id)
INNER JOIN platform ON (available_on_platform.platform_id=platform.id)
WHERE on_date>=latest_date-5
AND platform.name='aaa'
GROUP BY fund_class_id,fund_class.name,sedol,isin;
END
My Matlab Code is:
conn=database('fund_data3','','');
sql = 'call latest_hl_tradables()';
curs = exec(conn,sql);
curs = fetch(curs);

mysql stored procedure, use column name as an argument

i have here a table of tapes with 3 fields:
Tapes
TapesID Title Qty
T1 BatDog 3
T2 UnderCat 2
T3 IronMouse 1
T4 Boys Zone 1
T5 RoboCat 1
i want to create a stored procedure that extract and displays specific id’s of tape by entering tape title as argument to the procedure. The procedure should be called list_tspec_id.
can u help me out?im having a hard time with this...
here's my code but it's not right:
create procedure tapesid
#columnname varchar
AS
begin
select #columnname from tapes
end
exec tapesid 'title'
You've tagged this as MySQL, so... here's a stored procedure, though it's unclear from your example what you're really wanting it to do or why.
The variables passed into a stored procedure as arguments don't use '#' in front of them.
DELIMITER $$
CREATE PROCEDURE list_tspec_id (IN my_title VARCHAR(254))
BEGIN
SELECT TapesID, Title, Qty FROM Tapes WHERE Title = my_title;
END $$
DELIMITER ;
then...
mysql> CALL list_tspec_id('BatDog');

Calling a user defined stored procedure from select statement mysql

I am trying to call a user defined stored procedure from a select statement and its giving me an error. However when I call a system procedure it works just fine. Is there a way to call a user defined procedure from a select statement. This is for mysql
SELECT ID, email FROM user PROCEDURE simpleproc();
give me an error ERROR 1106 (42000): Unknown procedure 'simpleproc'
mysql> call simpleproc();
Query OK, 0 rows affected (0.21 sec)
where as
SELECT ID, email FROM user PROCEDURE ANALYSE();
works
You can call stored procedure from select statement,To call a procedure you must use following syntax:
CALL stored_procedure_name (param1, param2, ....)
Such as, you can CALL following procedure:
DELIMITER //
CREATE PROCEDURE `procedure1`(IN var1 INT)
BEGIN
SELECT var1 + 2 AS result;
END//
as
CALL procedure1(10);
Check this site for reference: http://net.tutsplus.com/tutorials/an-introduction-to-stored-procedures/