Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2013
    Posts
    1

    Unanswered: How to Create a Stored Procedure in MySQL

    Hello!

    I am new to creating stored procedures in any RDBMS server and I have started learning this concept using MySQL server.

    I have the following table in my database.

    Table Name: Forum

    Columns:-
    Id - Datatype: INTEGER
    Title - Datatype: VARCHAR(200)
    Category - Datatype: VARCHAR(200)
    UserId - Datatype: VARCHAR(200)

    I want to create a stored procedure which adds rows to this table. Hence I use the following syntax.

    create procedure add_forum (
    f_id in integer,
    f_title in varchar(200),
    f_category in varchar(200),
    f_userid in integer)

    as
    begin
    /*Insert new row of forum table*/
    insert into forum(id, title, category, userid)
    values (f_id, f_title, f_category, f_userid)

    /*Commit transaction*/
    commit
    end;

    However when I try to execute the above piece of code to create the procedure, MySQL throws me the following error.

    "Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL version for the right syntax to use near in 'int(11),
    f_title in varchar(200),
    f_category in varchar(200),
    f_userid in ' at line 2
    "

    Can anyone please help me resolve this error please. Replies at the earliest will be highly appreciated. Thank you in advance.
    Last edited by rugvedmandrekar; 07-23-13 at 10:30.

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    If you look at the documentation you will see that stored procedure parameters have a slightly different format. The mode IN, OUT or INOUT must be specified first. So in your case:

    create procedure add_forum (
    IN f_id integer,
    IN f_title varchar(200),
    IN f_category varchar(200),
    IN f_userid integer)
    ...
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •