Categories:
Cloud (161)
Entertainment (11)
Facebook (43)
General (16)
Life (30)
Programming (33)
Technology (224)
Testing (4)
Tools (431)
Twitter (5)
Wearable (26)
Web Design (9)
Collections:
Other Resources:
Oracle Truncating Message with '...'
What is the best way in Oracle to truncate a string to 140 characters and add "..." to the end if there are more than 140 characters in the string? I need this to display initial parts of user comments on my home page.
✍: FYIcenter
Basically, you are asking the logic to be implemented in an Oracle query,
If the string has more than 140 characters, Return the first 140 characters with "..." added to the end Else Return the string as is
A straightforward solution is the following:
SELECT CASE WHEN LENGTH(input)>140 THEN SUBSTR(input,1,140)||'...' ELSE input END FROM DUAL;
But using the REGEXP_REPLACE() function will give you a better solution:
SELECT REGEXP_REPLACE(input,'(.{140}).*','\1...',1,0,'n') FROM DUAL;
2015-09-16, 1022👍, 0💬
Popular Posts:
How register my Fitbit device through Fitbit Connect? I have an account with Fitbit server, installe...
Where to find answers to frequently asked questions on Google Chrome? I want to know how to install ...
Where to find answers to frequently asked questions about Microsoft Office 365? Here is a collection...
Where to find answers to frequently asked questions on installing and using Mozilla Firefox 2.0? Her...
How to start to troubleshoot my Actiontec GT784WNV Modem? I am not able to access Internet. If you a...