Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to access sql table records in PL/SQL

Re: How to access sql table records in PL/SQL

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Wed, 5 Apr 2000 21:26:48 +0200
Message-ID: <954963387.4766.0.pluto.d4ee154e@news.demon.nl>


A select into can retrieve only one row. You'll need a cursor like this:

 Declare
 cursor cEmployee is
 select FirstName

         , LastName
         , Salary

 from emp;
 rEmployee cEmployee%ROWTYPE; -- this binds the record to the cursor, whenever the table changes the rest is adjusted automatically.  Begin
 --Employee is table name & FirstName, LastName, Salary are the fields of the table

for rEmployee in cEmployee loop

    dbms_output.put_line(rEmployee.LastName || ' ' || rEmployee.FirstName || ' ' || rEmployee.Salary);
end loop;

 End;
 /

Hth,

Sybrand Bakker, Oracle DBA

News <JadhavR_at_automationc.com> wrote in message news:8ILG4.141$k5.63930_at_news.abs.net...
> I am a new Oracle user. I want to display the SQL table records in PL/SQL
> procedure. For which I'm using following
>
> Declare
> v_FirstName varchar2(15);
> v_LastName varchar2(15);
> v_Salary number;
>
> Begin
> --Employee is table name & FirstName, LastName, Salary are the fields of
the
> table
>
> select FirstName, LastName, Salary into v_FirstName, v_LastName, v_Salary
> from employee;
>
> dbms_output.put_line(v_LastName || ' ' || v_FirstName || ' ' || v_Salary);
>
> End;
> /
>
> I have multiple records in the employee table. When I run the program I
get
> error multiple records found.
> If anybody knows, Please let me know.
>
> Thanking in advance.
>
> Rajashri Jadhav
>
>
Received on Wed Apr 05 2000 - 14:26:48 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US