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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:43:41+00:00 2026-06-05T23:43:41+00:00

Is this the safest/optimal code for a simple does the record exist question: .

  • 0

Is this the safest/optimal code for a simple “does the record exist” question:

. . . // "oc" is an OracleConnection component
const string sql = "SELECT COUNT(*) FROM CONGRESS WHERE IQ > WEIGHT"; //Most politicians have more pounds than sense
try {
    using (OracleCommand ocmd = new OracleCommand(sql, oc)) {
        return Convert.ToInt32(ocmd.ExecuteScalar()) > 0;
    }
. . . // the rest elided to spare the vertical scroll-bar bearings

?

  • 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-05T23:43:44+00:00Added an answer on June 5, 2026 at 11:43 pm

    Something like

    SELECT 1
      FROM dual
     WHERE EXISTS( SELECT 1
                     FROM congress
                    WHERE iq > weight )
    

    is probably the safest option since that allows Oracle to stop executing the query as soon as one matching row is found rather than scanning the entire table to get an accurate count. Something like

    SELECT COUNT(*) 
      FROM congress
     WHERE iq > weight
       AND rownum <= 1
    

    should do the same thing as well. In my mind, the first query is more expressive of your intent but it’s also a bit more verbose.

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

Sidebar

Related Questions

This is probably a very simple question for somebody with experience, but I just
This somehow simple task is not so simple. I can get the number of
This should be simple, but the answer is eluding me. If I've got a
this is my code that I write it but I want to use LINQ
This is probably a stupid question, but how much of a security risk is
This is a complex question, because there are a lot of moving parts. My
This is related to this question I asked earlier about syntax highlighting user-defined blocks
This is a pretty specific question, albeit possibly subjective, but I've been using this
what's the safest way to integrate multi-currency support to Ubercart ? I found this
This is a basic question about what options are available for defining the scope

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.