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

  • Home
  • SEARCH
  • 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 6646371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:24:30+00:00 2026-05-26T00:24:30+00:00

I’m just learning plsql and I’m having problems running simple sql queries in procedures.

  • 0

I’m just learning plsql and I’m having problems running simple sql queries in procedures.
I wanted to write a procedure that displays all the records from a table.

create or replace procedure display_all_students
as
    begin
        dbms_output.put_line('Listing all the student records');
        select * from student;
    end;

I get this as a result :
Warning: Procedure created with compilation errors.

What am I missing, from what I understand is that plsql is an extension to sql is there some other way of achieving this instead?

Updated code, I’m still facing the same problem. Is there a way by which we can debug these errors one by one?

-- procedure to display the table
create or replace procedure display_all_students
as
  -- declarations
  cursor cur_student is
    select * from student;
  student_record student%rowtype;
 begin
    dbms_output.put_line('Listing all the student records');
    for student_record in cur_student
    loop
      dbms_output.put_line(student_record);
    end loop;
  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-26T00:24:31+00:00Added an answer on May 26, 2026 at 12:24 am

    You cannot just select * from student;. That doesn’t mean anything, what does it do with the returned data?

    Instead you need to either create a cursor which selects ... from student or SELECT columns INTO variables FROM student;.

    So for you problem you need to create a cursor which selects from student and then loop through it and output each row. For example:

    create or replace procedure display_all_students
    as
        CURSOR cur_student IS
        SELECT student_id, first_name, last_name FROM student;    
    begin
        dbms_output.put_line('Listing all the student records');
        FOR rec IN cur_student
        LOOP
            dbms_output.put_line( 'ID[' || rec.student_id || '] Name: '
                || rec.first_name || ' ' rec.last_name);
        END LOOP;
    end;
    

    The same thing written the long way is probably better to learn as a beginner as it teaches you the various aspects of cursors etc. This is the same code written the long way.

    create or replace procedure display_all_students
    as
        CURSOR cur_student IS
        SELECT student_id, first_name, last_name FROM student;    
        -- Host Variable to store cursor result.
        rec cur_student%ROWTYPE;
    begin
        dbms_output.put_line('Listing all the student records');
        OPEN cur_student;
        LOOP
            FETCH cur_student INTO rec;
            EXIT WHEN cur_student%NOTFOUND;
            dbms_output.put_line( 'ID[' || rec.student_id || '] Name: '
                || rec.first_name || ' ' rec.last_name);
        END LOOP;
        CLOSE cur_student;
    end;
    

    The FOR variable IN cursor syntax takes care of some things for you:

    • You don’t have to decalre the Host Variable
    • You don’t have to OPEN the cursor
    • You don’t have to check when you’ve reached the end of the data
    • You don’t have to CLOSE the cursor

    The difference is syntax only. The actual execution and performance of both is almost identical.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

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.