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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:01:50+00:00 2026-06-15T04:01:50+00:00

I want to use the function SQL%ROWCOUNT as a way to tell me if

  • 0

I want to use the function SQL%ROWCOUNT as a way to tell me if a record is in a table or not.
The code that I have is the following:

DECLARE
v_emp employee%ROWTYPE; 
CURSOR c_emp IS
SELECT * FROM employee WHERE name='chuck';
BEGIN
OPEN c_emp;

    FETCH c_emp INTO v_emp;
    IF SQL%ROWCOUNT=1 THEN
             DBMS_OUTPUT.PUT_LINE('found');
            ELSE
                     DBMS_OUTPUT.PUT_LINE(TO_CHAR('not found'));
        END IF;
END;

But it does not print anything at all, even though that record with that name exists in the database

  • 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-15T04:01:51+00:00Added an answer on June 15, 2026 at 4:01 am

    Normally, you’d do something like

    DECLARE
      l_count PLS_INTEGER;
    BEGIN
      SELECT COUNT(*)
        INTO l_count
        FROM employee
       WHERE name = 'chuck'
         AND rownum = 1;
    
      IF( l_count = 1 )
      THEN
        dbms_output.put_line( 'found' );
      ELSE
        dbms_output.put_line( 'not found' );
      END IF;
    END;
    

    If you really want to use an explicit cursor, you would need to check the <<cursor_name>>%rowcount, not sql%rowcount to determine how many rows had been fetched. If you’re going to use an explicit cursor, you also need to take care to close the cursor. Since you didn’t post your table definition or the data you’re using, I’ll use the EMP table in the SCOTT schema as an example

    SQL> ed
    Wrote file afiedt.buf
    
      1  DECLARE
      2    v_emp emp%ROWTYPE;
      3    CURSOR c_emp IS
      4      SELECT * FROM emp WHERE ename='SMITH';
      5  BEGIN
      6    OPEN c_emp;
      7    FETCH c_emp INTO v_emp;
      8    IF c_emp%ROWCOUNT=1 THEN
      9      DBMS_OUTPUT.PUT_LINE('found');
     10    ELSE
     11      DBMS_OUTPUT.PUT_LINE(TO_CHAR('not found'));
     12    END IF;
     13    CLOSE c_emp;
     14* END;
    SQL> /
    found
    
    PL/SQL procedure successfully completed.
    

    And note that no matter what approach you use, if you want the output from DBMS_OUTPUT to be displayed, you need to enable output in whatever tool you are using. If you are using SQL*Plus, that would mean running

    SQL> set serveroutput on;
    

    before executing the anonymous PL/SQL block.

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

Sidebar

Related Questions

I want to use CLR table-valued function in SQL Server 2008, which accesses a
I want to use magic function __set() and __get() for storing SQL data inside
i want to use .animate function but i have some problems i want to
I have following query in sql server 2005 with a table select t1.id, CONVERT(VARCHAR,t1.dt,103)
I found this SQL function that iterates over the table and it finds the
I want to use the AVG function in sql to return a working average
I'm new to the Entity Framework. I have a SQL Function that returns the
Need help with Min Function in SQL I have a table as shown below.
I want to use the fallowing function in my SQL-Server: CREATE FUNCTION RTF2TXT(@in varchar(8000))
I want use javascript setInterval function to achieve a box rotate animate effect, I

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.