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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:47:53+00:00 2026-06-12T09:47:53+00:00

I have a table CREATE TABLE STUDENT ( ID INTEGER PRIMARY KEY, FIRSTNAME VARCHAR2(1024

  • 0

I have a table

CREATE TABLE STUDENT
(
  ID            INTEGER PRIMARY KEY,
  FIRSTNAME     VARCHAR2(1024 CHAR),
  LASTNAME      VARCHAR2(1024 CHAR),
  MODIFIEDDATE  DATE  DEFAULT sysdate
)

I am inserting a row of data

insert into STUDENT (ID, FIRSTNAME, LASTNAME, MODIFIEDDATE)  values (1,'Scott', 'Tiger', sysdate);

When I have to insert a record of data, I need to write a procedure or function which does the following:

  1. if there is no record for the same id insert the row.
  2. if there is a record for the same id and data matches then do nothing.
  3. if there is a record for the same id but data does not match then update the data.

I am new to oracle. From the java end, It is possible to select the record by id and then update that record, but that would make 2 database calls. just to avoid that I am trying update the table using a procedure. If the same can be done in a single database call please mention.

  • 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-12T09:47:54+00:00Added an answer on June 12, 2026 at 9:47 am

    For a single SQL statement solution, you can try to use the MERGE statement, as described in this answer https://stackoverflow.com/a/237328/176569

    e.g.

    create or replace procedure insert_or_update_student(
    p_id number, p_firstname varchar2, p_lastname varchar2
    ) as
    begin
        merge into student st using dual on (id = p_id)
             when not matched then insert (id, firstname, lastname) 
               values (p_id, p_firstname, p_lastname)
             when matched then update set 
               firstname = p_firstname, lastname = p_lastname, modifiedate = SYSDATE
    end insert_or_update_student;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For exmple i have two tables A create table teachers( id number(4) primary key,
I have three tables. The designs were like student table create table student (studID
i have this table create table eveniment( + evenimentId bigint not null auto_increment primary
I have a table that looks something like this: CREATE TABLE student_results(id integer, name
Let's say I have this: CREATE TABLE `classes` ( `class_ID` INT AUTO_INCREMENT, FOREIGN KEY
I have a table contains bus and student sign up information: CREATE TABLE [dbo].[BusSignupInstance](
I have a table: CREATE TABLE siteConfig ( settingName VARCHAR(64) NOT NULL, value VARCHAR(255),
I have a table CREATE TABLE `messages` ( `uid` BIGINT NOT NULL , `mid`
I have a table Create table Country_State_Mapping ( Country nvarchar(max), State nvarchar(max) ) With
I have a table: create table Transactions(Tid int, amt int) With 5 rows: insert

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.