0

I currently have the following query:

SELECT SPEAKERNAME, 
       SUBSTR(SPEAKERADDRESS, CHARINDEX('-', SPEAKERADDRESS), 4)
  FROM SPEAKER;

I am tyrying to only return the postcode from SPEAKERADDRESS and the postcode is always after '-' but i am getting an invalid identifier (ORA-00904) error for CHARINDEX

4
  • Where in the Oracle manual did you find charindex()? Commented Oct 5, 2017 at 10:04
  • can you add sample data for that and expected o/p Commented Oct 5, 2017 at 10:05
  • Oracle doesn't have CHARINDEX, use INSTR instead: sqlines.com/oracle/functions/instr Commented Oct 5, 2017 at 10:09
  • 2113 and the addresses are all of different lengths but this is always 4 digits Commented Oct 5, 2017 at 10:13

1 Answer 1

1

You can use SUBSTR and INSTR:

SELECT SPEAKERNAME, 
       SUBSTR(SPEAKERADDRESS, instr(SPEAKERADDRESS, '-')+1 ,4)
  FROM SPEAKER;

Check Demo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.