| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
|  |  | |||
Home -> Community -> Mailing Lists -> Oracle-L -> Re: how do I concatenate a string in PL/SQL?
Hi,
Please try both versions. You'l understand easily why 50+30 field char 
lengths don't fit in
a 50 char length field. Use instead varchar2.
declare
 a_strng  CHAR(50);
 a_ATWRT  CHAR(30);
begin
  a_ATWRT := 'World';
  a_strng := 'Hello';
  dbms_output.put_line('a_ATWRT real length: ' || to_char(length(a_ATWRT)));
  dbms_output.put_line('a_strng real length: ' || to_char(length(a_strng)));
  dbms_output.put_line('And the sum is ....: ' || 
to_char(length(a_strng) + length(a_ATWRT)));
 
end;
/
--
--
--
--
declare
 a_strng  VARCHAR2(50);
 a_ATWRT  VARCHAR2(30);
begin
  a_ATWRT := 'World';
  a_strng := 'Hello';
  dbms_output.put_line('a_ATWRT real length: ' || to_char(length(a_ATWRT)));
  dbms_output.put_line('a_strng real length: ' || to_char(length(a_strng)));
  a_strng := a_ATWRT || a_strng;
  dbms_output.put_line ( a_strng);
end;
/
Cumpliments
 Dias Costa
Roger Xu wrote:
>SQL> !cat /tmp/abc.sql
>set serveroutput on
>set verify off
>
>declare
>
> a_strng  CHAR(50);
> a_ATWRT  CHAR(30);
>
>begin
>
>  a_ATWRT := 'World';
>  a_strng := 'Hello';
>  a_strng := a_ATWRT || a_strng;
>  dbms_output.put_line ( a_strng);
>
>end;
>
>/
>
>set verify on
>
>SQL> @/tmp/abc
>declare
>*
>ERROR at line 1:
>ORA-06502: PL/SQL: numeric or value error
>ORA-06512: at line 10
>
>
>SQL>
>
>-----Original Message-----
>From: Pat Hildebrand [mailto:pat_at_sas.upenn.edu]
>Sent: Wednesday, February 08, 2006 4:28 PM
>To: Roger Xu
>Cc: Jared Still; Oracle-L_at_Freelists. Org (E-mail)
>Subject: Re: how do I concatenate a string in PL/SQL?
>
>
>I common cause of the error that you are getting for strings is that
>you are trying to put in a value that is too long for the
>variable. Look at your variable definition and what you are trying to
>put into it.
>
>                     Pat
>
>
>On Wed, Feb 08, 2006 at 05:01:16PM EST, Roger Xu <roger_xu_at_dp7uptx.com> wrote:
>  
>
>>Nothing wrong with the cursor, the only problem is: "a_strng := a_ATWRT || a_strng;"
>> 
>>ORA-06502: PL/SQL: numeric or value error
>>ORA-06512: at line 97
>> 
>>    
>>
>
>For technical support please email tech_support_at_dp7uptx.com or you can
>call (972)721-8257. 
>This email has been scanned for all viruses by the MessageLabs Email Security System.
>
>This e-mail is intended solely for the person or entity to which it is addressed and may contain confidential and/or privileged information. Any review, dissemination, copying, printing or other use of this e-mail by persons or entities other than the addressee is prohibited. If you have received this e-mail in error, please contact the sender immediately and delete the material. 
>____________________________________________________________________
>This email has been scanned for all viruses by the MessageLabs Email Security System. Any questions please call 972-721-8257 or email your request to tech_support_at_dp7uptx.com.
>--
>http://www.freelists.org/webpage/oracle-l
>
>
>  
>
--
http://www.freelists.org/webpage/oracle-l
Received on Wed Feb 08 2006 - 17:16:09 CST
|  |  |