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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:28:14+00:00 2026-05-28T06:28:14+00:00

Suppose I have a table abc with columns p_id , u_id , and comments

  • 0

Suppose I have a table abc with columns p_id ,u_id, and comments. I want to fetch the data from this table only if there are multiple rows for a particular p_id value (there is a single row of “junk” data in the table for every p_id that I want to ignore). How can I structure my query so that I can determine whether there are multiple rows for a p_id without fetching the data from the cursor.

Currently, my code looks something like this

Declare
  Cursor pqr is 
  Select p_id,u_id,comments from abc where p_id=123;
Begin

--I want to ignore the results if this query returns 0 or 1 row.
--I only want to process the data if this query returns multiple rows

End;
  • 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-05-28T06:28:15+00:00Added an answer on May 28, 2026 at 6:28 am

    You can add an analytic COUNT to your query so that the number of rows in the result set will be available in each row that you fetch from the cursor

    Declare
      Cursor pqr is 
       select p_id,u_id,comments
         from (Select p_id,u_id,comments,count(*) over () cnt
                 from abc 
                where p_id=123)
        where cnt > 1;
    Begin
    

    The probably doesn’t buy you much, if any, performance, however. You’re forcing Oracle to materialize the entire result set in order to count the number of rows which is likely to make the code slower. You’re also adding another column to every row in the result set which will increase memory usage. And you still have to fetch the first row in order to access the CNT column.

    What is the business problem you are trying to solve that requires that you know how many rows are going to be fetched before you fetch all the rows? That isn’t something that is commonly needed so perhaps there is a better way to solve whatever problem you’re facing.

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

Sidebar

Related Questions

Suppose I have a table called 'test', into which there are three columns named
Suppose I have this table [Table1] Name Mark ------- ------ ABC 10 DEF 10
Suppose I have table with two columns. I can center this table by using:
Suppose I have table Person table Employee, which inherits Person. I want to get
Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose I have a table . Now, I'm interested in Getting Useful Data Easily.
Suppose I have a tags table with two columns: tagid and contentid . Each
Suppose I have a table with full-text index on column Firstname, lastname, email. There
Suppose I have a table like so: <table> <tr><td class=this-is-a-label>Label Cell</td></tr> <tr><td>Detail 1</td></tr> <tr><td
Suppose I have a table that contains valid data. I would like to modify

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.