18

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?

Sami
  • 8,168
  • 9
  • 66
  • 99

2 Answers2

46

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.

Karl Horky
  • 4,410
  • 2
  • 31
  • 35
Jake Feasel
  • 16,785
  • 5
  • 53
  • 66
  • 9
    @JakeFeasel: let me take this opportunity to thank you once more for the AWESOME SQL Fiddle. You're the man! :| Keep rocking... – Leniel Maccaferri Nov 17 '12 at 03:08
  • 3
    @LenielMacaferi lol Thanks! Glad you like the site. Keep up the good work on the SQL questions! – Jake Feasel Nov 17 '12 at 05:10
  • 6
    See also [this bigger example, which shows that the queries IN the procedure actually need ; to delimit](http://sqlfiddle.com/#!2/e5a27/3). – Konerak Dec 02 '14 at 12:33
  • @Konerak thanks for that example, it was very helpful! – ocean800 Jun 11 '15 at 20:15
  • 1
    @Konerak looks like using MySQL 5.6 it stop to work and showing an error: DDL and DML statements are not allowed in the query panel for MySQL; only SELECT statements are allowed. Put DDL and DML in the schema panel . I'm using the example you sent http://sqlfiddle.com/#!2/e5a27/3 . there is another thread in Portuguese about it too https://pt.stackoverflow.com/questions/380029/erro-ao-realizar-chamada-de-procedure-no-sql-fiddle – Rafael Gorski May 04 '19 at 22:55
0

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 ;
    
Brad Parks
  • 66,836
  • 64
  • 257
  • 336
  • Can you keep it simple by defining delimiter right before `CREATE PROCEDURE dowhile() ` line like `DELIMITER // CREATE PROCEDURE dowhile() ` and end it right after procdure definition completes like `END// DELIMITER ;` – Sami Dec 21 '22 at 08:16
  • You will able to use normal `;` in all other statements except the create procedure statement – Sami Dec 21 '22 at 08:17
  • Hi, I have this one and it errors out, https://www.db-fiddle.com/f/7iPdu4Hdzs7S8dAHeRN6TT/4 – Chris Habgood May 15 '23 at 00:57