[mysql] How to call a mysql stored procedure, with arguments, from command line?

How can I call a stored procedure from command line?

I have a procedure:

CREATE DEFINER=`root`@`localhost` PROCEDURE `insertEvent`(IN `dateTimeIN` DATETIME)
    NO SQL
BEGIN
    SET @eventIDOut = NULL;

    IF  EXISTS(SELECT * FROM `events` WHERE `eventDate` = dateTimeIN) THEN
        SELECT `eID` INTO @eventIDOut FROM `events` WHERE `eventDate` = dateTimeIN LIMIT 1;
        ELSE
        INSERT INTO `events` (`eventDate`) VALUES(dateTimeIN);
        SET @eventIDOut = last_insert_id();
    END IF;

    SELECT CONCAT(@eventIDOut);
END
  1. I tried this: mysql> CALL insertEvent(2012.01.01 12:12:12);

    Result:

    ERROR 1064 (42000): 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 '.01 12:12:12)' at line 1

  2. And this: mysql> CALL insertEvent

    -> 2012.01.01 12:12:12;

    Result:

    ERROR 1064 (42000): 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 '2012.01.01 12:12:12' at line 2

This question is related to mysql command-line call procedure

The answer is


With quotes around the date:

mysql> CALL insertEvent('2012.01.01 12:12:12');

Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to command-line

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Flutter command not found Angular - ng: command not found how to run python files in windows command prompt? How to run .NET Core console app from the command line Copy Paste in Bash on Ubuntu on Windows How to find which version of TensorFlow is installed in my system? How to install JQ on Mac by command-line? Python not working in the command line of git bash Run function in script from command line (Node JS)

Examples related to call

ReactJS - Call One Component Method From Another Component Call a Class From another class What does it mean to "call" a function in Python? How to make method call another one in classes? How to call a mysql stored procedure, with arguments, from command line? Submit form on pressing Enter with AngularJS Running bash script from within python javascript: get a function's variable's value within another function Passing variables, creating instances, self, The mechanics and usage of classes: need explanation Android Call an method from another class

Examples related to procedure

ORA-06550: line 1, column 7 (PL/SQL: Statement ignored) Error How to call a mysql stored procedure, with arguments, from command line? set serveroutput on in oracle procedure Creating a procedure in mySql with parameters What is the difference between a "function" and a "procedure"?