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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:40:11+00:00 2026-06-17T15:40:11+00:00

Issue desc: Need to match and update new desc(if different) production table from a

  • 0

Issue desc: Need to match and update new desc(if different) production table from a flat file. Have imported flat file in temptable.

sample from prod table:
[mstr_plan]

char(5)    varchar2(30) char(3)
PLAN_CODE PLAN_DESC FIN_CLUSTER
BB123     Plan_desc3 Z01
BB124     Plan_desc4 Z02
BB125     Plan_desc5 Z02
BB126     Plan_desc6 Z03
BB127     Plan_desc7 Z04
BB128     Plan_desc8 Z06
<about 500 records>

tmptbl01 <new records from flat file)
PLAN_CODE PLAN_DESC    FIN_CLUSTER
BB123     Plan_desc3    Z01
BB124     Plan_desc4    Z02
BB125     Plan_desc51   Z02
BB126     Plan_desc61   Z03
BB127     Plan_desc7    Z04
BB128     Plan_desc81   Z06
<about 150 records>

Select query :

select * from mstr_plan, tmptbl01
where mstr_plan.plan_code = tmptbl01.plan_code and 
(mstr_plan.PLAN_DESC <> tmptbl01.PLAN_DESC or
mstr_plan.FIN_CLUSTER <> tmptbl01.FIN_CLUSTER);

<in my database with 500 & 150 rows it returns 17 rows>
<in sample should return 3 rows>
PLAN_CODE PLAN_DESC    FIN_CLUSTER
BB125     Plan_desc51   Z02
BB126     Plan_desc61   Z03
BB128     Plan_desc81   Z06

There are no changes in FIN_CLUSTER. So, took it out from update query.

UPDATE mstr_plan 
SET mstr_plan.PLAN_DESC = 
(select tmptbl01.plan_desc from mstr_plan, tmptbl01 where mstr_plan.plan_code=
 tmptbl01.plan_plan_code and mstr_plan.plan_desc <> mstr_plan.plan_desc )

where mstr_plan.PLAN_DESC = <or IN>
(select tmptbl01.plan_desc from mstr_plan, tmptbl01 where mstr_plan.plan_code=
 tmptbl01.plan_plan_code and mstr_plan.plan_desc <> mstr_plan.plan_desc )

returns ORA-01427: single-row subquery returns more than one row

Methods:
<1> Manually update 17 records one by one
<2> Read about a crude method to ‘and where with rownum = 1’. Didn’t try yet.

Please recommend me better method.

  • 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-17T15:40:12+00:00Added an answer on June 17, 2026 at 3:40 pm

    The error is because you have placed mstr_plan table inside the subqueries.

    Even if you corrected that though, none of your UPDATE statements would work because they include and mstr_plan.plan_desc <> mstr_plan.plan_desc in the WHERE clause, making it always false.

    It’s usually better to use a variation of the SELECT you already have and correctly finds the rows to be updated. You only need to select only the column(s) to be updated and the new values and then update this derived table:

    UPDATE 
        ( SELECT mstr_plan.plan_desc 
               , tmptbl01.plan_desc AS new_plan_desc 
          FROM mstr_plan 
            JOIN tmptbl01 
              ON mstr_plan.plan_code = tmptbl01.plan_code 
          WHERE mstr_plan.plan_desc <> tmptbl01.plan_desc  
        ) 
    SET plan_desc = new_plan_desc ;
    

    This way you have less chances of updating wrong rows in case you make a mistake in the code (if your WHERE was always true instead of always false you might have updated all the rows in your mstr_plan table, possibly placing some NULL values in the (500-17) rows that shouldn’t be updated.

    You can also use aliases to make it more readable:

    UPDATE 
        ( SELECT m.plan_desc 
               , t.plan_desc AS new_plan_desc 
          FROM mstr_plan  m
            JOIN tmptbl01  t
              ON m.plan_code = t.plan_code 
          WHERE m.plan_desc <> t.plan_desc  
        ) 
    SET plan_desc = new_plan_desc ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help to solve my issue. I have a table like this one,
I have an issue in writing fixed width text file using php and data
Issue - We have a spreadsheet with thousands of addresses but no counties. Goal
I have following complex query which I need to use. When I run it,
I'm new to Java, Android, and SQLite, and I'm stuck at this. I have
I have the following problem I have 3 table (all of the are used
Here's the issue in verbose mode. I have instances of certifications on a certification
I have been working on a CodeIgniter project and hav run into an issue
I struggling with a problem I have in TSQL, I need to get the
I have a co-worker who is working on a table with an 'amount' column.

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.