Execute triggers stored procedures on SqlFiddle. Mysql

zbwhf8kr  于 2022-12-22  发布在  Mysql
关注(0)|答案(2)|浏览(119)

Does SQL-fiddle facilitate execution of triggers/stored procedures?
I have been unable to execute even the simplest form of stored procedure on sqlfiddle

DELIMITER $$
DROP PROCEDURE IF EXISTS myProc $$

CREATE PROCEDURE myProc()
BEGIN

END$$
DELIMITER ;

Sqlfiddle does not allow executing this(above) sql in build schema, but allows create table etc

Note: The same syntax is working for me on my localhost using wamp with mysql 5.5.24

Can anyone guide please?

goqiplq2

goqiplq21#

Instead of using the delimiter option (which is not a real SQL statement, but rather only a command for the mysql command prompt) use the "Query Terminator" option on SQL Fiddle to establish your delimiter.
For example:
http://sqlfiddle.com/#!2/88fcf
Note the // dropdown below the schema box? That's the SQL Fiddle equivalent to the mysql DELIMITER command.
Longer example with queries in the stored procedure (note that within the stored procedure, ; is still used as a delimiter):
http://sqlfiddle.com/#!9/4db78
Full disclosure: I'm the author of SQL Fiddle.

xmq68pz9

xmq68pz92#

I couldn't get this answer to work on sql fiddle, but found db-fiddle, and it seems to work.
Example in DB Fiddle
If the above doesn't work for some reason, do the following

  • Go here: https://www.db-fiddle.com/
  • Enter the following SQL on the left, and SELECT * FROM tblTest; on the right.
  • Select "MySql 5.7" or whatever in dropdown.
  • Click "Run"
DELIMITER //

 CREATE TABLE tblTest (col1 INT)//

 INSERT INTO tblTest VALUES (9)//

 CREATE PROCEDURE dowhile() 
 BEGIN   
   DECLARE v1 INT DEFAULT 3;

   WHILE v1 > 0 DO
     INSERT INTO tblTest VALUES(v1);
     SET v1 = v1 - 1;   
   END WHILE; 
 END//

 INSERT INTO tblTest VALUES (8)//

 select * from tblTest// 
 call dowhile()// 
 select * from tblTest// 

 DELIMITER ;

相关问题