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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:07:33+00:00 2026-06-17T20:07:33+00:00

The following PL/SQL successfully executes as expected: declare myCount number; begin select count(*) into

  • 0

The following PL/SQL successfully executes as expected:

declare
    myCount number;
begin
    select count(*)
    into myCount
    from myTable
    where id = 1;
end;

However, the following does not and instead throws this error:

ORA-01422: exact fetch returns more than requested number of rows

declare
    myCount number;
    myId number := 1;
begin
    select count(*)
    into myCount
    from myTable
    where id = myId;
end;

Conceptually, I understand what the error means, but I don’t know how it applies to my situation. All I’ve done is moved the hardcoded value to a variable in the declare block. Why would that affect the results of the select when it’s the exact same number?

Version is Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production.

  • 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-17T20:07:35+00:00Added an answer on June 17, 2026 at 8:07 pm

    There is something going on in your system that you haven’t reproduced in this question. If I create a table myTable in my local system, your code runs without error

    SQL> create table myTable( id number );
    
    Table created.
    
    SQL> declare
      2      myCount number;
      3      myId number := 1;
      4  begin
      5      select count(*)
      6      into myCount
      7      from myTable
      8      where id = myId;
      9  end;
     10  /
    
    PL/SQL procedure successfully completed.
    

    Is it possible that there is some difference between the code you’ve posted and the code that you’re actually running?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following SQL statementL: select DATE(bla), count(*) from tableA group by DATE(bla) UNION
I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I am successfully executing the following query in SQL Server 2008 built into VS2008:
I have the following SQL Server query: SELECT area FROM places WHERE REPLACE(area,'-',' ')
How can I fix this error in T-SQL? The following line executes successfully: SET
I have the following SQL statement: SELECT 420, DueDate, ISNULL(Amount, 0) FROM Payments WHERE
I have the following SQL statement: USE ws_results_db_2011_09_11_09_06_24;SELECT table_name FROM INFORMATION_SCHEMA.Tables WHERE table_name like
The following SQL Lite statement in Trac SELECT id, changetime / 1000000 as 'MODIFIED',
The following sql will return a count of how many users have played a
I have the following SQL snippet within a select statement: CASE WHEN wot.id LIKE

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.