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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:54:19+00:00 2026-05-10T15:54:19+00:00

I have a rather weak understanding of any of oracle’s more advanced functionality but

  • 0

I have a rather weak understanding of any of oracle’s more advanced functionality but this should I think be possible.

Say I have a table with the following schema:

MyTable   Id INTEGER,   Col1 VARCHAR2(100),   Col2 VARCHAR2(100) 

I would like to write an sproc with the following

PROCEDURE InsertOrUpdateMyTable(p_id in integer, p_col1 in varcahr2, p_col2 in varchar2) 

Which, in the case of an update will, if the value in p_col1, p_col2 is null will not overwrite Col1, Col2 respectively

So If I have a record:

id=123, Col1='ABC', Col2='DEF'  exec InsertOrUpdateMyTable(123, 'XYZ', '098'); --results in id=123, Col1='XYZ', Col2='098' exec InsertOrUpdateMyTable(123, NULL, '098');  --results in id=123, Col1='ABC', Col2='098' exec InsertOrUpdateMyTable(123, NULL, NULL);   --results in id=123, Col1='ABC', Col2='DEF' 

Is there any simple way of doing this without having multiple SQL statements?

I am thinking there might be a way to do this with the Merge statement though I am only mildly familiar with it.


EDIT: Cade Roux bellow suggests using COALESCE which works great! Here are some examples of using the coalesce kewyord. And here is the solution for my problem:

MERGE INTO MyTable mt     USING (SELECT 1 FROM   DUAL) a     ON (mt.ID = p_id)     WHEN MATCHED THEN         UPDATE            SET mt.Col1 = coalesce(p_col1, mt.Col1), mt.Col2 = coalesce(p_col2, mt.Col2)     WHEN NOT MATCHED THEN         INSERT (ID, Col1, Col2)         VALUES (p_id, p_col1, p_col2); 
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T15:54:20+00:00Added an answer on May 10, 2026 at 3:54 pm

    Using MERGE and COALESCE? Try this link for an example

    with

    SET a.Col1 = COALESCE(incoming.Col1, a.Col1)     ,a.Col2 = COALESCE(incoming.Col2, a.Col2) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather mundane Oracle table with seven rows. Each row has different
I have rather simple, I imagine, question about CRTP , but I cannot seem
Have a (rather complex) app that works fine on iOS 4 but fails on
I have a rather large(not too large but possibly 50+) set of conditions that
I have rather big form where a user can choose any number of parameters
I have rather a very basic question but somehow it is confusing to me.
I'm using acts_as_taggable_on, but now have a new requirement: The end goal: Users should
I have rather unusual problem. It is hard to explain, so this is address
I have rather large project that uses ICU regex classes. Basically it might run
Have a rather simple question. Does anyone knows if i can use jparallax both

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.