Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read string from right PLSQL

In a table column, I have this value:

DV-2011-01-000004 (the data type is varchar2)

How can i get the part of the string '000004'? In t-sql they have this right() function but in PL SQL i cant'seem to find a function just like the right() in t-sql.

Thanks for the help.

like image 237
FMiS Help Desk Avatar asked Feb 27 '12 07:02

FMiS Help Desk


People also ask

Is there a right function in Oracle SQL?

Oracle SQL doesn't have LEFT and RIGHT functions. They can be emulated with SUBSTR and LENGTH.

How do I search for a string in PLSQL?

The PLSQL INSTR function is used for returning the location of a substring in a string. The PLSQL INSTR function searches a string for a substring specified by the user using characters and returns the position in the string that is the first character of a specified occurrence of the substring.

How do I check if a string contains a substring in PLSQL?

The Oracle INSTR function is used to search string for substring and find the location of the substring in the string. If a substring that is equal to substring is found, then the function returns an integer indicating the position of the first character of this substring.

How do I print a string in PLSQL?

v_length Loop v_out := substr(IN_string,i,1) ; DBMS_OUTPUT. PUT_LINE(v_out); End loop; DBMS_OUTPUT. PUT_LINE('Text printed: ' || IN_string); End; -- Procedure created. BEGIN print_string('Hello'); END; -- Output: H e l l o Text printed: Hello Statement processed.


2 Answers

substr('DV-2011-01-000004', length('DV-2011-01-000004')-6 + 1 )
like image 166
turbanoff Avatar answered Oct 01 '22 01:10

turbanoff


you can use:

 SUBSTR('DV-2011-01-000004', INSTR('DV-2011-01-000004', '-', -1) +1)

when using INSTR with negative start position he will find the last index of "-". then SUBSTR will cut from this occurrence until the end (because I didn't supply Length)

like image 39
Dor Cohen Avatar answered Oct 01 '22 02:10

Dor Cohen