Re: Inserting using existing row data

From: Graeme Sargent <graeme_at_pyra.co.uk>
Date: Fri, 16 Jul 1993 11:42:22 GMT
Message-ID: <1993Jul16.114222.9179_at_pyra.co.uk>


In <223non$b9c_at_spock.dis.cccd.edu> paulk_at_spock.dis.cccd.edu (Paul Krikorian) writes:

>Example:
 

> table_a
> -------
> key_col
> col_1
> col_2
> ...
> col_n

>Normally, to insert a new row (with say key_col = 2) using all the columns
>from another row (with say key_col = 1), I could perform the following:
 

>INSERT INTO table_a
>SELECT 2,col_1,col_2,...,col_n FROM table_a WHERE key_col = 1
 

>Is it possible to perform this type of statement without having to
>specify 'col_1,col_2,...,col_n', but using something generic to
>represent them?
 

>I am writing a PRO*COBOL application and will have to perform this type
>of function on about 30 tables and I would really like not to have to
>maintain all those column names (or even type them out in the first
>place!).
 

>Any suggestions or am I just dreaming?

How about:

EXEC SQL EXECUTE
    DECLARE
        arec table_a%ROWTYPE;
    BEGIN

	SELECT * INTO arec FROM table_a WHERE key_col=1;
	arec.key_col := 2;
	INSERT INTO table_a VALUES (arec);

    END;
END EXEC; This is, of course, less efficient than hand-coding the INSERT statement.

graeme

--
Disclaimer:	The author's opinions are his own, and not necessarily
		those of Pyramid Technology Ltd. or Pyramid Technology Inc.
---------------------------------------------------------------------------
      -m------- Graeme Sargent                 Voice: +44 (0)252 373035
    ---mmm----- Senior Database Consultant     Fax  : +44 (0)252 373135
  -----mmmmm--- Pyramid Technology Ltd.        Telex: Tell who???
-------mmmmmmm- Farnborough, Hants  GU14 7PL   Email: graeme_at_pyra.co.uk
---------------------------------------------------------------------------
    We have the technology.  The tricky bit is learning how to use it.
Received on Fri Jul 16 1993 - 13:42:22 CEST

Original text of this message