dbTalk Databases Forums  

how to copy data from long to varchar2

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss how to copy data from long to varchar2 in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Peter Keckeis
 
Posts: n/a

Default how to copy data from long to varchar2 - 11-02-2006 , 06:14 AM






Hello all,

I would like a way to copy the data from l_txt to vc_txt with sql*plus.

create table test (pk char(6), vc_txt varchar2(2000), l_txt long,
constraint testpk primary key(pk))

Using

update test set vc_txt = l_txt;
or
update test set vc_txt = to_char(l_txt);

generates an ORA-00932 error.

Can you tell me please the right update statement.

Thanks in advance.
Peter







Reply With Quote
  #2  
Old   
Martin T.
 
Posts: n/a

Default Re: how to copy data from long to varchar2 - 11-02-2006 , 06:58 AM






Peter Keckeis wrote:
Quote:
Hello all,

I would like a way to copy the data from l_txt to vc_txt with sql*plus.

create table test (pk char(6), vc_txt varchar2(2000), l_txt long,
constraint testpk primary key(pk))

Using

update test set vc_txt = l_txt;
or
update test set vc_txt = to_char(l_txt);

generates an ORA-00932 error.

Can you tell me please the right update statement.

You might want to post your Oracle version when asking around here

Hmm .... can't get this to work on 9i2 either, but the docs don't seem
to say it wouldn't work.

Work-around:

begin
for reco in (
select *
from test
for update
) loop
update test set vc_txt = reco.l_txt;
end loop;
end;

br,
Martin



Reply With Quote
  #3  
Old   
Peter Keckeis
 
Posts: n/a

Default Re: how to copy data from long to varchar2 - 11-03-2006 , 12:47 AM




"Martin T." <bilbothebagginsbab5 (AT) freenet (DOT) de> schrieb im Newsbeitrag
news:1162472305.225648.113800 (AT) b28g2000cwb (DOT) googlegroups.com...
Quote:
Peter Keckeis wrote:
Hello all,

I would like a way to copy the data from l_txt to vc_txt with sql*plus.

create table test (pk char(6), vc_txt varchar2(2000), l_txt long,
constraint testpk primary key(pk))

Using

update test set vc_txt = l_txt;
or
update test set vc_txt = to_char(l_txt);

generates an ORA-00932 error.

Can you tell me please the right update statement.


You might want to post your Oracle version when asking around here

Hmm .... can't get this to work on 9i2 either, but the docs don't seem
to say it wouldn't work.

Work-around:

begin
for reco in (
select *
from test
for update
) loop
update test set vc_txt = reco.l_txt;
end loop;
end;

br,
Martin

Thanks to Martin

Acts unfortunately not as expected.

PL/SQL procedure execute successfull, but vc_txt columns are emtpy.

oracle version is 10g

Regards
Peter




Reply With Quote
  #4  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: how to copy data from long to varchar2 - 11-03-2006 , 02:17 AM



Martin T. schreef:
Quote:
Peter Keckeis wrote:

create table test (pk char(6), vc_txt varchar2(2000), l_txt long,
constraint testpk primary key(pk))

generates an ORA-00932 error.

You might want to post your Oracle version when asking around here

Must be pre-8.0, because Oracle advertises to use LOB's, not longs
since the end of 7.3. The use of char(6) as primary key also makes
me wonder.

And when were varchar2(4000) columns introduced?

--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...


Reply With Quote
  #5  
Old   
Martin T.
 
Posts: n/a

Default Re: how to copy data from long to varchar2 - 11-03-2006 , 02:20 AM



Peter Keckeis wrote:
Quote:
"Martin T." <bilbothebagginsbab5 (AT) freenet (DOT) de> schrieb im Newsbeitrag
news:1162472305.225648.113800 (AT) b28g2000cwb (DOT) googlegroups.com...
Peter Keckeis wrote:
Hello all,

I would like a way to copy the data from l_txt to vc_txt with sql*plus.

create table test (pk char(6), vc_txt varchar2(2000), l_txt long,
constraint testpk primary key(pk))

Using

update test set vc_txt = l_txt;
or
update test set vc_txt = to_char(l_txt);

generates an ORA-00932 error.

Can you tell me please the right update statement.


You might want to post your Oracle version when asking around here

Hmm .... can't get this to work on 9i2 either, but the docs don't seem
to say it wouldn't work.

Work-around:

begin
for reco in (
select *
from test
for update
) loop
update test set vc_txt = reco.l_txt;
end loop;
end;

br,
Martin


Thanks to Martin

Acts unfortunately not as expected.

PL/SQL procedure execute successfull, but vc_txt columns are emtpy.

oracle version is 10g

Hm. Well I tried the script on my 9i2 and the values were copied as
expected ... but of course I only had a very small amount of test data.
Can you log the long values read via dbms_output in the script?
How long are your Longs anyway?
And, is this a one-off thing you are trying here? As Frank said it
might be a good idea to get rid of that long column.

cheers,
Martin



Reply With Quote
  #6  
Old   
Peter Keckeis
 
Posts: n/a

Default Re: how to copy data from long to varchar2 - 11-06-2006 , 01:41 AM




"Martin T." <bilbothebagginsbab5 (AT) freenet (DOT) de> schrieb im Newsbeitrag
news:1162542003.960987.301590 (AT) b28g2000cwb (DOT) googlegroups.com...
Quote:
Peter Keckeis wrote:
"Martin T." <bilbothebagginsbab5 (AT) freenet (DOT) de> schrieb im Newsbeitrag
news:1162472305.225648.113800 (AT) b28g2000cwb (DOT) googlegroups.com...
Peter Keckeis wrote:
Hello all,

I would like a way to copy the data from l_txt to vc_txt with
sql*plus.

create table test (pk char(6), vc_txt varchar2(2000), l_txt long,
constraint testpk primary key(pk))

Using

update test set vc_txt = l_txt;
or
update test set vc_txt = to_char(l_txt);

generates an ORA-00932 error.

Can you tell me please the right update statement.


You might want to post your Oracle version when asking around here

Hmm .... can't get this to work on 9i2 either, but the docs don't seem
to say it wouldn't work.

Work-around:

begin
for reco in (
select *
from test
for update
) loop
update test set vc_txt = reco.l_txt;
end loop;
end;

br,
Martin


Thanks to Martin

Acts unfortunately not as expected.

PL/SQL procedure execute successfull, but vc_txt columns are emtpy.

oracle version is 10g


Hm. Well I tried the script on my 9i2 and the values were copied as
expected ... but of course I only had a very small amount of test data.
Can you log the long values read via dbms_output in the script?
How long are your Longs anyway?
And, is this a one-off thing you are trying here? As Frank said it
might be a good idea to get rid of that long column.

cheers,
Martin

Hi Martin,

i made the following changes in the PL/SQL Script:

begin
for reco in (
select pk,l_txt
from test
for update
) loop
update test set vc_txt = substr(reco.l_txt,1,2000) where pk = reco.pk;
end loop;
end;

(pk = primary key field)

and now, it works fine.

cheers,
Peter




Reply With Quote
  #7  
Old   
Martin T.
 
Posts: n/a

Default Re: how to copy data from long to varchar2 - 11-06-2006 , 07:48 AM



Peter Keckeis wrote:
Quote:
"Martin T." <bilbothebagginsbab5 (AT) freenet (DOT) de> schrieb im Newsbeitrag
news:1162542003.960987.301590 (AT) b28g2000cwb (DOT) googlegroups.com...
Peter Keckeis wrote:
"Martin T." <bilbothebagginsbab5 (AT) freenet (DOT) de> schrieb im Newsbeitrag
news:1162472305.225648.113800 (AT) b28g2000cwb (DOT) googlegroups.com...
Peter Keckeis wrote:
Hello all,

I would like a way to copy the data from l_txt to vc_txt with
sql*plus.

create table test (pk char(6), vc_txt varchar2(2000), l_txt long,
constraint testpk primary key(pk))

Using

update test set vc_txt = l_txt;
or
update test set vc_txt = to_char(l_txt);

generates an ORA-00932 error.

Can you tell me please the right update statement.


You might want to post your Oracle version when asking around here

Hmm .... can't get this to work on 9i2 either, but the docs don't seem
to say it wouldn't work.

Work-around:

begin
for reco in (
select *
from test
for update
) loop
update test set vc_txt = reco.l_txt;
end loop;
end;

br,
Martin


Thanks to Martin

Acts unfortunately not as expected.

PL/SQL procedure execute successfull, but vc_txt columns are emtpy.

oracle version is 10g


Hm. Well I tried the script on my 9i2 and the values were copied as
expected ... but of course I only had a very small amount of test data.
Can you log the long values read via dbms_output in the script?
How long are your Longs anyway?
And, is this a one-off thing you are trying here? As Frank said it
might be a good idea to get rid of that long column.

cheers,
Martin

Hi Martin,

i made the following changes in the PL/SQL Script:

begin
for reco in (
select pk,l_txt
from test
for update
) loop
update test set vc_txt = substr(reco.l_txt,1,2000) where pk = reco.pk;
end loop;
end;

(pk = primary key field)

and now, it works fine.

Ah ok. My test data wasn't that long.
It's a bit weird though that you get empty when the long are longer
than the varchar2 instead of an error. Whatever

best,
Martin



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.