3 Replies - 1119 Views - Last Post: 03 June 2010 - 09:29 AM

#1 Guest_nxion*


Reputation:

SQL statement question

Posted 03 June 2010 - 09:11 AM

Hi All,

SO I am new to Oracle SQL and I have a question. Here is a statement I made.

SELECT order_date, LPAD(order_total, 7, '$') order_total as "TOTAL" FROM F_ORDERS


When I run it I get an error:

ORA-00923: FROM keyword not found where expected



But if I run it like THIS:


SELECT order_date, LPAD(order_total, 7, '$') order_total FROM F_ORDERS


This is what happens:

ORDER_DATE ORDER_TOTAL
10-DEC-02 $103.02

Why does my alias for the "order total" column not work?

Thanks in advance

Is This A Good Question/Topic? 0

Replies To: SQL statement question

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: SQL statement question

Posted 03 June 2010 - 09:15 AM

Looks like you missed a comma, try this

SELECT order_date, LPAD(order_total, 7, '$'), order_total as "TOTAL" FROM F_ORDERS



EDIT: Nevermind, for some reason you have order_total 2 times, once inside LPAD and once outside (not sure the reasoning for this) try this

SELECT order_date, LPAD(order_total, 7, '$') AS "TOTAL" FROM F_ORDERS


Was This Post Helpful? 0
  • +
  • -

#3 Guest_nxion*


Reputation:

Re: SQL statement question

Posted 03 June 2010 - 09:28 AM

View PostPsychoCoder, on 03 June 2010 - 08:15 AM, said:

Looks like you missed a comma, try this

SELECT order_date, LPAD(order_total, 7, '$'), order_total as "TOTAL" FROM F_ORDERS



EDIT: Nevermind, for some reason you have order_total 2 times, once inside LPAD and once outside (not sure the reasoning for this) try this

SELECT order_date, LPAD(order_total, 7, '$') AS "TOTAL" FROM F_ORDERS




That worked! Thank you so much! The reason I had it twice was because I thought I was defining it in LPAD and then I had to put it again to select it. I guess I was wrong :) Thanks again so much!
Was This Post Helpful? 0

#4 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: SQL statement question

Posted 03 June 2010 - 09:29 AM

No problem, glad I could help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1