Home » RDBMS Server » Server Administration » SQLPLUS help please
SQLPLUS help please [message #373759] Fri, 04 May 2001 17:02 Go to next message
S Bala
Messages: 9
Registered: April 2001
Junior Member
Hi ,
when i do a rtrim on a field i get the following error:
===============================================
SQL> select rtrim(details) from mytable where my_field='2000USFI03378';
select rtrim(details) from mytable where my_field='2000USFI03378'
*
ERROR at line 1:
ORA-00932: inconsistent datatypes
=============================================
The datatype of this variable is unknown to me(
its from a remote database)
Basically i want to trim off the extra special characters from the field so that
i can print the variable to the web.
Can you please help me how do i retrieve
a ASCII only extract from this field?
Thanx very much ,
Bala S
Re: SQLPLUS help please [message #373761 is a reply to message #373759] Fri, 04 May 2001 17:50 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
In sqlplus to see the datatypes, enter:
descr table_name
or
descr table_name@db_link

Use trim() as the new equivalent to the combination of ltrim() and rtrim(). Use translate() or replace() to remove unwanted characters. The functions are similar but different. use chr() to specify unprintable characters.

select translate('hello'||chr(10)||'world',chr(10),'~') from dual
Re: SQLPLUS help please [message #373765 is a reply to message #373761] Mon, 07 May 2001 07:47 Go to previous messageGo to next message
S Bala
Messages: 9
Registered: April 2001
Junior Member
Hi ,
the datatype of the field details is LONG.
Thanx for your help.
But the trim(details) failed to work:
SQL> select trim(details) from mytable where my_field='2000';
select trim(details) from invoices where my_field='2000'
*
ERROR at line 1:
ORA-00904: invalid column name

======================
In case if there is anyway to remove the special characters
from the LONG datatype, can you please let me know
about the same.
Thanx ,
Bala S
Re: SQLPLUS help please [message #373767 is a reply to message #373759] Mon, 07 May 2001 12:44 Go to previous message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
You can manipulate LONG data when you chop it up into varchar2 chunks in pl/sql.

see the following 2 examples for ideas...

http://www.classicity.com/oracle/htdocs/forums/ClsyForumID125/8.html#
http://www.oracle.com/oramag/oracle/01-may/index.html?o31asktom.html

scott@DEV816> create or replace function
clean( p_raw in blob )
return varchar2
2 as
3 l_tmp long default
utl_raw.cast_to_varchar2(
dbms_lob.substr(p_raw,2000,1));
4 l_char char(1);
5 l_return long;
6 begin
7 for i in 1 .. length(l_tmp)
8 loop
9 l_char := substr( l_tmp, i, 1
);
10 if ( ascii(l_char) between 32
and 127 )
11 then
12 l_return := l_return ||
l_char;
13 else
14 l_return := l_return ||
'.';
15 end if;
16 end loop;
17 return l_return;
18 end;
19 /
Previous Topic: Select selected rows at a time
Next Topic: Help !!
Goto Forum:
  


Current Time: Sat Jun 29 00:05:09 CDT 2024