1

I am using the following query to create an oracle view in oracle sql developer,

    select * from (SELECT DATEENTER as PI_TIMESTAMP,PI_TAG as  PI_TAGNAME, 
case when LENGTH(TRIM(TRANSLATE(final, ' +-.0123456789', ' '))) is null then cast(final as number) else null end as PI_VALUE,
STATUS AS  PI_STATUS  
FROM T2) a
where PI_VALUE is not null

The query is working fine in a query window, however it is giving me the error Error(s) parsing SQL: Unexpected token at 134 near ). Unexpected token at 136 near is. when i try to create it as a view

Thanks

4
  • I can't see anything wrong in the query. Does it work when you run it from SQL*Plus?
    – user330315
    Jun 25, 2012 at 7:08
  • 1
    yes it works fine, only when trying to create a view out of it the error pops up Jun 25, 2012 at 7:10
  • If you get an error when trying to create your view from SQL*Plus, then please post your complete statement. I was able to create a view using your above statement just fine. Jun 25, 2012 at 7:21
  • I am using the same statement to create the view, since it worked fine with u then I am begining to suspect that my sql developer is corrupted, really wierd Jun 25, 2012 at 7:24

1 Answer 1

3

Probably, SQL Developer is getting confused by the column name "final". "final" is used in Oracle PL/SQL to prevent inheriting from an Object type.

Try running your statement in SQL/Plus - should work fine.

BTW, I'd recommend using to_number(final) instead of a plain cast.

3
  • Thanks, but actually the column final is a string, Jun 25, 2012 at 7:05
  • Of course, but you are still telling Oracle to "treat final as a number" without specifying any number format. If you use to_number(), you can provide a number format - this will allow you to handle NLS-specific issues etc. correctly. FYI: You also don't handle scientific numbers ('1E2') in your translate() correctly. Jun 25, 2012 at 7:26
  • Thanks Frank for pointing this out, Actually my point of this translation was to use the SQL funtion IsNumeric in oracle, so that's the only thing i found, can it be better than this? thanks again Jun 25, 2012 at 7:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.