sqloracleoracle11g

How to get SUBSTR of an LPAD of a number in ORACLE?


Some student IDs are 5 digits instead of 6, so I added the LPAD to add a leading 0. Then after the LPAD, I need the first two digits of that.

Is this possible in Oracle? I keep getting this error ORA-00907: missing right parenthesis

SELECT SUBSTR(LPAD(S.ID_STUDENT,6,0)0,2) FROM MASTER.T_STDNT S

Let's say I have a student ID that is 12345. I'm expecting that to become 012345 and then get the first two digits of that.


Solution

  • Your query is correct but you're missing a comma after the LPAD.

    Here's your query fixed:

    SELECT SUBSTR(LPAD(S.ID_STUDENT,6,0), 0,2) FROM MASTER.T_STDNT S
    -- You were missing this comma      ^