I am trying to create a mysql stored procedure with phpmyadmin:
CREATE PROCEDURE AddTableColumn()
BEGIN
IF (SELECT COUNT (table_name)
FROM information_schema.tables
WHERE table_name IN ('authors', 'publishers') = 2 )
print 'specified tables exist...';
ELSE
print 'specified tables unavailable...';
END IF;
END
above code is a snippet that should search information schema for the availability of authors and publishers tables, then proceed to add new column in each table if present.
the print statement was for debug purpose. when i clicked the GO command, here's the error message :
MySQL said:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'print 'avail...'; ELSE print 'unavail...'; END IF; END' at line 7.
what am i doing wrong ? i have even tried other code as a test, all failing with the same error. code as simple as:
BEGIN
IF (6 > 4)
print 'greater';
ELSE
print 'lesser';
END IF;
END
all failed. any help will be appreciated.
'print'
is not recognized inMySQL
.If you want to read back the output, just use a
select
in the SP.Change part of your SP as below: