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 6935113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:03:35+00:00 2026-05-27T12:03:35+00:00

My task is to write a stored procedure that will first validate the data

  • 0

My task is to write a stored procedure that will first validate the data from a temporary table and then insert the data into the main table.
For this I am planning to iterate over each row of the temp table, validate it using some other stored procedure or user defined function and then insert the data into the main table.

My problem is how to iterate over the rows of temp table without using CURSORS because they are very slow and memory consuming. I want to use some looping structure instead of CURSOR.

Of course if any one has any other algorithm for the above problem there suggestions are welcome.

PS: I am using MYSQL DB

  • 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-05-27T12:03:35+00:00Added an answer on May 27, 2026 at 12:03 pm

    Without the use of Cursor, you could iterate using a temporary table and a While..Do statement.

    Let’s say you have two tables

    CREATE TABLE `user` (
      `id` int(11) NOT NULL auto_increment,
      `name` varchar(45) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM;
    

    And

    CREATE TABLE `tmp_user` (
      `id` int(11) NOT NULL auto_increment,
      `name` varchar(45) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM;
    

    Create the following routine, and adjust the validation process:

    DELIMITER $$
    USE `routines_sample`$$
    CREATE PROCEDURE `nocursor`()
    BEGIN
      Declare validId int;
      Declare validName varchar(45);
    
      -- drop the temporary table if exists
      Drop table if exists `routines_sample`.tmp_validation;
      -- create the temporary table, here you could use Engine=Memory
      Create table `routines_sample`.tmp_validation (`id` int not null, `name` varchar(45) not null, `valid` bit(1) not null) Engine=MyISAM;
    
      -- insert into the temporary table with a valid flag = 0 (false)    
      Insert into `routines_sample`.tmp_validation (`id`, `name`, `valid`)
      Select tu.id, tu.name, 0
      From `routines_sample`.tmp_user tu;
    
      -- while exists data to validate on temporary table do something    
      While exists(Select `id` From `tmp_validation` Where `valid` = 0) Do
    
        Select `id`, `name` Into @validId, @validName From tmp_validation Where `valid` = 0 Limit 1;
    
        -- do your validation
        Select @validId, @validName;
    
        -- don't forget to update your validation table, otherwise you get an endless loop    
        Update `tmp_validation` 
        Set `valid` = 1
        Where `id` = @validId;
    
      END WHILE;
    
      -- insert only valid rows to your destination table    
      Insert into `routines_sample`.`user` (`name`)
      Select `name` From `tmp_validation`
      Where `valid` = 1;
    
      -- drop the temporary table    
      DROP TABLE tmp_validation;
    
    END$$
    
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to write an ant task that removes files from a previously compiled JAR?
I want to write a script that will stop a scheduled task on a
Task: Write timestamps into MS SQL database table every second. Solutions: External application which
I have been assigned wit the task to write a program that takes a
I want to write a simple task which will update and commit source code
I want to call a rake task from a cron job that stores remote
Greetings, I want to write a script that handles simple http requests from Google
We've been given the task by my customer to export data from a legacy
I wrote a stored procedure and want to execute it within a Rake task.
I am trying to complete a seemingly simple task that has turned into a

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.