Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create Column Alias using a Function

User_BFIC6Jun 1 2016 — edited Jun 3 2016

Hello all!

I am fairly new to SQL, and am using Developer currently to query a database. My query is returning calculations, which are working fine, but I want them to roll monthly and to trend for the previous six months. So far my code is working great at pulling the correct calculations and trending for the previous months, the only bit I have left to get is the column aliases. The aliases are currently hard coded as "May", "Apr", etc, but I would like to have those calculate and roll with the rest of the calculations if possible. My current SELECT query is:

SELECT MONTH1.AGREETYP, MONTH1.CURR AS (SELECT TRUNC(ADD_MONTHS(SYSDATE, -1), 'MM') FROM DUAL), MONTH2.CURR AS "APR", MONTH3.CURR AS "MAR", MONTH4.CURR AS "FEB",MONTH5.CURR AS "JAN", MONTH6.CURR AS "DEC"

FROM [MONTH1 sub-select],[MONTH2 sub-select],etc.

As you can see above, I'm trying to get month 1 to work and then will move on to the other months. The current code returns an error of

ORA-00923: FROM keyword not found where expected

00923. 00000 -  "FROM keyword not found where expected"

*Cause:   

*Action:

Error at Line: 1 Column: 47

But if I only run that sub-select then it returns the date of 01-May-16, so I know that code works.

If I change the sub-select to "May" just like the other months then the code works perfectly. If I need to I can keep the column headings hard coded as they are, but I would much rather have the whole report automated and think that surely there has to be a way to make that happen. Any help is appreciated!

This post has been answered by Frank Kulash on Jun 1 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 1 2016
Added on Jun 1 2016
14 comments
4,903 views