Avatar of chalie001
chalie001

asked on 

how to trim value in Long datatype

hi i have the following query

select -- substr(msg_name,1,8),
         fld_seq_no,
          substr(fld_name,1,40) fld_name, fld_type, fld_length,
          fld_precision
     from message_dict
    where msg_name like ('&msg')
    order by fld_seq_nO

Open in new window

;
 which retun following values
  FLD_SEQ_NO FLD_NAME   FLD_TYPE      FLD_LENGTH  FLD_PRECISION
--------------------------------------- ---------------------------------------- -------- --------------------------------------- ---------------------------------------
  10 IDMSTYPE_100                  CH                   1
  20 SASTIME_100                     DF                14
                                     
               
                        
                  i have another query which got this
SQL> SELECT MSG_TEXT FROM msg_in WHERE stream = 'TESTBASIC'
 
MSG_TEXT
--------------------------------------------------------------------------------
U201605170000001122334455667788990065465465465033024tONYTEST

i what the value to display as

I what to trim the msg_text based on the FLD_LENGTH AND POPULATE in extra column

FLD_SEQ_NO FLD_NAME         FLD_TYPE    FLD_LENGTH        FLD_PRECISION          Value
--------------------------------------- ---------------------------------------- -------- --------------------------------------- -----------------------------------------------------------
   10                IDMSTYPE_100      CH                1                                                                 U
   20     SASTIME_100                    DF               1                                                                 20160517000000
                                     
                                                      

desc msg_in
Name          Type        Nullable Default Comments
------------- ----------- -------- ------- --------                            
MSG_TEXT      LONG
DatabasesOracle Database

Avatar of undefined
Last Comment
chalie001
Avatar of johnsone
johnsone
Flag of United States of America image

Your biggest hurdle is going to be the LONG datatype.  Why are you using that?  That was deprecated a long time ago.  You really should be using a CLOB.

If you cannot change the data type, then I believe your best option is going to be to temporarily convert it to a CLOB.  The unfortunate part there is that it would involved additional steps.  The easiest way I know if to do it is using the TO_LOB function, however that can only be used in an insert statement.  I would convert the LONG to a CLOB using a global temporary table, then you can use the DBMS_LOB.SUBSTR function to do the substrings that you need.
Avatar of chalie001
chalie001

ASKER

How can I do that
SOLUTION
Avatar of johnsone
johnsone
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of chalie001
chalie001

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Oracle Database
Oracle Database

Oracle is an object-relational database management system. It supports a large number of languages and application development frameworks. Its primary languages are SQL, PL/SQL and Java, but it also includes support for C and C++. Oracle also has its own enterprise modules and application server software.

81K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo