Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Allow to set negative substr length: SUBSTR(text,position,-length)

Sven W.Jul 16 2019 — edited Jul 22 2019

syntax

SUBSTR(text,position,-length,length_mode)

example

text="abcdefgh"

SUBSTR(text,1,-2) => "abcdef"

result

This would fetch a part from a string that is a little less than the original string.

The suggestion would be a shortcut (and hopefully one with a higher performance) to

SUBSTR(text, 1, LENGTH(text)-2))

reason

The advantage is that this eliminates the need to write "text" - which could be a complex expression - twice.

We already can select a few characters from the end of the string using a negative position.

SUBSTR(text,-2) => "gh"

returns the last two chars from a text. However currently there is no quick way to fetch the first part.

The suggestion would complete this.

-- Edit --

added 4th parameter length_mode: needed so that existing code still produces NULL for negative lengths. See further comments in this thread.

Comments
Post Details
Added on Jul 16 2019
5 comments
3,343 views