Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oracle and table variables, how well are they handled?

Status
Not open for further replies.

Maim

Programmer
Jun 25, 1999
106
CA
I usually write my procedures in SQL Server 2000 but I need to start writing them for Oracle and DB2. One issue that concerns me is how table variables are handled by Oracle.

For example;
Code:
DECLARE @myTable(
   f1 integer,
   f2 varchar(256),
   f3 smallint)
INSERT INTO @myTable
SELECT ... a whole bunch of records ...

SELECT * FROM @myTable

Would the above be possible in Oracle 8+?
I haven't installed Oracle on my machine yet, so I don't have any documentation to verify this.

Thanks in advance :D
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rich Cook
 
Hi D,

Welcome to the world of ANSI standards (not)

As no-one has answered yet, the way it is done in Oracle is:

CREATE TABLE @myTable
(
f1 NUMBER, --NUMBER covers a multitude of types
f2 VARCHAR2(256),
f3 NUMBER
)
/ --execute statement!!

INSERT INTO @myTable
VALUES
(
..
);
/

/*Unfortunately you can only insert one line at a time using this method*/

SELECT * FROM @myTable
/

Good luck with Oracle

[bomb]
 
thanks for your answer. Only one record at a time hunh?

I'd still need to use a cursor to traverse all the records and insert them into the table variable... or am I still thinking like a newbie? "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rich Cook
 
YOu can insert multiple recored at one tme as you had mentioned before.

INSERT INTO @myTable
SELECT ... a whole bunch of records ...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top