Solved

Truncate string field from the right

Posted on 2004-08-10
8
10,472 Views
Last Modified: 2012-06-21
Hello,
Trying to return the rightmost 5 characters in a multi-length field (1-9 characters).  In Excel or VB I could use the RIGHT function to get what I want, but I'm using Discoverer which is not recognizing RIGHT as a registered function.  RTRIM only weeds out the blanks so that doesn't work.  Any other suggestions?

TIA
0
Comment
Question by:mriozzo
8 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 11767026
It's not pretty but should work (it's the quickest I can come up with off the top of my head).

drop table tab1;

create table tab1( col1 varchar2(9));

insert into tab1 values('1');
insert into tab1 values('12');
insert into tab1 values('123');
insert into tab1 values('1234');
insert into tab1 values('12345');
insert into tab1 values('123456');
insert into tab1 values('1234567');
insert into tab1 values('12345678');
insert into tab1 values('123456789');
commit;

select substr(lpad(col1,14,0),10) from tab1
/
0
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 125 total points
ID: 11767097
I believe the only string function specific to Discoverer is AllTrim.

However, the INSTR and SUBSTR Oracle PL/SQL string functions should work. For syntax, see: http://www.psoug.org/reference/substr_instr.html
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 125 total points
ID: 11770250
another option:
select iif( len(col1) >= 5 ,  substr (  len(col1) - 4 )   , col1)

Cheers
0
 
LVL 2

Expert Comment

by:binghu
ID: 11789854
how about

substr(column_name, length(column)-5,5)
0
 
LVL 1

Expert Comment

by:amulya_333
ID: 11808699
Hi,
 binghu 's code will give you the result leaving the last char.
Try this,
substring(columnname, len(column)-4,5)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

830 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