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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT INTO with UNION

Status
Not open for further replies.

szeiss

Programmer
Apr 5, 2000
137
US
Is it possible to use a SELECT INTO clause with a UNION?

SELECT
table1.COLUMN
INTO v_column
FROM
TABLE1
WHERE
.....
UNION
SELECT
table2.COLUMN
INTO v_column
FROM
TABLE2
WHERE
.....

I get the following error ORA-01744:, inappropriate INTO

I want to insert v_column into a table

Thanks,
Sherry
 
You could do it by means of an inline view:

DECLARE
v_column number;
BEGIN
select col1
into v_column
from
(SELECT
1 as col1
FROM DUAL
UNION
SELECT 2 as col2
FROM DUAL);
END;

The code fragment also illustrates the problem with your whole approach. SELECT..INTO will only ever allow a single row to be returned but a UNION, by its nature, is likely to return more than one. You need to look at using a CURSOR instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top