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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:37:39+00:00 2026-06-16T03:37:39+00:00

I am trying to write a procedure to check if parameters given (dates) lie

  • 0

I am trying to write a procedure to check if parameters given (dates) lie between any of the existing dates in the table. And if not insert new row.

CREATE OR REPLACE PROCEDURE test(date1 IN DATE, date2 IN DATE) AS 
  ddate1 DATE;
  ddate2 DATE;
  quer VARCHAR2(50);
BEGIN 
  SELECT fdate, tdate INTO ddate1, ddate2 FROM dataHolder; 
  IF (ddate1 < date1) AND (ddate2 > date2) THEN
    quer := 'invalid'; 
  ELSE 
    INSERT INTO dataHolder VALUES (date1, date2);
    quer := 'success';
  END IF; 
  DBMS_OUTPUT.PUT_LINE(quer); 
END;
/

I have tried something like this but when executed I get this error:

ORA-01422: exact fetch returns more than requested number of rows
  • 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-16T03:37:40+00:00Added an answer on June 16, 2026 at 3:37 am

    You are getting that error because your select statement returns more than one record. To simplify the process you could use merge statement and rewrite your procedure as follows:

    CREATE OR REPLACE PROCEDURE test(date1 IN DATE, date2 IN DATE) AS
    BEGIN
      merge into Dataholder dh
      using dual
         on ((date1 < dh.fdate) and (date2 < dh.tdate))
      when not matched then
        insert (dh.fdate, dh.tdate)
          values(date1, date2);
      if sql%rowcount > 0
      then
        dbms_output.put_line('success');
      else
        dbms_output.put_line('invalid');
      end if;
    END; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new stored procedures and trying to write a procedure to duplicate user(by
I am trying to write a stored procedure that takes a table name as
I am new to SQL and trying to write a stored procedure. I am
Trying to write a procedure that given a value and a list, it deletes
I'm trying to write a stored procedure that will create a new FILEGROUP based
I'm fairly new to SQL and was trying to write a procedure that would
I am trying to write a stored procedure that will check for the existence
I am trying to write a procedure to drop the Unique constraints from any
I'm trying to write a stored procedure in which I insert a few things
i am trying to write a procedure that inserts rows into a temp table.

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.