how to direct select output to insert input

Bill Davidson harley7
Mon May 17 11:45:59 PDT 2004


On Thu, 27 Mar 2003 19:44:50 -0800
"Net Llama!" <netllama at linux-sxs.org> wrote:

> On 03/27/03 19:37, Bill Davidson wrote:
> > On Thu, 27 Mar 2003 19:11:37 -0800
> > "Net Llama!" <netllama at linux-sxs.org> wrote:
> > 
> >> On 03/27/03 19:10, Bill Davidson wrote:
> >> > On Thu, 27 Mar 2003 17:45:33 -0800
> >> > "Net Llama!" <netllama at linux-sxs.org> wrote:
> >> > 
> >> >> i've got an Oracle (9i, if that matters) problem.  i need to
> >> >> essentially copy all the data from a single column (call it a)
> >in a> >> table into a different column (call it b) in the same table.
> > both
> >> >a> and b are the same datatype, and b is currently empty.  i've
> >tried> >the> following, but it fails:
> >> >> insert into table_foo (b) values ((select a from table_foo));
> >> >> 
> >> >> i think the problem is that its attempting to insert all the
> >rows> >from> a into a single row of b.  i just don't know how to work
> >around> >this. > anyone have any ideas or suggestions?  thanks!
> >> > 
> >> > How about:
> >> > insert into table_foo (b) select a from table_foo;
> >> 
> >> ORA-01400: cannot insert NULL
> > 
> > I was just about to correct that post. INSERT creates a new row. It
> > sounds like you need to UPDATE. I don't know how to to update
> > multiple rows with different data. Sorry.
> 
> why would i want to update?  there's nothing in b yet to update, which
> is why i thought inserting was the way to get the data in there.

INSERT inserts rows, not columns. If you INSERT like you tried you'll
get new rows with only column b filled with data. That won't even work
if you try unless all the other fields are optional (which would be
highly irregular, to say the very least). I don't have a lot of
experience with SQL, just from college, where I'm in my final year, so I
can't help you much more than that.

Bill


More information about the Linux-users mailing list