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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:47:42+00:00 2026-06-04T09:47:42+00:00

I have (simplified for this question) a table ‘TAB’ with two columns ‘id’ (integer

  • 0

I have (simplified for this question) a table ‘TAB’ with two columns ‘id’ (integer and not null in db) and ‘value’ (varchar and not null in db). I am using a java application to update ‘value’ column for multiple rows in one go (which is my requirement). I have used update statement with case and when keyword. The query is being generated at runtime depending on number of rows modified.

The query works fine if data is updated for all rows together, but it gives me error when updated for less rows. Say we have three rows with id = 1, 2 and 3 with values A ,B and C resp.
When the query is fired for all three rows together then it works fine

UPDATE 
     TAB set value = CASE 
       WHEN id = 1 THEN 'X' WHEN id = 2 THEN 'Y' WHEN id = 3 THEN 'Z' 
END

But when the query is fired for less than three rows then I am encountering with a DB error.

UPDATE TAB set value = CASE WHEN id = 1 THEN 'X' END

Results in following error:

DB Error=ORA-01407: cannot update (“XXX”.”XXX”.”VALUE”) to NULL.

I know this is happening because the ‘value’ column is not null in DB. I want to know whether the above query is trying to update all the remaining values with NULL?

The query works fine if I add ELSE part as written below.

UPDATE TAB set value = CASE WHEN id = 1 THEN 'X' ELSE TAB.value END

Will the above query impact any performance issue, if there are multiple rows in 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-06-04T09:47:43+00:00Added an answer on June 4, 2026 at 9:47 am

    The way you are doing this is perfectly fine.

    UPDATE TAB set value = CASE WHEN id = 1 THEN 'X' ELSE TAB.value END
    

    other solution could be using where clause

    UPDATE TAB set value = CASE WHEN id = 1 THEN 'X' when ID = 2 then 'Y' END where id in ( 1, 2 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database with two tables (simplified for this question): movies table
I have the following two tables (simplified for this question): CREATE TABLE team (
I have the following table users (simplified for the purposes of this question) with
This is heavily simplified for the sake of the question. Say I have a
I have a table like this (simplified): ID | Name | Parent --------------------------------- 1
Imagine that we have two tables as follows: Trades ( TradeRef INT NOT NULL,
I have the following 4 tables (simplified for this question): Company CompanyId | Name
This is a more theoretical question, not a specific scenario: Let's assume, we have
I have a table that simplified looks like this: create table Test ( ValidFrom
I have a table whose header looks like this (I've simplified it): id, a1,

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.