Call a stored procedure every 5 seconds in MySQL - 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();

Related

Create an Event inside a procedure

I have a condition, where I want to create an event inside a procedure for multiple Databases.
I want to first create an event from procedure.
I am getting below error,
MySQL said: #1576 - Recursion of EVENT DDL statements is forbidden when body is present
Below is my sample query, Any help please
CREATE PROCEDURE ActivateHolidays()
BEGIN
CREATE EVENT myevent
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
DO
SELECT * from employee;
END

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');

Display result of MYSQL event scheduler in an interface

I have a database containing the name and the associated birthday. I have set an event scheduler to periodically check the database for bithdays within two days from the current date. This is my code-
DELIMITER $$ CREATE EVENT `Reminder` ON SCHEDULE
EVERY 1 Day
ON COMPLETION PRESERVE
ENABLE
DO BEGIN
select * from reminder where date_format(date_sub(Birthday,interval 2 day),'%m-%d') = Date_Format(curdate(),'%m-%d');
END $$
DELIMITER ;
Apparently the sql query does not display any information. I would like to display the result of the query in an interface, whenever the query returns at least one row.

Creating a simple stored procedure reaching max execution time

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...

Executing MYSQL Stored Procedures using DBVisualizer

I am using DBVisualizer for the first time. I have made a stored procedure in mysql database. However I am unable to execute it from DBVisualizer.
This is how the procedure looks like. Here // is used as delimiter. I have four columns in the table namely slno int (autoincrement), time timestamp, price int, and prodid varchar.
*DROP PROCEDURE `spTest`//
CREATE DEFINER=`root`#`localhost` PROCEDURE `spTest`()
BEGIN
SELECT * FROM dummy1 where prodid=pr01;
END*
In DBVisualizer, I am executing #call spTest()
Where am I going wrong?
As the definer of the stored procedure is root, your DBVizualizer connection to MySQL must be as the root user in order to execute it.