Column alias name

Hi All,
can we use the column alias name in expression in a select query?
example,
select (10+20) as col1, (col1+30) as col2 from dual;
when i execute the above query, i am getting "col1 is invalid identifier".
can please some one answer to my query OR is there any other way to get the answer to my query?

As you found out, you can't do it that way... What you can do is something like
select (col1+30) as col2
  from (select 10+20 as col1
              from  dual
)

Similar Messages

  • Flexible column alias name?

    Hi
    Is that a way to assign the column alias name at run time.
    Example: I want to sums a column and label it based on the current year.
    For 2007, I should have:
    SELECT
    ‘A’
    ‘B’,
    ‘C’,
    sum(RESERVE_AMT) AS RESERVE_AMT_2007
    FROM table_name
    For 2006 I should have:
    SELECT
    ‘A’
    ‘B’,
    ‘C’,
    sum(RESERVE_AMT) AS RESERVE_AMT_2006
    FROM table_name
    For 2005 I should have:
    SELECT
    ‘A’
    ‘B’,
    ‘C’,
    sum(RESERVE_AMT) AS RESERVE_AMT_2005
    FROM table_name
    Etc.
    For some reason I need a sql (something like above) in the procedure to be run in each year and populate a column labeled the current year concatenated with a fix string such as RESERVE_AMT_2007.
    Thanks.

    I've just modify your code and see what it shows --
    SQL>
    SQL> Create or Rreplace Procedure PROC_EXECUTE(var_Year VARCHR2)
      2  lsql VaRCHAR2(4000);
    Create or Rreplace Procedure PROC_EXECUTE(var_Year VARCHR2)
    ERROR at line 1:
    ORA-00905: missing keywordThen i've corrected it and again execute it then it shows --
    SQL> BEGIN
      2 
      3  lsql = ' SELECT empno , ename RESERVE_AMT_ ' || var_year
      4  || ' FROM emp';
      5 
      6  execute immediate(lsql);
      7  END PROC_EXECUTE;
      8  /
    lsql = ' SELECT empno , ename RESERVE_AMT_ ' || var_year
    ERROR at line 3:
    ORA-06550: line 3, column 6:
    PLS-00103: Encountered the symbol "=" when expecting one of the following:
    := . ( @ % ;
    ORA-06550: line 6, column 1:
    PLS-00103: Encountered the symbol "EXECUTE"As because, you didn't use :=. Then i've corrected that one and again execute it and it shows --
    SQL>
    SQL> Create or replace Procedure PROC_EXECUTE(var_Year VARCHR2)
      2  lsql VaRCHAR2(4000);
      3  BEGIN
      4 
      5  lsql := ' SELECT empno , ename RESERVE_AMT_ ' || var_year
      6  || ' FROM emp';
      7 
      8  execute immediate(lsql);
      9  END PROC_EXECUTE;
    10  /
    Warning: Procedure created with compilation errors.
    SQL>
    SQL>
    SQL> sho errors;
    Errors for PROCEDURE PROC_EXECUTE:
    LINE/COL ERROR
    2/1      PLS-00103: Encountered the symbol "LSQL" when expecting one of
             the following:
             ; is with authid as cluster order using external
             deterministic parallel_enable pipelined
             The symbol "is" was substituted for "LSQL" to continue.I've to correct two places and then ---
    SQL>
    SQL> Create or replace Procedure PROC_EXECUTE(var_Year IN VARCHAR2)
      2  is
      3  lsql VaRCHAR2(4000);
      4  BEGIN
      5 
      6  lsql := ' SELECT empno , ename RESERVE_AMT_ ' || var_year
      7  || ' FROM emp';
      8 
      9  execute immediate(lsql);
    10  END PROC_EXECUTE;
    11  /
    Procedure created.And, now i execute it and it shows --
    SQL>
    SQL> exec PROC_EXECUTE('TRY');
    BEGIN PROC_EXECUTE('TRY'); END;
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    ORA-06512: at "SCOTT.PROC_EXECUTE", line 9
    ORA-06512: at line 1My request to you - before put any solution please check the basic structure of your solution.
    Regards.
    Satyaki De.
    N.B: If you don't provide proper structure - it might be a hectic solution for the user, too. Don't mind. I know you want to help the user - i mean your motive is good. But, still you should understand. Be positive. Hope you don't mind. With best regards.

  • Issue with Column Alias Name in a SELECT statement

    I am trying to run sql query(IN ORACLE) to get the data from a remote database(TERADATA). The query is
    select (table1.exp_date - table1.setup_date) AS day_diff,
    CASE
    WHEN day_diff = '0'
    THEN 'YES'
    WHEN day_diff > '0'
    THEN 'NO'
    ELSE 'Unknown'
    END AS alias_type
    from table1@remote_database_name;
    The query is running fine when I run it in TERADATA environment directly without the remote database link since it is not necessary. If I run the above query in Oracle I am getting an error ORA-00904: invalid identifier.(this error is pointing to day_diff alias name)
    Can anyone help me with this?
    Thanks

    The Column alias can be used in the ORDER BY clause, but not other clauses,like WHERE clause, in the query.
    Use..
    select (table1.exp_date - table1.setup_date) AS day_diff,
    CASE
    WHEN (table1.exp_date - table1.setup_date) = '0'
    THEN 'YES'
    WHEN (table1.exp_date - table1.setup_date) > '0'
    THEN 'NO'
    ELSE 'Unknown'
    END AS alias_type                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Alias name for the column name in Prompt

    Hi,
    I have a scenario where I am taking column names into prompt. I have used the following SQL in the SQL results under "Show" option of the Prompt.
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By OrderDate"' END FROM " Real Time"
    UNION ALL
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By ShipDate"' END FROM "Real Time"
    My problem here is I am getting the column names into the Prompt as "Orders"."By OrderDate" and "Orders"."By ShipDate", which is not acceptable and readable for mat for the user. Is there any way that I can assign an alias name for the column name such as OrderDate and ShipDate in the above SQL.
    Your quick respose is appreciated.
    Thanks,
    Rama

    hi,
    try an alternative one....in your administrator make new columns with alias to ones you want...so you wiil be able to show whatever you want.
    Otherwise,is it possible to show
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By OrderDate"' as "xxxxxxxxxxxxx"END FROM " Real Time"
    UNION ALL
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By ShipDate"' as "yyyyyyyyyyyyyyyy"END FROM "Real Time"
    Ending,you want the data from your columns?or just the name??
    hope i helped...
    http://greekoraclebi.blogspot.com/

  • How to get the alias name of an attribute of a VO from its column name?

    How can I programmatically get the alias name of an attribute of a VO given its column name?
    Often alias and column names are not same when the VO is created (and I don't require them to be the same)

    Hello John.
    I will be more precise. When the VO based on a table comes out from the wizard, it produces xml entries like the following one:
      <ViewAttribute
        Name="ColumnName"
        AliasName="COLUMN_NAME"/>There the column of the table on the DB really is COLUMN_NAME. The wizard mangles that name producing ColumnName as Name property.
    This is ok. I don't want to change this default behaviour.
    What I need is to programmatically get the value of that attribute given its AliasName property value:
    String f(ViewObject vo, String AliasName) {
    return (String)vo.getCurrentRow().getAttributeFromAliasName(aliasName); // getAttributeFromAliasName does not exist
    // instead of return (String)vo.getCurrentRow().getAttribute(Name);
    That is, usually getAttribute expects what in the xml is the Name property. However, I want a sort of getAttribute() expecting the AliasName.
    I hope it's clear.

  • ORA-00998: must name this expression with a column alias

    Dear all,
    create table mebs_temp10 tablespace mebs_tempt nologging as SELECT TRUNC(meddate) as meddate, ctype , btext btext, COUNT (1), sum(duration/60), SUM (bamount) FROM mells.hcalls WHERE meddate >= '01-JAN-2009' and meddate < '01-MAY-2009' GROUP BY meddate, ctype, btext
    ERROR at line 1:
    ORA-00998: must name this expression with a column alias
    I tried giving a alias for the columns ctype , btext .. but helpless. which column to be aliased ?
    Kai

    Try this...
    create table
    mebs_temp10 tablespace mebs_tempt nologging as
    SELECT
    TRUNC(meddate) as meddate,
    ctype,
    btext btext,
    COUNT (1) count_field,
    sum(duration/60) sum_duration,
    SUM (bamount) sum_bamount
    FROM mells.hcalls WHERE meddate >= '01-JAN-2009' and meddate < ' GROUP BY meddate, ctype, btext

  • Alias Names for Column names in the Prompt

    Hi,
    I have a scenario where I am taking column names into prompt. I have used the following SQL in the SQL results under "Show" option of the Prompt.
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By OrderDate"' END FROM " Real Time"
    UNION ALL
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By ShipDate"' END FROM "Real Time"
    My problem here is I am getting the column names into the Prompt as "Orders"."By OrderDate" and "Orders"."By ShipDate", which is not acceptable and readable format for the user. I tried using the alias name in the SQL query this way.
    SELECT (CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By OrderDate"' END) AS "By OrderDate" FROM " Real Time"
    UNION ALL
    SELECT (CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By ShipDate"' END) AS "By ShipDate" FROM "Real Time"
    but it is throwing an error.Is there any way that I can assign an alias name for the column names such as OrderDate and ShipDate in the above SQL.
    Your quick respose is appreciated.
    Thanks,
    Rama

    Change ur
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By OrderDate"' END FROM " Real Time"
    UNION ALL
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By ShipDate"' END FROM "Real Time"
    To
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE By OrderDate END FROM " Real Time"
    UNION ALL
    SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE By ShipDate END FROM "Real Time"
    So that it displays the Name as required
    Then in the Fx for that column in the Report Use '"Orders"."@Presentation variable"'.
    This worked for me Let me know if it worked for you.

  • How to give alias name for group of columns.

    the below is the query to get Columns. But, i need to make single alias name to all the column which i get. I need to get column names also event, domain, entity, bpdid. Above columns should be under single alias name like 'baseMessage'. Please advise on this.
    select (select decode(ICKD_CHR_KY1_ID,'I','New','D','Cancelled','U','Modified') from ICKD where ICKD_APLN_ID = 'CSTCOM' and ICKD_NUM_KY1_ID = 1438227010) event, 'Client' domain, 'CustomerCommunication' entity, 'General' scope, (select ICKD_NUM_KY6_ID from ICKD where ICKD_NUM_KY1_ID = 1438227010 and ICKD_APLN_ID = 'CSTCOM') bpdId from dual;

    ; WITH CTE AS (
        SELECT Case When  sum(b.targetTotal) > 0 then  Sum(b.targetTotal)  
                          else 0
               end as Profttarget,
               Case When  sum(a.salestotal) > 0 then  Sum(a.salestotal)  
                          else 0
               end as Sales,
               Case When  sum(a.salescost) > 0 then  Sum(a.salescost)  
                    else 0
               end as SalesCost
        From  Sales A
        JOIN  Target B A.salesdate = B.salesdate
    SELECT Profttarget- ( Sales - SalesCost ) as TargetRequired
    FROM   CTE
    This gives you a query that runs in SQL Server.
    But it does not look right to me. I don't know what the keys of these tables are, but is it really salesdate in both? And even if it is, the join still looks strange.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • No Column Names in 'Column Alias' Configuration

    I have a column alias action following a transaction call.  I'd like to rename the XML columns coming out of the call.  A Tracer on the transaction call output shows columns but when I configure the Column Alias action, no columns appear in the drop down lists.
    Any ideas?

    Never Mind - I didn't have a reference document assigned correctly.  It works now.

  • SQL query - Alias name (value) as parameter to an Oracle function

    Hi,
    I have a sql query something like
    Select tbl1.valueA, tbl1.valueB, tbl2.valueX, MAX(CASE tbl2.valueY = 'XX' THEN tbl2.valueZ END) AS "ValueZ header", Function(tbl1.valueB, tbl2.valueX, "valueZ header")
    FROM table1 tbl1
    JOIN table2 tbl2 ON tbl1.id = tbl2.tbl1id
    WHERE ...
    my problem is that I need the value from MAX statement as parameter to the function and I have tried to use the alias name (valueZ header) but this is not working. I guess because of some syntax error. Can I use alias name as parameter into the function at all - if - how should I do this?

    Hi,
    user8819407 wrote:
    Hi,
    I have a sql query something like
    Select tbl1.valueA, tbl1.valueB, tbl2.valueX, MAX(CASE tbl2.valueY = 'XX' THEN tbl2.valueZ END) AS "ValueZ header", Function(tbl1.valueB, tbl2.valueX, "valueZ header")
    FROM table1 tbl1
    JOIN table2 tbl2 ON tbl1.id = tbl2.tbl1id
    WHERE ...
    my problem is that I need the value from MAX statement as parameter to the function and I have tried to use the alias name (valueZ header) but this is not working. I guess because of some syntax error. Can I use alias name as parameter into the function at all - if - how should I do this?You can use a column alias in the ORDER BY clause of the same query where it was defined, but that's the only place where you can use it in that query.
    You could repeat the entire MAX (CASE ...) expression as the 3rd argumnet to your function, or you could compute it once in a sub-query, then reference the column alias as often as you like in the super-query, like this:
    WITH     got_valuez_header     AS
         Select  tbl1.valueA
         ,     tbl1.valueB
         ,     tbl2.valueX
         ,     MAX ( CASE
                            WEHN  tbl2.valueY = 'XX'     -- Don't forget the keyword WHEN
                      THEN      tbl2.valueZ
                    END
                  )          AS "ValueZ header"
         FROM         table1     tbl1
         JOIN         table2     tbl2     ON     tbl1.id     = tbl2.tbl1id
         WHERE          ...
         GROUP BY     ...
    Select  tbl1.valueA
    ,     tbl1.valueB
    ,     tbl2.valueX
    ,     "ValueZ header"
    ,     Function_x ( tbl1.valueB     -- FUNCTION is not a good name for a function
                 , tbl2.valueX
                 , "ValueZ header"     -- Case-sensitive
    FROM    got_valuez_header
    ;

  • How can i use this alias name Day1 br 06/09/2005 without " "

    From my application (asp.net), i don't know how to pass alias name "Day1<br>06/09/2005"(with " ")
    I this possible anyother way to use this Day1<br>06/09/2005 alias name without using " "
    select sum(count) Day1<br>06/09/2005 from test
    Millions of thanks in advacne..

    if your alias name for a column contains spaces, it needs to be enclosed in double-quotes.
    is there a real need to have such a column heading? what is the problem in enclosing the alias name in double-quotes?
    SQL*Plus has no problem displaying such a column heading? what issue are you encountering?
    SQL> select sum(sal) "Day1 06/09/2005" from emp ;
    Day1 06/09/2005
              29025
    1 row selected.
    SQL>

  • Column alias error in a query of views

    Hi
    I was trying to workout this query
    create view dept_sal as
    select d.department_name,sum(e.salary)
    from departments d left outer join employees e
    on d.department_id= e.department_id
    group by d.department_name;
    and i recieved this error message .............
    Error at Command Line:2 Column:25
    Error report:
    SQL Error: ORA-00998: must name this expression with a column alias
    00998. 00000 - "must name this expression with a column alias"
    *Cause:   
    *Action:
    I tried to put an alias for sum(e.salary) function and it worked but i dont understand why it is required or is the problem somewhere else and why an alias is needed here ???
    Actually the book hasnt specfied the need for an alias at this place ...so i wanted to know why am getting this error ..
    create or replace view dept_sal as
    select d.department_name,sum(e.salary) as d_sal
    from departments d left outer join employees e
    on d.department_id= e.department_id
    group by d.department_name;
    view DEPT_SAL created.
    Also i wanted to know if i can start a thread each time i want have a problem or can i add my questions to somebody
    else's thread ..
    Thanks
    Jayshree

    Hi, Jayshree,
    to_learn wrote:
    Hi
    I was trying to workout this query
    create view dept_sal as
    select d.department_name,sum(e.salary)
    from departments d left outer join employees e
    on d.department_id= e.department_id
    group by d.department_name;
    and i recieved this error message .............
    Error at Command Line:2 Column:25
    Error report:
    SQL Error: ORA-00998: must name this expression with a column alias
    00998. 00000 - "must name this expression with a column alias"
    *Cause:   
    *Action:
    I tried to put an alias for sum(e.salary) function and it worked but i dont understand why it is required or is the problem somewhere else and why an alias is needed here ???Every column in a table or view must have a unique name. If you don't explicitly specify a name for the output column, Oracle will try to generate one based on the input expression. If the name does not follow the normal rules for identifiers (one of which is that the name can't contain special symbols, like parentheses) then the name must be enclosed in double-quotes.
    Notice that these rules are a little different from the rules about result sets. In the result set of a main query, for example, column names do not have to be unique, and a system-generated name like 'SUM(E.SALARY)" is acceptable.
    Actually the book hasnt specfied the need for an alias at this place ...so i wanted to know why am getting this error ..I can't see which book you're reading. Post a quote. If the book is available on line, post a link, too.
    create or replace view dept_sal as
    select d.department_name,sum(e.salary) as d_sal
    from departments d left outer join employees e
    on d.department_id= e.department_id
    group by d.department_name;
    view DEPT_SAL created.That's the right way to do it.
    Also i wanted to know if i can start a thread each time i want have a problem or can i add my questions to somebody
    else's thread ..It's better to start your own thread.

  • Dynamic alias name in query

    Is it possible to use dynamic alias name in query for interactive report?
    I have this SELECT and I would like to use the parameters used in alias request to build a dynamic crosstab report:
    SELECT p.annee AS "Ann&eacute;e", p.desc_rls AS "RLS",
    SUM(CASE WHEN p.age BETWEEN :P2_AGE1 AND :P2_AGE2 THEN p.pop END) "0-4 ANS",
    SUM(CASE WHEN p.age BETWEEN :P2_AGE3 AND :P2_AGE4 THEN p.pop END) "5-9 ANS",
    SUM(CASE WHEN p.age BETWEEN :P2_AGE5 AND :P2_AGE6 THEN p.pop END) "10-14 ANS"
    FROM pop_rls_isq_111 p
    GROUP BY ROLLUP(p.annee, p.desc_rls);
    Instead of coding "0-4 ANS" as alias, I would like for example use the parameters ":P2_AGE1 - :P2_AGE2 ANS".

    Hi,
    to make your column headings dynamic you can use the substitution syntax in the "Column Heading" property of your IR columns. For example:
    &P2_AGE1. - &P2_AGE2. ANSHope that helps
    Patrick
    My blog: http://www.oracleapex.info/
    New Check out the Oracle APEX Essentials!

  • How to use alias name in where clause

    Hello,
    DECODE (item.inv_type,'OT', (DECODE (item.attribute2, 'STONE', 0, xfer.release_quantity1 * xfer.attribute10)
    'FG', (xfer.release_quantity1 * xfer.attribute10)
    ) matl_val
    In the above code matl_val is alias name i need to use that one in where clause as
    where matl_val > 0
    is this possible or anyother way can anyone help me.

    But the point is as you haven't read the documentation you may miss some valuable points about alias and will soon end with another problem.
    >
    Specify an alias for the column expression. Oracle Database will use this alias in the column heading of the result set. The AS keyword is optional. The alias effectively renames the select list item for the duration of the query. The alias can be used in the order_by_clause but not other clauses in the query.
    >
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#SQLRF01702

  • Problem with column/field names in Oracle resultset being UPPERCASE

    Hi everyone,
    I understand that Oracle DBMS returns all the field names in UPPERCASE in the result set. However this is undesired for my application and I was wondering if there is any workaround for getting the field names in the application in exactly the same format as your select query. Is there any set method which can be called before to control this behavior.
    E.g. select ename as employeename from table_name;
    ORACLE RETURNS --> EMPLOYEENAME
    Required --> employeename
    Please help me
    ..Vinit

    Vinit,
    You can use column aliases in your query -- see Oracle SQL Reference for more details.
    Then you can set some connection property in Oracle JDBC that allows you to obtain the column alias (I think). Check the Oracle JDBC User's Guide and Reference for more details.
    Good Luck,
    Avi.

Maybe you are looking for