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.

Similar Messages

  • ORA-00904 when use column alias in Record Group Query

    Is it possible to use column aliases in Record Group Queries?
    I have a query that runs fine in SQL*Developer, but gives me runtime errors when I use it as a Record Group Query.
    When I use it as a Record Group Query, the Form compiles, but at runtime I receive the following errors:
    FRM-40502: ORACLE error: unable to read list of values
    when I use Help - Display Error, I see:
    ORA-00904:"CHILDNAME":invalid identifier
    The query is something like this
    select decode(complex stuff here) as "childname" ....
    I've tried it with and without the double quotes surrounding the alias name, and have also tried it without using the "as" keyword.
    I would appreciate any suggestions or insights. I'm using Forms 9.0.4.
    Thanks.

    It looks like this is caused by bug 725059:
    "FILTER BEFORE DISPLAY" DOESN'T WORK IF LOV HAS COLUMN ALIASES (TRIAGE1098)
    My LOV does have the Filter Before Display turned on. Here's the text of the bug:
    IF an LOV is created with column aliases in the select statement, (eg: select ename emp_name from emp) and the LOV property "Filter Before Display" is "Yes", THEN when you attempt to filter the LOV at runtime, (eg: type '%' then press the 'Find' button) the internal WHERE clause that forms sends to the database is: WHERE column_alias LIKE '%%' This is incorrect syntax. A client-side sqlnet trace shows this. The correct syntax should be: WHERE column LIKE '%%' . The incorrect syntax results in no rows returned. However no error is displayed by forms to the user.

  • Error in running a query in XSJS - column store error: [2950] user is not authorized :  at ptime/session/dist/RemoteQueryExecution.cc:1354]

    Hi All,
    I get the below error when i load my xsjs file in browser,
    Error while executing query: [dberror(PreparedStatement.executeQuery): 2048 - column store error: column store error: [2950] user is not authorized : at ptime/session/dist/RemoteQueryExecution.cc:1354]
    I am able to execute the same query in  HANA SQL editor
    Please note that ,No Analytical privileges are applied to the view.
    Could you please help solving this issue.
    Regards,
    Logesh Kumar.

    Hay,
    are you using the same Database user for both SQL Editor and XSJS ?
    try the following.
    Before executing the query , display it and copy the same from browser and execute in SQL editor.
    Put the statement in  a try catch block and analyse the exception .
    Sreehari

  • Invalid column Index error - While consuming Calculation view via Native SQL

    Hi Experts,
    I am trying to consume a Calculation view (sql script one) , which has input parameters, via Native SQL in a ABAP program .
    Code snippet for the same would be as follows , Upon execution, it throws an error "Invalid Column Index (8) error " . Can anyone help what could be the issue here ?
    Thanks in Advance,
    Suma
    REPORT ZTEST_HANA2.
    *Report to consume Calculation view (script based) from ABAP
    PARAMETERS: ip_docnr type BELNR_D,
                ip_gjahr type GJAHR,
                ip_bukrs type BUKRS,
                ip_blgr type FAGL_RLDNR.
       DATA: LO_SQL_STMT TYPE REF TO CL_SQL_STATEMENT,
              LO_CONN     TYPE REF TO CL_SQL_CONNECTION,
              LO_RESULT   TYPE REF TO CL_SQL_RESULT_SET,
              LV_SQL      TYPE STRING,
              LR_DATA     TYPE REF TO DATA.
        DATA: LX_SQL_EXC           TYPE REF TO CX_SQL_EXCEPTION,
              LT_SEPMAPPS_CLSDINV  TYPE TABLE OF SEPMAPPS_CLSDINV,
              LV_TEXT              TYPE STRING.
        TRY.
    lv_sql = |SELECT * FROM "_SYS_BIC"."DEMO-ABAP/CA_GET_FI_DATA" | &&
                     |WITH PARAMETERS ('placeholder'= ('$$p_DOCNR$$','{ ip_docnr }'),| &&
                      |'placeholder'=('$$p_GJAHR$$','{ ip_gjahr }')| &&
                      |,'placeholder'= ('$$S_BUKRS$$','{ ip_bukrs }')| &&
                      |,'placeholder'= ('$$p_base_ledger$$','{ ip_blgr }') )| .
             LO_CONN = CL_SQL_CONNECTION=>GET_CONNECTION( ).
             "Create an SQL statement to be executed via the connection
              LO_SQL_STMT = LO_CONN->CREATE_STATEMENT( ).
             "Execute the native SQL query
             LO_RESULT = LO_SQL_STMT->EXECUTE_QUERY( LV_SQL ).
             "Read the result into the internal table lt_sepmapps_clsdinv
             GET REFERENCE OF LT_SEPMAPPS_CLSDINV INTO LR_DATA.
             LO_RESULT->SET_PARAM_TABLE( LR_DATA ).
             LO_RESULT->NEXT_PACKAGE( ).
             LO_RESULT->CLOSE( ).
             LO_CONN->CLOSE( ).
        CATCH CX_SQL_EXCEPTION INTO LX_SQL_EXC.
             LV_TEXT = LX_SQL_EXC->GET_TEXT( ).
             MESSAGE LV_TEXT TYPE 'E'.
        ENDTRY.

    Hi Suma,
    Post the SQL you success run directly on Studio together with error message (even if is the Invalid column index error).
    Check there if the parameters case is working properly... Is it really this confusing options:
    p_GJAHR
    S_BUKRS
    p_base_ledger
    Why not all lower or all upper? Anyhow you must test and find which option works according your modeling
    Regards, Fernando Da Rós

  • Report Query w. Column Alias issue?

    I have this query:
    SELECT
    TXI_IS_PROJECTS.PROJECT_NAME,
    TXI_IS_PROJECTS.PROJECT_DESC,
    TXI_IS_PROJECTS.PROJECT_SIZE,
    TXI_IS_PROJECTS.PROJECT_STATUS,
    (select NLS_INITCAP(name_f || ' ' || name_l) name from TXI_PEOPLE where userid= TXI_IS_PROJECTS.PROJECT_OWNER),
    TXI_IS_PROJECTS.SYSTEM_OWNER,
    TXI_IS_PROJECTS.CREATE_DATE,
    TXI_IS_PROJECTS.SPEC_REVIS,
    TXI_DOCUMENTS.NAME
    FROM TXI_IS_PROJECTS
    INNER JOIN TXI_DOCUMENTS ON TXI_DOCUMENTS.PROJECT_ID = TXI_IS_PROJECTS.PROJECT_ID
    INNER JOIN TXI_DOCUMENT_SIGNOFF ON TXI_DOCUMENT_SIGNOFF.DOC_ID = TXI_DOCUMENTS.ID
    WHERE TXI_DOCUMENT_SIGNOFF.SIGN_OFF_ID = :P9_SIGN_OFF_ID;
    The issue with this line:
    (select NLS_INITCAP(name_f || ' ' || name_l) name from TXI_PEOPLE where userid= TXI_IS_PROJECTS.PROJECT_OWNER),
    It's giving me this error:
    query column #5 ((SELECTNLS_INITCAP(NAME_F||''||NAME_L)NAMEFROMTXI_PEOPLEWHEREUSERID=TXI_IS_PROJECTS.PROJECT_OWNER)) is invalid, use column alias
    I've tried various ways and it's still not working.

    SELECT
      TXI_IS_PROJECTS.PROJECT_NAME,
      TXI_IS_PROJECTS.PROJECT_DESC,
      TXI_IS_PROJECTS.PROJECT_SIZE,
      TXI_IS_PROJECTS.PROJECT_STATUS,
      (select NLS_INITCAP(name_f || ' ' || name_l) name
       from TXI_PEOPLE
       where userid= TXI_IS_PROJECTS.PROJECT_OWNER) as "My Column",
      TXI_IS_PROJECTS.SYSTEM_OWNER,
      TXI_IS_PROJECTS.CREATE_DATE,
      TXI_IS_PROJECTS.SPEC_REVIS,
      TXI_DOCUMENTS.NAME
    FROM TXI_IS_PROJECTS
      INNER JOIN TXI_DOCUMENTS ON TXI_DOCUMENTS.PROJECT_ID = TXI_IS_PROJECTS.PROJECT_ID
      INNER JOIN TXI_DOCUMENT_SIGNOFF ON TXI_DOCUMENT_SIGNOFF.DOC_ID = TXI_DOCUMENTS.ID
    WHERE TXI_DOCUMENT_SIGNOFF.SIGN_OFF_ID = :P9_SIGN_OFF_ID;<br>
    as "My Column"<br><br>
    I just recreated it and that worked.<br><br>
    chet

  • Error in pakcage table or view does not exist but on sql prompt query works

    Hi
    Can any one help me to understand the error of ORA-00942: table or view does not exist while compiling the package on Oracle 9.2.0.4.0
    The below package compiled in system user and trying to query on view v$session_wait however getting below error.
    PACKAGE BODY SYSTEM.PK_DB_ALERT
    On line: 212
    PL/SQL: ORA-00942: table or view does not exist
    I can execute same query mentioned below from sql prompt from system user and it works fine however it doesn't like from package, Please advice, thank you in advance.
    SELECT SID, seq#, event, wait_time
    FROM v$session_wait
    WHERE event NOT LIKE 'SQL*Net%' AND wait_time <> 0
    ORDER BY 2

    SDD wrote:
    Hi
    Can any one help me to understand the error of ORA-00942: table or view does not exist while compiling the package on Oracle 9.2.0.4.0Which means package owner is granted select on view not directly but via roles. However, roles are ignored by definer rights packages/stored procedures/stored functions/triggers... You need to grant package owner select on view directly.
    SY.
    Edited by: Solomon Yakobson on Jan 21, 2010 4:06 AM

  • How to use : bind character in DB adapter Select Query SOA11g. Getting Error code :17003 .java.sql.SQLException: Invalid column index error

    Hi All,
    The Actual query to perform is below.
    SELECT name,number from emp  WHERE CASE WHEN :1='T' AND term_date IS Not NULL THEN 1 WHEN :1='A' AND term_date IS NULL THEN 1 WHEN :1='ALL' THEN 1 ELSE  1 END = 1;
    I have tried in DB adapter like below as a parameter for :1 as #vInputParam
    SELECT name,number from emp  WHERE CASE WHEN #vInputParam='T' AND term_date IS Not NULL THEN 1 WHEN #vInputParam='A' AND term_date IS NULL THEN 1 WHEN #vInputParam='ALL' THEN 1 ELSE  1 END = 1;
    Getting Error code :17003 .java.sql.SQLException: Invalid column index error.
    Please suggest me on using ':' bind character in DB adapter Select Query SOA11g.
    Can someone help me on this please?
    Thanks,
    Hari

    Hi,
    Could you please make sure your binding style(Oracle Positional,Oracle named..etc) of the Seeded VO and Custom Vo are same.
    This is the option you will get when you are extending your vo. So make sure that both are same.
    You can refer the below link too
    VO extension leads to "Invalid column index" exception
    Thanks
    Bharat

  • Query doesn't work in APD, Error: column store error: fail to create scenario: [340 2048

    Hi Experts,
    We got a problem here.
    We have a query ran without any problems in RSRT. But when I try to put it as data sources(infoprovider) in APD.
    I got following error:
    column store error: fail to create scenario: [340 2048
    We are in BW731006 & ABAP731006.
    Any advise?
    Thanks in advance!
    Tengran

    Hi,
    Can you check this part in error mentioned by clicking as highlighted in red box. It will give you a correct idea about the issue ::
    Also share the detailed error with us as well.
    Best Regards,
    Arpit

  • Oracle DB Query Generating Invalid Column Index error

    Dear All,
    Apologies for a question on this rather basic error but I don't understand why i'm experiencing the behaviour described.
    The piece of code below connects to a database, runs a query, then attempts to display the contents of the resultset. I understand from other posts on the topic that the query I am executing (INSERT INTO table VALUES (...)) as in the comments below needs to have autocommit disabled to allow me to access the resultset without the transaction closing.
      public void runQuery(String query) throws Exception {   Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection(database, username, password); con.setAutoCommit(false); Statement st = con.createStatement();         ResultSet rs = st.executeQuery (query);         // "select * from user_tables"         // "INSERT INTO BH VALUES ('','2.25','Dark Red','Samsonite','4987638762')"         while (rs.next()) {         System.out.print (rs.getString(1)); // Exception thrown here     }         con.commit(); st.close();   con.close();   }
    I have removed try {} catch {} error handling for clarity.
    I am receiving the invalid column index error from the indicated line, which clearly suggest column 1 doesn't exist, however if i run the same query in another tool, something like the following is returned:
    Rows Affected
    1
    The query is being received by the database as the row ends up in the table intact, so I am clearly missing something about how to access the resultset correctly.
    I am guessing that I am either misusing/misunderstanding the autocommit option or that the resultset is different to what I am expecting...
    Can someone please shed a little light?
    Many thanks!
    George

    Ok, I've done a little more digging, and i've come to the conclusion that an INSERT query doesn't return a resultset (or returns an empty one)
    Could someone with a little more knowledge confirm this as I've had little luck finding an explicit yes or no from the web!
    Many Thanks in advance...

  • Alternative to Column alias in a Where clause

    This question is related to earlier thread: https://forums.oracle.com/thread/2578735
    The below query gives me millions of records which is unacceptable from performance point of view. I am only interested in Tickets that are closed in a particular week. I cannot use closed_date in the inner query as closed_date >= '08/18/2013' AND closed_date < '08/24/2013' because close_date is column alias. I can't put it in the where condition of parent query because it makes no sense because by the time control raches to WHERE condition of parent query the subquery would have already fetched millions of records.
    Any alternative to this?
    SELECT  b.ticket_id, b.ticket_status, b.created_date, b.closed_status, b.closed_date 
      FROM 
      (SELECT  ticket_id, ticket_status, created_date, lead(ticket_status) over (partition BY ticket_id order by created_date) AS closed_status, lead(created_date) over (partition BY ticket_id order by created_date) AS closed_date 
      FROM cc_ticket_history 
      WHERE ticket_status IN ('NEW', 'REOPENED', 'CLOSED')                                   /* AND closed_date >= '08/18/2013' AND closed_date < '08/24/2013'      gives error */
      ) b 
      WHERE b.ticket_status != 'CLOSED' and b.closed_status = 'CLOSED                 /*AND b.closed_date >= '08/18/2013' AND b.closed_date < '08/24/2013'     -- makes no sense */';
    Ticket_ID
    TICKET_STATUS
    CREATED_DATE
    CLOSED_STATUS
    CLOSED_DATE
    D21207155
    NEW
    06/28/2013 17.28.59.000000000
    CLOSED
    06/28/2013 18.54.23.000000000
    D21207155
    REOPENED
    07/02/2013 19.55.04.000000000
    CLOSED
    07/02/2013 23.06.16.000000000

    Ora-aff wrote:
    Point Noted.
    It's not just a point, it's a fundamental bug in the code.
    Consider this...
    SQL> ed
    Wrote file afiedt.buf
      1  select 'Wrong' from dual
      2* where '03/18/2012' > '02/15/2013'
    SQL> /
    'WRON
    Wrong
    Comparing strings is not the same as comparing dates.
    SQL> ed
    Wrote file afiedt.buf
      1  select 'Wrong' from dual
      2* where to_date('03/18/2012','MM/DD/YYYY') > to_date('02/15/2013','MM/DD/YYYY')
    SQL> /
    no rows selected

  • Database column alias problem

    When joining the firstname and surname fields in my inital SQL query of my interactive report i.e
    INITCAP(INDSNAME)||' '||INITCAP(INDFNAME) AS FULLNAME,
    When clicking through to the record detail page I am getting the following error from the page item where in the source I am specifying FULLNAME under Source value or expression
    Column FULLNAME not found in table MYTABLENAME
    How can I get around this?
    Many Thanks

    Hi Bas
    Thanks - it will just be a view as basically I just want to print the data via jasper
    In my IA report under column attributes there is one called FULLNAME which is derived from INITCAP(INDSNAME)||' '||INITCAP(INDFNAME) AS FULLNAME,
    So how can I get the data displayed in the FULLNAME column in the IA report into a single record view.  At the moment my IA report the Link Column is currently linked to a 'Link to custom target'
    the target is a 'Page in this Application'  in this case page 9
    and in Item1 under Name the value is P9_ROWID and the value is #ROWID#
    Database column alias problem 

  • 5200 : Error in executing  query -- Hyperion Financial Reporting

    Problem in accessing the Hyperion Financial Reports.User is having full access and able to access all the folders except one folder(Legal Folder reports). We are getting 5200: Error Executing the query error. Recently we have upgraded Hyperion to 11.1.1.3 version . Before upgrade user is not facing the problem. After Upgrade user is getting these errors while accessing the reports. we did research and found in "Error 5200: Error Executing Query" When Viewing Financial Reporting (FR) Reports". Is this error is relevant to the Information provided in Metalink and also can you please tell us is there any impact on doing the solution provided in the below. Why is this error is coming is any preferences needs to be changed.Please help us on this.
    Error Description:
    5200: Error executing query
    Servername/ApplicationName/DatabaseName/Error(1007090) Unknown Member name [Current Point of view for years] in Outline Query
    Doc ID 1107142.1:
    Possible Cause 1:
    If members have recently been added, moved, or deleted from the data source, Essbase, HFM, or Planning, the existing User POV records become out of sync.
    The User Point of View record uses indexing to identify the member. If the index changes because of changes in the outline, the User Point of View record no longer points to the correct location in the outline.
    To resolve the issue, you need to run the ManageUserPOV utility on a Windows server that has the Financial Reporting Reports Server, or in a Unix or Linux environment, has the Financial Reporting Print Server installed.
    You will need to provide a BIPlus Global Administrator user ID and password to run the utility.
    The utility will provide the correct syntax to run the command.
    1. In \Hyperion\products\biplus\bin\ManageUserPOV.properties, specify the following parameters:
    a. ReportServer
    b. DatasourceUser
    c. DatasourcePassword
    d. User
    e. Datasource (You can find the datasource in Workspace under Tools>Database Connection Manager in the Name column.)
    2. From the command line, cd to Hyerion\products\biplus\bin
    3. Type in "ManageUserPOV" without the quotes. The executable will read the parameters previously set in the ManageUserPOV.properties file.
    Thanks,
    Naresh.

    Take a look at this: http://adistrategies.com/index.php?loc=knowledge1&item=291
    Hope it helps.
    Mehmet

  • Resolve column names in a sql Query

    Hi Folks,
         I’m upgrading an application and there are database columns that have major changes that could affect production reports. I would like to survey v$SQL for a few days to see if these columns are affected. Here’s the problem.
    Looking at a SQL query to determine which columns are used is not nearly as easy as it sounds. Are there any oracle functions or 3rd party tools that can be used to list the columns used by a sql query? (this gets extremely tricky when subqueries become involved)
    For instance.
    select
    name, b.dep_id, employee_id
    From emp a
    Inner join v_department b on a.dep_id=b.dep_id
    Columns used:+
    Emp.name+
    Departments.dep_id (under the view)+
    Emp.employee_id+
    Emp.dep_id (from the join)+

    If you're on > 10g, you can use dbms_xplan with "all" option.
    It shows "column projection information" which is exactly what you want.
    UKJA@ukja102> set serveroutput on
    UKJA@ukja102>
    UKJA@ukja102> drop table t1 purge;
    Table dropped.
    Elapsed: 00:00:00.03
    UKJA@ukja102> create table t1(c1 int, c2 int);
    Table created.
    Elapsed: 00:00:00.03
    UKJA@ukja102>
    UKJA@ukja102> explain plan for
      2  select
      3    t1.c1, t1.c2, v.cnt
      4  from t1,
      5    (select /*+ no_merge */ c1, count(*) as cnt
      6        from t1
      7        group by c1) v
      8  where
      9    t1.c1 = v.c1
    10  ;
    Explained.
    Elapsed: 00:00:00.01
    UKJA@ukja102>
    UKJA@ukja102> @plan_all
    UKJA@ukja102> select * from table(dbms_xplan.display(null,null,'all'))
      2  /
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 536125944                                                     
    | Id  | Operation            | Name | Rows  | Bytes | Cost (%CPU)| Time     |  
    |   0 | SELECT STATEMENT     |      |     1 |    52 |     6  (34)| 00:00:01 |  
    |*  1 |  HASH JOIN           |      |     1 |    52 |     6  (34)| 00:00:01 |  
    |   2 |   TABLE ACCESS FULL  | T1   |     1 |    26 |     2   (0)| 00:00:01 |  
    |   3 |   VIEW               |      |     1 |    26 |     3  (34)| 00:00:01 |  
    |   4 |    HASH GROUP BY     |      |     1 |    13 |     3  (34)| 00:00:01 |  
    |   5 |     TABLE ACCESS FULL| T1   |     1 |    13 |     2   (0)| 00:00:01 |  
    Query Block Name / Object Alias (identified by operation id):                  
       1 - SEL$1                                                                   
       2 - SEL$1 / T1@SEL$1                                                        
       3 - SEL$2 / V@SEL$1                                                         
       4 - SEL$2                                                                   
       5 - SEL$2 / T1@SEL$2                                                        
    Predicate Information (identified by operation id):                            
       1 - access("T1"."C1"="V"."C1")                                              
    Column Projection Information (identified by operation id):                    
       1 - (#keys=1) "T1"."C1"[NUMBER,22], "T1"."C2"[NUMBER,22],                   
           "V"."CNT"[NUMBER,22]                                                    
       2 - "T1"."C1"[NUMBER,22], "T1"."C2"[NUMBER,22]                              
       3 - "V"."C1"[NUMBER,22], "V"."CNT"[NUMBER,22]                               
       4 - (#keys=1) "C1"[NUMBER,22], COUNT(*)[22]                                 
       5 - "C1"[NUMBER,22]                                                         
    Note                                                                           
       - dynamic sampling used for this statement                                  
    40 rows selected.
    Elapsed: 00:00:00.01
    UKJA@ukja102>
    UKJA@ukja102>
    UKJA@ukja102> @end
    UKJA@ukja102> set echo offDion Cho

  • Syntax error in a query

    Hello all
    I have a query, and i got this error , any idea ?
    Error starting at line 1 in command:
    WITH continent_table  AS
    SELECT     en.country,en.continent
            ,ROW_NUMBER() OVER (PARTITION BY en.country ORDER BY en.percent DESC) ran
         FROM     encompasses en
         where ran=1
    select co.name,con.continent,co.population/co.area as pop_density,ec.GDP,pop.Population_Growth,pop.infant_mortality,pol.government
    from country co
    join economy ec
    on co.code=ec.country
    join population pop
    on co.code=pop.country
    join politics pol
    on co.code=pol.country
    join continent_table  con
    on co.code=con.country
    Error at Command Line:6 Column:8
    Error report:
    SQL Error: ORA-00904: "RAN": invalid identifier
    00904. 00000 -  "%s: invalid identifier"
    *Cause:   
    *Action:im using oracle 11g
    thank you in advance
    best,
    david

    >
    So is it still possible to use this selection as a view? because i can run it but i can not use it to create a view
    i think because i have with xx as structure, i don't know
    >
    I don't know either since you didn't post your 4 digit Oracle version. You probably just have an error in your query.
    This works for me using vanilla 11.2.0.1.0:
    create view v_emp as
    WITH q AS
    SELECT empno, deptno, ename
            ,ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY deptno) r_id
        FROM    emp
    q1  AS
    SELECT * from q where r_id < 3
    SELECT * from q1
    select * from v_emp
    EMPNO     DEPTNO     ENAME     R_ID
    7782     10     CLARK     1
    7934     10     MILLER     2
    7369     20     SMITH     1
    7902     20     FORD     2
    7499     30     ALLEN     1
    7521     30     WARD     2

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for