Retrieving the data from the table using the PL/SQL

前端 未结 1 369
粉色の甜心
粉色の甜心 2021-01-26 16:00

I want to retrieve all the information about each department from the DEPARTMENT table and display the information on the screen.

Column name      Data type     C         


        
相关标签:
1条回答
  • 2021-01-26 16:30

    Yes, a simple way to do that is to use a loop. But, you're looping through nothing (never fetch anything into those variables) and never exit the loop. Besides, what exactly are you committing?

    Here's how you might have done it (based on Scott's DEPT table which is similar to yours):

    SQL> set serveroutput on
    SQL> begin
      2    for cur_r in (select deptno, dname, loc from dept) loop
      3      dbms_output.put_line(cur_r.deptno ||' '|| cur_r.dname ||' '|| cur_r.loc);
      4    end loop;
      5  end;
      6  /
    10 ACCOUNTING NEW YORK
    20 RESEARCH DALLAS
    30 SALES CHICAGO
    40 OPERATIONS BOSTON
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
    0 讨论(0)
提交回复
热议问题