Column Alias Logic!

Hi,
I'm in the process of learning Oracle9i SQL and I don't
understand why column alias are not allowed in a where
and group by clause but are allowed in the order by
clause? To me this makes no sense and I have noticed that
that there are a lot of conditions in SQL that make no
sense (ie. this is allowed in a from clause but not the where clause unless using this function or that). Too
many conditions and restrictions are in place!

Exactly. Database vendors make their own enhancements and additions, but if you don't like the core SQL language you should take it up with ANSI.
That FLAGGER switch is neat:
SQL> set flagger off
SQL> SELECT DECODE('x','y','z','Using default') AS example1 FROM dual;
EXAMPLE1
Using default
SQL> SELECT CASE 'x' WHEN 'y' THEN 'z' ELSE 'Using default' END AS example2 FROM dual;
EXAMPLE2
Using default
SQL> set flagger full
SQL> SELECT DECODE('x','y','z','Using default') AS example1 FROM dual;
SELECT DECODE('x','y','z','Using default') AS example1 FROM dual
ERROR at line 1:
ORA-00097: use of Oracle SQL feature not in SQL92 Full Level
ORA-06550: line 2, column 8:
PLS-01416: Use of <id> (<value>...) here
SQL> SELECT CASE 'x' WHEN 'y' THEN 'z' ELSE 'Using default' END AS example2 FROM dual;
EXAMPLE2
Using default

Similar Messages

  • Use column alias in another calculation

    Database:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
    Is there a way to use a column alias in an another calculation within the
    same query? Since I am using some long and complex logic to compute total1
    and total2, I don't want to repeat the same logic to compute the ratio of
    those two columns. do you have any suggestion other than nested sub-query or view?
    select
    total1 = sum(case(long complex logic)),
    total2 = sum(case(another long complex logic)),
    ratio = total1/total2
    thanks in advance

    Jimmie_M wrote:
    Database:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
    Is there a way to use a column alias in an another calculation within the
    same query? Since I am using some long and complex logic to compute total1
    and total2, I don't want to repeat the same logic to compute the ratio of
    those two columns. do you have any suggestion other than nested sub-query or view?
    select
    total1 = sum(case(long complex logic)),
    total2 = sum(case(another long complex logic)),
    ratio = total1/total2
    thanks in advanceHi,
    Use oracle's with clause
    WITH test_data
    AS
    SELECT sum(case(long complex logic)) total1,
    sum(case(another long complex logic)) total2
    from your_table_name
    SELECT total1/total2
    from test_data
    WHERE....Regards,
    Achyut Kotekal

  • Will deleting a column at logical schema delete the same at physical level by DDL Sync?

    Will deleting a column at logical schema delete the same at physical level by DDL Sync?

    Hi David,
    First of all thanks for your quick response and for your help logging the enhancement request,
    I am testing more or less your suggestion but I  am not sure if I understood exactly what you mean,
    1)I imported from data dictionary in a new model and into the options menu on the schema select screen I un-ckecked partitions and triggers,
    I guessed that the import should not get from the data dictionary the information about the partitions but the result is that the tables partitioned (by list in this case) are partitioned by range without fields into the physical model on SDDM,
    2)I select one of the tables modify a NO partitioned option and propagate the option for the rest of the tables
    3) I imported again from data dictionary but this time I included the partitions into the option menu on select schema screen,
    into tabular view on compare models screen I can select all the tables with different partitioned option, also I can change for "list partitions" and select only the partitions that I want to import.
    So I have a solution for my problem, thanks a lot for your suggestion
    The second step I'm not sure is needed or maybe I can avoid the step with some configuration setting in any of the preferences screen,
    if not, I think the options to not include partitions into select schema screen are not so clear, at least for me,
    please, could you confirm me if a way to avoid the second step exists or if I misunderstood this option?
    thanks in advance

  • 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.

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Comma in report column alias breaking PDF Printing?

    It appears that some (but not all) special characters (e.g., a comma) in a report column alias causes an error when using PDF printing under "Print Attributes" for reports.
    This query works fine:
    select sysdate as "Date Today" from dual
    But the query below causes the error "Adobe could not open 'report[1].pdf' because it is either not a supported file type or because the file has been damaged...":
    select sysdate as "Date, Today" from dual
    Does anyone know a work-around? My real alias is "Lastname, Firstname" so I would like to keep the comma!
    We're using APEX 3.0.1 and PDF printing with Apache FOP.
    Thanks ahead of time.
    Cindy

    Hi Cindy,
    why not use the "Heading" property of a report column to show a speaking column heading? The column alias isn't really intended for that purpose.
    Set the "Heading Type" to "Custom" then you are able to change them for each column.
    Patrick
    My APEX Blog: http://inside-apex.blogspot.com
    The ApexLib Framework: http://apexlib.sourceforge.net
    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/

  • Column alias

    Hi,
    in oracle express, on a report querry region I give this :
    select 'PINS - # of times an item in the library cache was executed - '||
    sum(pins),
    'RELOADS - # of library cache misses on execution steps - '||
    sum (reloads),
    'RELOADS / PINS * 100 = '||round((sum(reloads) / sum(pins) *
    100),2)||'%'
    from v$librarycache
    But I receive :
    1 error has occurred
    query column #1 ('PINS-#OFTIMESANITEMINTHELIBRARYCACHEWASEXECUTED-'||SUM(PINS)) is invalid, use column alias
    Any idea ? Any help ?
    Many thanks.

    You need to define column aliases.
    SQL> SELECT 'PINS - # of times an item in the library cache was executed - ' || SUM (pins) AS LibRatio,
      2         'RELOADS - # of library cache misses on execution steps - ' || SUM (reloads) AS MissRatio,
      3         'RELOADS / PINS * 100 = ' || ROUND ((SUM (reloads) / SUM (pins) * 100), 2) || '%' AS Ratio
      4    FROM v$librarycache
      5  ;
    LIBRATIO                                                                                               MISSRATIO
    PINS - # of times an item in the library cache was executed - 10455253                                 RELOADS - #

  • 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
    )

  • Column alias results in ORA-00972

    Hi,
    I am using Eclipselink v1.0.2 on glassfish.
    I have a query where I have set the maxResults to 1 like so:
    this.entityManager.createQuery("SELECT t FROM Tbl t where t.name='271040300018**'")
                        .setMaxResults(1)
                        .getResultList();
    The resultant query contains a column alias that has more than 30 characters which causes an ORA-00972 error. I've noticed that if I don't call setMaxResults the query does not contain aliased column names. Is there a way to either make sure that the query generator does not generate invalid column names or get it to not alias columns when I have a result set limit?
    Thanks,
    Drew
    Edited by: user10816727 on Jan 27, 2009 1:02 PM

    Here is the generated query with the problematic aliases bolded. Note that I cannot change the length of the non aliased column names as a workaround.
    Thanks,
    Drew
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ a.*, ROWNUM rnum FROM (SELECT new_drug_status AS new_drug_status1, message AS message2, message_stop_date AS message_stop_date3, termination_date AS termination_date4, cms_drug_status AS cms_drug_status5, drug_status_ovrd AS drug_status_ovrd6, min_rx_qty AS min_rx_qty7, max_rx_qty AS max_rx_qty8, min_rx_days AS min_rx_days9, max_rx_days AS max_rx_days10, max_dose AS max_dose11, min_age AS min_age12, max_age AS max_age13, min_age_dob_opt AS min_age_dob_opt14, max_age_dob_opt AS max_age_dob_opt15, sex_restriction AS sex_restriction16, qty_dsup_compare_rule AS qty_dsup_compare_rule17, max_qty_over_time AS max_qty_over_time18, rx_qty_opt_multiplier AS rx_qty_opt_multiplier19, specialty_drug_ind AS specialty_drug_ind20, ssb_copay_tier AS ssb_copay_tier21, msb_copay_tier AS msb_copay_tier22, bga_copay_tier AS bga_copay_tier23, gen_copay_tier AS gen_copay_tier24, bng_sngl_inc_exc_ind AS bng_sngl_inc_exc_ind25, bng_multi_inc_exc_ind AS bng_multi_inc_exc_ind26, bga_inc_exc_ind AS bga_inc_exc_ind27, gen_inc_exc_ind AS gen_inc_exc_ind28, merge_defaults AS merge_defaults29, otc_chk_flag AS otc_chk_flag30, physician_list AS physician_list31, physician_specialty_list AS physician_specialty_list32, alternate_price_schedule AS alternate_price_schedule33, alternate_copay_sched AS alternate_copay_sched34, max_rxs_patient AS max_rxs_patient35, max_rxs_time_flag AS max_rxs_time_flag36, copay_network_ovrd AS copay_network_ovrd37, max_days_supply_opt AS max_days_supply_opt38, max_days_over_time AS max_days_over_time39, reject_only_msg_flag AS reject_only_msg_flag40, max_qty_per_fill AS max_qty_per_fill41, days_supply_opt_multiplier AS days_supply_opt_multiplier42, recalc_price_schedule AS recalc_price_schedule43, alternate_pricing_strategy AS alternate_pricing_strategy44, alternate_copay_strategy AS alternate_copay_strategy45, max_days_over_time_drug_list AS max_days_over_time_drug_list46, max_qty_over_time_drug_list AS max_qty_over_time_drug_list47, max_rxs_patient_drug_list AS max_rxs_patient_drug_list48, max_price_patient_drug_list AS max_price_patient_drug_list49, max_rxs_time_flag_mult AS max_rxs_time_flag_mult50, max_price_patient AS max_price_patient51, max_price_time_flag AS max_price_time_flag52, max_price_patient_opt AS max_price_patient_opt53, max_price_patient_split_opt AS max_price_patient_split_opt54, max_price_patient_pricing_opt AS max_price_patient_pricing_opt55, max_price_patient_split_copay AS max_price_patient_split_copay56, max_price_patient_copay AS max_price_patient_copay57, misc_data_1 AS misc_data_158, misc_data_2 AS misc_data_259, misc_data_3 AS misc_data_360, misc_data_4 AS misc_data_461, misc_data_5 AS misc_data_562, user_id_created AS user_id_created63, gpi_exception_list AS gpi_exception_list64, pharmacy_country_code AS pharmacy_country_code65, generic_product_id AS generic_product_id66, pharmacy_state AS pharmacy_state67, effective_date AS effective_date68, process_rule AS process_rule69, apply_on_group_renewal_ind AS apply_on_group_renewal_ind70 FROM PHIDBA.gpi_exception_lists WHERE (generic_product_id = ?)) a WHERE ROWNUM <= ?) WHERE rnum > ?
         bind => [271040300018**, 1, 0]

  • 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

  • Problem with column alias: Unknown column 'avg_rating' in 'where clause'

    Hello,
    I have a basic sql statement as follows:
    SELECT
    e.establishment_id,
    e.establishment_name,
    avg(r.rating) avg_rating
    FROM
    establishment e,
    rating r,
    comment com,
    establishment_country ec,
    country_ref cou
    where
    etc...
    and avg_rating >= 1
    and 0=0
    group by e.establishment_id
    order by e.establishment_idI have used a column alias for "avg(r.rating)" and named it "avg_rating".
    It works in my Mysql Query browser without problem but when I run it from Java I get this:
    java.sql.SQLException: Unknown column 'avg_rating' in 'where clause'
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2988)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2917)
        at com.mysql.jdbc.Statement.executeQuery(Statement.java:824)
        at org.jboss.resource.adapter.jdbc.WrappedStatement.executeQuery(WrappedStatement.java:145)
        at arcoiris.SearchSessionBean.performSearch(SearchSessionBean.java:73)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
        at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
        at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
        at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
        at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
        at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
        at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
        at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
        at org.jboss.ejb.Container.invoke(Container.java:873)
        at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:415)
        at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:88)
        at $Proxy172.performSearch(Unknown Source)
        at arcoiris.SearchManagedBean.performSearch(SearchManagedBean.java:171)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
        at javax.faces.component.UICommand.broadcast(UICommand.java:312)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:595)Can anyone help please?
    Thanks in advance,
    Julien Martin.

    I am having the similiar problem, the query in java creator IDE works fine after i upgraded the J-connector and changed DataSource type for MySQL to mysql-connector-java-5.0.4-bin.jar. but still i cannot bind any control in the form to the aliased column. this is really frustrating. can anyone from Sun Developer explain?
    THX

  • 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 

  • Group by with column alias does not work?

    Hello,
    The column alias is not working in the group clause?
    select col1,col2-col3 "col23", sum(col4)
    from table1
    group by col1,col23
    Error is col23 is invalid identifier.
    Thank you.

    I guess it's the double quotes around bonus:
    SQL> select empno, deptno, sum(bonus)
      2  from
      3  (
      4     select empno, (sal + 500) bonus, deptno
      5     from emp
      6  )
      7  group by empno, deptno
      8  ;
                   EMPNO               DEPTNO           SUM(BONUS)
                    7900                   30                 1450
                    7369                   20                 1300
                    7499                   30                 2100
                    7521                   30                 1750
                    7566                   20                 3475
                    7654                   30                 1750
                    7698                   30                 3350
                    7782                   10                 2950
                    7788                   20                 3500
                    7839                   10                 5500
                    7844                   30                 2000
                    7876                   20                 1600
                    7902                   20                 3500
                    7934                   10                 1800
    14 rows selected.

  • 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

  • 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.

Maybe you are looking for