Categories:
Cloud (204)
Entertainment (11)
Facebook (43)
General (50)
Life (31)
Programming (64)
Technology (430)
Testing (4)
Tools (488)
Twitter (5)
Wearable (26)
Web Design (44)
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, ∼2658🔥, 0💬
Popular Posts:
How to unzip a PowerPoint .pptx file? According to Microsoft documentation, a .pptx file is really a...
How to update TOC (Table Of Content) for a FrameMaker book? I have make changes in some chapters. Yo...
How to find and read log file in FileZilla Server? I have logging turned on already. For FileZilla S...
What are those search options provided on Library Genesis? Library Genesis provides 3 types of searc...
How to start and stop FileZilla Server service? I have FileZilla installed on my Windows computer. Y...