PL/SQL ... Anybody?

Discuss all aspects of programming here.

Moderator: The Mod Squad

PL/SQL ... Anybody?

Postby chrisostomos » Mon Nov 28, 2005 11:21 pm

Hi

Im trying to learn some PL/SQL here and I was just wondering if anyone knew how to save the result of a query into a variable.
For example

SELECT userName FROM userTable WHERE userID = 1;

and save that into a variable called user_name

Thanks
Chris Drogaris
chrisostomos
Initiate
Initiate
 
Posts: 79
Joined: Fri Jan 23, 2004 11:13 pm

Postby Toby B. » Mon Nov 28, 2005 11:47 pm

Google is a wonderful tool.... :P

PL/SQL Tutorials
http://www.ilook.fsnet.co.uk/ora_sql/sqlmain2.htm
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby Roach412 » Tue Nov 29, 2005 1:36 pm

ooooyeah...this is my job. =)

SELECT userName
into user_name
FROM userTable
WHERE userID = 1;

it's actually better to use cursors, and you'll definitely want to look into those as early as you can, it makes things VERY easy later on :wink: :

Code: Select all
declare
v_user_name varchar2(20);
cursor userName is
SELECT userName
FROM userTable
WHERE userID = 1;

begin
open userName;
fetch userName into v_user_name;
close userName;
dbms_output.put_line('User name is: ' || v_user_name);

end;
/


-Roach
Lian Li Lancool First Knight Series PC-K59W
Intel Core i7-960 Bloomfield 3.2GHz
EVGA X58 FTW3 132-GT-E768-TR
EVGA GeForce GTX 1070 FTW GAMING ACX 3.0
G.SKILL Ripjaws Series 12GB (3 x 4GB)
Crucial M4 128gb SATAIII SSD x2
Crucial M4 256gb SATAIII SSD
OCZ Saber 1000 960GB Enterprise SSD
Corsair Professional Series HX850 PSU
Dell UltraSharp U2713HM 27" w/drop ceiling mount
Logitech G930 7.1 Headset
DBPOWER RGB LED Keyboard
Logitech G402 Hyperion Fury
Roach412
Black Belt 2nd Degree
Black Belt 2nd Degree
 
Posts: 2714
Joined: Mon Aug 09, 2004 7:33 pm
Location: Milwaukee - Wisconsin


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest