Solved

Stripping non-printable characters from varchar2 column

Posted on 2004-09-03
9
2,071 Views
Last Modified: 2008-01-09
I am storing all the sql generated by Informatica PowerMart ETL tool and the sql is being stored with chr(10) and chr(13) in it causing ugly viewing.  I'd like to strip that out for easy viewing.

Here is an example:

SELECT DISTINCT HRA_QUESTIONNAIRE.HEALTH_RELATED_ACTIVITY_ID

FROM

 HRA_QUES_ANSWER_HISTORY, HRA_Q

I've reviewed some of the other answers related to this topic and having found what I need or am not understanding how it works.   Can somebody show me how to strip those two characters, maybe replacing them with spaces, and leave the rest of the text?

0
Comment
Question by:DonFreeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 9

Expert Comment

by:pratikroy
ID: 11972844
There could be different ways of doing this. Tell us how do you wish to do it ?

You can use grep, awk, sed or write a program in C, perl etc to get rid of blank lines from a file. Depends on how and where you have stored this SQL file.
0
 
LVL 9

Accepted Solution

by:
pratikroy earned 125 total points
ID: 11972882
oops ... did'nt see tha you have this stored in a varchar2 column.

well, if you just wish to ignore the chr(10) and chr(13) you can do this :

SQL> desc TAB_CHARS
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 MYFLD                                              VARCHAR2(10)

SQL> select * from TAB_CHARS;

MYFLD
----------
120
180
1700
SEED

SQL> insert into TAB_CHARS values ('abc' || chr(10) || 'def');

1 row created.

SQL> insert into TAB_CHARS values ('ghi' || chr(13) || 'jkl');

1 row created.

SQL> select * from TAB_CHARS;

MYFLD
----------
abc
def

jkl
120
180
1700
SEED

6 rows selected.

SQL> select translate(MYFLD,chr(13)||'A', 'A') from select translate(MYFLD,chr(13)||'^C

SQL>
SQL> select translate(MYFLD,chr(13)||chr(10)||'A','A') from TAB_CHARS;

TRANSLATE(
----------
abcdef
ghiAjkl
120
180
1700
SEED

6 rows selected.

Hope this helps!
0
 
LVL 9

Expert Comment

by:pratikroy
ID: 11972901
I just got rid of the special characters, but if you wish to convert them to a space character (which I think you would want), then do this :

SQL> select translate(MYFLD,chr(13)||chr(10)||'A', '  A') from TAB_CHARS;

TRANSLATE(
----------
abc def
ghi jkl
120
180
1700
SEED

6 rows selected.

Hope this helps!
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 1

Expert Comment

by:erhanyayli
ID: 11972913
Hi

You may use replace function to eliminate unwanted characters

Below should omit char(10+13)

select replace(replace(string, chr(10)),chr(13)) from dual

Regards,
Erhan
0
 
LVL 4

Expert Comment

by:mottor
ID: 11973084
pratikroy,

You can alo delete 'A':
select translate(MYFLD,chr(13)||chr(10), '  ') from TAB_CHARS;
0
 
LVL 9

Expert Comment

by:pratikroy
ID: 11973244
true :))
0
 
LVL 1

Author Comment

by:DonFreeman
ID: 11973340
I'm not getting consistent results.

The two chrs come in pairs.
There is a pair of chr(13)||chr(10) at the end of each of these lines

SELECT HEALTH_RELATED_ACTIVITY.HEALTH_RELATED_ACTIVITY_ID
FROM
 HEALTH_RELATED_ACTIVITY
WHERE

0
 
LVL 1

Author Comment

by:DonFreeman
ID: 11973425
This got it. Thanks everybody!

SELECT TRANSLATE(SUBSTR(SQL_STATEMENT_TEXT,1,100),CHR(13)||CHR(10),' ') FROM RPT_SQL_STATEMENTS WHERE ROWID='AAA1IpAATAAABEeAE/';

TRANSLATE(SUBSTR(SQL_STATEMENT_TEXT,1,100),CHR(13)||CHR(10),'')
----------------------------------------------------------------------------------------------------
SELECT HEALTH_RELATED_ACTIVITY.HEALTH_RELATED_ACTIVITY_ID  FROM  HEALTH_RELATED_ACTIVITY  WHERE
0
 
LVL 9

Expert Comment

by:pratikroy
ID: 11973946
Glad your problem is solved !! Cheers !
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle mutateing errors 3 28
date show only hh:mm 2 50
Oracle database T-1 Setup 7 45
Oracle Date add 9 35
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question