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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:39:06+00:00 2026-05-12T17:39:06+00:00

the MySQL manual says that a CASE statement (the WHEN part) can contain a

  • 0

the MySQL manual says that a CASE statement (the WHEN part) can contain a statement_list.

How much statement is that to be exact? I need to perform a pretty big query which I would like to parametrize. However this also implies that I need to change tables that are being joined. I’ve read that this cannot be done using CASE statements, so I’m looking for a solution to not have to re-create the stored procedure for every parameter value that there is…

UPDATE
I tried to solve it using a CURSOR. I have defined a CURSOR for every object I have. I would like to use IF-ELSE-statements to choose which cursor to open, loop and close. However I cannot get the syntax right…

All cursors and variables (usb, obj, mm, stamp) are declared with different names, but I’ve shortened them for reading….

if OBJECTTYPE = 1 then
open CUR_1_BUILDING;
LOOP1: loop
    fetch CUR_1_BUILDING into usb, obj, mm, stamp;
    if no_more_rows then
        close CUR_1_BUILDING;
        leave loop1;
    end if;
    INSERT INTO ObjectCache (usb, obj, mm, date_checked) VALUES (usb, obj, mm, now());
end loop LOOP1;
    CLOSE CUR_1_BUILDING;
else if OBJECTTYPE = 2 then
open CUR_2_CITY;
LOOP2: loop
    fetch CUR_2_CITY into usb, obj, mm, stamp;
    if no_more_rows then
        close CUR_2_CITY;
        leave loop2;
    end if;
    INSERT INTO ObjectCache (usb, obj, mm, date_checked) VALUES (usb, obj, mm, now());
end loop LOOP2;
    close CUR_2_CITY;
end if;

Is this is any way possible to do using CASE statements?

BEGIN
    CASE
        when OBJECTTYPE = 1
            INSERT INTO ObjectCache SELECT id FROM Building
        when OBJECTTYPE = 2
            INSERT INTO ObjectCache SELECT id FROM City
    END CASE;
END
  • 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-12T17:39:07+00:00Added an answer on May 12, 2026 at 5:39 pm

    You could use IF ELSE or you could build and execute dynamic SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The mysql manual says that SET NAMES 'x' is equivalent to SET character_set_client =
It says in MySQL 5.6 manual that: Values for DECIMAL (and NUMERIC) columns are
On the manual page; http://dev.mysql.com/doc/refman/5.0/en/mysql-insert-id.html It is said that Returns the value generated for
I have an incredibly simple query (table type InnoDb) and EXPLAIN says that MySQL
i need to perform an operation (in this case DATEDIFF()) on 2 dates. But
The MySQL manual (http://dev.mysql.com/doc/refman/5.1/en/charset-syntax.html) says: There are default settings for character sets and collations
Quoting MySQL INSERT manual - same goes for UPDATE: Use the keyword DEFAULT to
Problem: To read MySQL's manual effectively Error: mysql> create database plastronics -> ; ERROR
This question is based on this thread . Problem: to access MySQL's manual when
I wasn't able to find out (googling, reading mysql reference manual) how to get

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.