Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:01:14+00:00 2026-06-10T16:01:14+00:00

I have this procedure in MySQL DROP PROCEDURE IF EXISTS `AddNotificationOnPosts`; DELIMITER $$ CREATE

  • 0

I have this procedure in MySQL

DROP PROCEDURE IF EXISTS `AddNotificationOnPosts`;

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `AddNotificationOnPosts`(from_user INT(11),on_post_id INT(11),in_group_id INT(11))
BEGIN
    DECLARE num_rows INT DEFAULT 0;

    SELECT count(notification_id) FROM notifications_posts 
    WHERE from_user = 1;

END $$
DELIMITER ;

and this table

notification_id from_user   on_post_id  in_group_id date
2   1   162 3   2012-07-11 12:01:08
3   19  163 1   2012-07-11 12:03:26
4   19  164 1   2012-08-10 17:42:36
5   1   165 3   2012-08-29 12:14:01
6   1   165 3   2012-08-29 12:14:29

when i execute:

SET @p0 =  '1';
SET @p1 =  '2';
SET @p2 =  '3';
CALL `AddNotificationOnPosts` ( @p0 , @p1 , @p2 );

it gives me:

count(notification_id)
5

why? because they are only 3 records of user_id 1

And also how do i make this procedure to:

  1. Give an error or warning when values are not set

  2. Get variables from the procedure, something like

    SELECT count(notification_id) FROM notifications_posts 
    WHERE from_user = @from_user;
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:01:15+00:00Added an answer on June 10, 2026 at 4:01 pm

    You should use different names for arguments:

    CREATE PROCEDURE AddNotificationOnPosts
    (arg_from_user INT(11),arg_on_post_id INT(11),arg_in_group_id INT(11))
    BEGIN
        DECLARE num_rows INT DEFAULT 0;
    
        IF(arg_from_user  IS NULL OR arg_from_user = '')
        THEN 
            SELECT "Error:Invalid argument for userID" AS error_code;
        ELSE
            SELECT count(notification_id) 
            INTO num_rows
            FROM notifications_posts 
            WHERE from_user = arg_from_user;
        END IF;
    
        SELECT num_rows;
    END $$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SOLVED: This works: DROP PROCEDURE IF EXISTS drop_all_tables_from_specified_database; DELIMITER $$ CREATE PROCEDURE drop_all_tables_from_specified_database(IN dbname
I have this sql file: USE mydb; DROP PROCEDURE IF EXISTS execSql; DELIMITER //
I have a simple stored procedure in MySQL database: DELIMITER $$ CREATE DEFINER=`vidhu`@`%` PROCEDURE
I'm writing a simple MySQL stored procedure: DELIMITER $ DROP PROCEDURE IF EXISTS GetUserByCaseId
I have the following code: delimiter ; DROP PROCEDURE IF EXISTS ufk_test; delimiter //
I am using the following sql: DELIMITER $$ DROP PROCEDURE IF EXISTS `get_auto_increment_settings`$$ CREATE
I have a mysql stored procedure from this ( google book ), and one
I have this stored procedure: CREATE OR REPLACE PROCEDURE LIQUIDACION_OBTENER ( p_Cuenta IN NUMBER,
I have this stored procedure for Oracle: create or replace procedure bns_saa_message_get() <--- PROBLEM
i have a stored procedure in mysql, accessed by a php page. this page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.