Solved

Truncate string field from the right

Posted on 2004-08-10
8
10,468 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 76

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 142

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

Suggested Solutions

Title # Comments Views Activity
ORA-12560: TNS:protocol adapter error 8 87
Slow SQL query 12 55
dbcc checkdb datawarehouse 2 41
Process mapping 5 29
Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now