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]

Similar Messages

  • 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

  • IMPDP SQLFILE : multibyte characters in constraint_name leads to ORA-00972

    Hi,
    I'm actually dealing with constraint_name made of multibyte characters (for example : constrain_name='VALIDA_CONFIRMAÇÃO_PREÇO13').
    Of course this Bad Idea® is inherited (I'm against all the fancy stuff like éàù in filenames and/or directories on my filesystem....)
    The scenario is as follows :
    0 - I'm supposed to do a "remap_schema". Everything in the schema SCOTT should now be in a schema NEW_SCOTT.
    1 - The scott schema is exported via datapump
    2 - I do an impdp with SQLFILE in order to get all the DDL (table, packages, synonyms, etc...)
    3 - I do some sed on the generated sqlfile to change every occurence of SCOTT to NEW_SCOTT (this part is OK)
    4 - Once the modified sqlfile is executed, I do an impdp with DATA_ONLY.
    (The scenario was imagined from this thread : {message:id=10628419} )
    I'm getting some ORA-00972: identifier is too long at step 4 when executing the sqlfile.
    I see that some DDL for constraint creation in the file (generated at step#2) is written as follow :ALTER TABLE "TW_PRI"."B_TRANSC" ADD CONSTRAINT "VALIDA_CONFIRMAÃÃO_PREÃO14" CHECK ...Obviously, the original name of the constraint with cedilla and tilde gets translated to something else which is longer than 30 char/byte...
    As the original name is from Brazil, I also tried do add an EXPORT LANG=pt_BR.UTF-8 in my script before running the impdp for sqlfile. This didn't change anything. (the original $LANG is en_US.UTF-8)
    In order to create a testcase for this thread, I tried to reproduce on my sandbox database... but, there, I don't have the issue. :-(
    The real system is an 4-nodes database on Exadata (11.2.0.3) with NLS_CHARACTERSET=AL32UTF8.
    My sandbox database is a (nonRAC) 11.2.0.1 on RHEL4 also AL32UTF8.
    The constraint_name is the same on both system : I checked byte by byte using DUMP() on the constraint_name.
    Feel free to shed any light and/or ask for clarification if needed.
    Thanks in advance for those who'll take on their time to read all this.
    I decided to include my testcase from my sandbox database, even if it does NOT reproduce the issue +(maybe I'm missing something obvious...)+
    I use the following files.
    - createTable.sql :$ cat createTable.sql
    drop table test purge;
    create table test
    (id integer,
    val varchar2(30));
    alter table test add constraint VALIDA_CONFIRMAÇÃO_PREÇO13 check (id<=10000000000);
    select constraint_name, lengthb(constraint_name) lb, lengthc(constraint_name) lc, dump(constraint_name) dmp
    from user_constraints where table_name='TEST';- expdpTest.sh :$ cat expdpTest.sh
    expdp scott/tiger directory=scottdir dumpfile=testNonAscii.dmp tables=test- impdpTest.sh :$ cat impdpTest.sh
    impdp scott/tiger directory=scottdir dumpfile=testNonAscii.dmp sqlfile=scottdir:test.sqlfile.sql tables=testThis is the run :
    [oracle@Nicosa-oel test_nonAsciiColName]$ sqlplus scott/tiger
    SQL*Plus: Release 11.2.0.1.0 Production on Tue Feb 12 18:58:27 2013
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> @createTable
    Table dropped.
    Table created.
    Table altered.
    CONSTRAINT_NAME                  LB       LC
    DMP
    VALIDA_CONFIRMAÇÃO_PREÇO13             29         26
    Typ=1 Len=29: 86,65,76,73,68,65,95,67,79,78,70,73,82,77,65,195,135,195,131,79,95
    ,80,82,69,195,135,79,49,51
    SQL> exit
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    [oracle@Nicosa-oel test_nonAsciiColName]$ ./expdpTest.sh
    Export: Release 11.2.0.1.0 - Production on Tue Feb 12 19:00:12 2013
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** directory=scottdir dumpfile=testNonAscii.dmp tables=test
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 0 KB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    . . exported "SCOTT"."TEST"                                  0 KB       0 rows
    Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
    Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
      /home/oracle/scott_dir/testNonAscii.dmp
    Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 19:00:22
    [oracle@Nicosa-oel test_nonAsciiColName]$ ./impdpTest.sh
    Import: Release 11.2.0.1.0 - Production on Tue Feb 12 19:00:26 2013
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Master table "SCOTT"."SYS_SQL_FILE_TABLE_01" successfully loaded/unloaded
    Starting "SCOTT"."SYS_SQL_FILE_TABLE_01":  scott/******** directory=scottdir dumpfile=testNonAscii.dmp sqlfile=scottdir:test.sqlfile.sql tables=test
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Job "SCOTT"."SYS_SQL_FILE_TABLE_01" successfully completed at 19:00:32
    [oracle@Nicosa-oel test_nonAsciiColName]$ cat scott_dir/test.sqlfile.sql
    -- CONNECT SCOTT
    ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';
    -- new object type path: TABLE_EXPORT/TABLE/TABLE
    CREATE TABLE "SCOTT"."TEST"
       (     "ID" NUMBER(*,0),
         "VAL" VARCHAR2(30 BYTE)
       ) SEGMENT CREATION DEFERRED
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 COMPRESS FOR OLTP LOGGING
      TABLESPACE "MYTBSCOMP" ;
    -- new object type path: TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    ALTER TABLE "SCOTT"."TEST" ADD CONSTRAINT "VALIDA_CONFIRMAÇÃO_PREÇO13" CHECK (id<=10000000000) ENABLE;I was expecting to have the cedilla and tilde characters displayed incorrectly....
    Edited by: Nicosa on Feb 12, 2013 7:13 PM

    Srini Chavali wrote:
    If I understand you correctly, you are unable to reproduce the issue in the test instance, while it occurs in the production instance. Is the "schema move" being done on the same database - i.e. you are "moving" from SCOTT to NEW_SCOTT on the same database (test to test, and prod to prod) ? Do you have to physically move/copy the dmp file ? Hi Srini,
    On the real system, the schema move will be to and from different machines (but same DBversion).
    I'm not doing the real move for the moment, just trying to validate a way to do it, but I guess it's important to say that the dump being used for the moment comes from the same database (the long story being that due to some column using object datatype which caused error in the remap, I had to reload the dump with the "schema rename", drop the object column, and recreate a dump file without the object_datatype...).
    So Yes, the file will have to move, but in the current test, it doesn't.
    Srini Chavali wrote:
    Obviously something is different in production than test - can you post the output of this command from both databases ?
    SQL> select * from NLS_DATABASE_PARAMETERS;
    Yes Srini, something is obviously different : I'm starting to think that the difference might be in the Linux/shell side rather than on the impdp as datapump is supposed to be NLS_LANG/CHARSET-proof +(when traditional imp/exp was really sensible on those points)+
    The result on the Exadata where I have the issue :PARAMETER                      VALUE
    NLS_LANGUAGE                   AMERICAN
    NLS_TERRITORY                  AMERICA
    NLS_CURRENCY                   $
    NLS_ISO_CURRENCY               AMERICA
    NLS_NUMERIC_CHARACTERS         .,
    NLS_CHARACTERSET               AL32UTF8
    NLS_CALENDAR                   GREGORIAN
    NLS_DATE_FORMAT                DD-MON-RR
    NLS_DATE_LANGUAGE              AMERICAN
    NLS_SORT                       BINARY
    NLS_TIME_FORMAT                HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT           DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT             HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT        DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY              $
    NLS_COMP                       BINARY
    NLS_LENGTH_SEMANTICS           BYTE
    NLS_NCHAR_CONV_EXCP            FALSE
    NLS_NCHAR_CHARACTERSET         AL16UTF16
    NLS_RDBMS_VERSION              11.2.0.3.0the result on my sandbox DB :PARAMETER                      VALUE
    NLS_LANGUAGE                   AMERICAN
    NLS_TERRITORY                  AMERICA
    NLS_CURRENCY                   $
    NLS_ISO_CURRENCY               AMERICA
    NLS_NUMERIC_CHARACTERS         .,
    NLS_CHARACTERSET               AL32UTF8
    NLS_CALENDAR                   GREGORIAN
    NLS_DATE_FORMAT                DD-MON-RR
    NLS_DATE_LANGUAGE              AMERICAN
    NLS_SORT                       BINARY
    NLS_TIME_FORMAT                HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT           DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT             HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT        DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY              $
    NLS_COMP                       BINARY
    NLS_LENGTH_SEMANTICS           BYTE
    NLS_NCHAR_CONV_EXCP            FALSE
    NLS_NCHAR_CHARACTERSET         AL16UTF16
    NLS_RDBMS_VERSION              11.2.0.1.0------
    Richard Harrison .  wrote:
    Hi,
    Did you set NLS_LANG also when you did the import?Yes, that is one of the difference between the Exadata and my sandbox.
    My environnement in sandbox has NLS_LANG=AMERICAN_AMERICA.AL32UTF8 where the Exadata doesn't have the variable set.
    I tried to add it, but it didn't change anything.
    Richard Harrison .  wrote:
    Also not sure why you are doing the sed part? Do you have hard coded scheme references inside some of the plsql?Yes, that is why I choose to sed. The (ugly) code have :
    - Procedures inside the same package that references one another with the schema prepended
    - Triggers with PL/SQL codes referencing tables with schema prepended
    - Dynamic SQL that "builds" queries with schema prepended
    - Object Type that does some %ROWTYPE on tables with schema prepended (that will be solved by dropping the column based on those types as they obviously are not needed...)
    - Data model with object whose names uses non-ascii characters
    +(In France we use to call this "gas power plant" in order to tell how a mess it is : pipes everywhere going who-knows-where...)+
    The big picture is that this kind of "schema move & rename" should be as automatic as possible, as the project is to actually consolidate several existing databases on the Exadata :
    One schema for each country, hence the rename of the schemas to include country-code.
    I actually have a workaround yet : Rename the objects that have funky characters in their name before doing the export.
    But I was curious to understand why the SQLFILE messed up the constraint_name on one sustem when it doesn't on another...

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SQL Developer Migrate mySQL to 11g gets ORA-00972 due to 30 char name limit

    I am running MySQL version 5.5.30 server, SQL Developer 3.0.04 Build MAIN-04.34, and Oracle Enterprise Server 11.2.0.1.0, and using Migrate option to move both data dictionary and data from mysql to Oracle
    Most of the steps worked fine using OnLine option: used Capture just fine to generate the repositiory, and Convert generated DDL script just fine in the SQL Developer file folder.
    It failed to create users due to privs, but I created them manually: emulation user and also the MYSQL data schema user, after which I took the generated DDL, connected to my Oracle data schema user, and ran the DDL to basically create all the objects. And found out that over 50 tables / column names from MYSQL are longer then 30 char, and thus the generated DDL fails to create objects..
    Question - I can manually replace the names with shorter 30 char names, but if I do, my data migration step will not work.
    i cannot find references to 'name too long' problem anywhere is SQL Server documentation..
    here is the Oracle error example:
    Error report:
    SQL Error: ORA-00972: identifier is too long
    00972. 00000 - "identifier is too long"
    *Cause:    An identifier with more than 30 characters was specified.
    *Action:   Specify at most 30 characters.
    Creating Primary Key Constraint PRIMARY_1 on table bank_account ...

    Hello,
    have you tried the offline migration option? Then you can probably modify also the ctl file for the SQL*Loader to reflect your changes in the DDL script. I didn't yet try it out, it was just an idea that came to my mind.
    Regards
    Wolfgang

  • Unable to find specied column in result set.

    i m trying to display database values in textboxes on SelectedIndex_Changed event of list box control but i am getting "Unable to find specified column in result set" again n again..
    why this is so??????

    i have to create a new iview from the template of mdm iviews. then i was asked about the alias property.
    thanks,
    raghavendra

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

  • 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

  • Column alias for spatial column within cursor loop using dynamic SQL

    The following PL/SQL is trying to generate an error report for records or objects which are 3 dimensional or above. I have no issue execute one statement in SQLPLUS but I need to use the column alias for the spatial column. But, it is a different story using PL/SQL and dynamic SQL Any help will be great because I've been working on this for than 8 hours but with no luck! Thanks.
    Here is the error I'm getting,
    stmt := 'select p.column_name.get_gtype(), id from '|| table_name p ' where p.column_name.get_gtype() > 2 ';
    ERROR at line 15:
    ORA-06550: line 15, column 79:
    PLS-00103: Encountered the symbol "P" when expecting one of the following:
    . ( * @ % & = - + ; < / > at in is mod remainder not rem
    <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
    LIKE4_ LIKEC_ between || member SUBMULTISET_
    The symbol "* was inserted before "P" to continue.
    and my PL/SQL is,
    set serveroutput on size 100000 feedback off
    declare
    rs integer;
    rs1 integer;
    cur integer;
    rp integer;
    trs integer;
    n integer;
    un varchar2(30);
    stmt varchar2(200);
    begin
    dbms_output.put_line(rpad('Table Name',40)||' Dimension');
    dbms_output.put_line(rpad('-',53,'-'));
    cur:= dbms_sql.open_cursor;
    for t in (select column_name,table_name from user_sdo_geom_metadata where regexp_like(table_name, '[^[A-B]_[AB]$'))
    loop
    stmt := 'select p.column_name.get_gtype(), id from '|| table_name p ' where p.column_name.get_gtype() > 2 ';
    dbms_sql.parse(cur, stmt, dbms_sql.native);
    dbms_sql.define_column(cur, 1, rs);
    dbms_sql.define_column(cur, 2, rs1);
    rp:= dbms_sql.execute(cur);
    n:=dbms_sql.fetch_rows(cur);
    dbms_sql.column_value(cur, 1, rs);
    dbms_sql.column_value(cur, 2, rs1);
    dbms_output.put_line(rpad(t.table_name,38,'.')||rpad(rs,15)||rpad(rs1,15));
    end loop;
    dbms_sql.close_cursor(cur);
    dbms_output.put_line(rpad('-',53,'-'));
    end;
    set serveroutput off feedback on feedback 6

    The following PL/SQL is trying to generate an error report for records or objects which are 3 dimensional or above. I have no issue execute one statement in SQLPLUS but I need to use the column alias for the spatial column. But, it is a different story using PL/SQL and dynamic SQL Any help will be great because I've been working on this for than 8 hours but with no luck! Thanks.
    Here is the error I'm getting,
    stmt := 'select p.column_name.get_gtype(), id from '|| table_name p ' where p.column_name.get_gtype() > 2 ';
    ERROR at line 15:
    ORA-06550: line 15, column 79:
    PLS-00103: Encountered the symbol "P" when expecting one of the following:
    . ( * @ % & = - + ; < / > at in is mod remainder not rem
    <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
    LIKE4_ LIKEC_ between || member SUBMULTISET_
    The symbol "* was inserted before "P" to continue.
    and my PL/SQL is,
    set serveroutput on size 100000 feedback off
    declare
    rs integer;
    rs1 integer;
    cur integer;
    rp integer;
    trs integer;
    n integer;
    un varchar2(30);
    stmt varchar2(200);
    begin
    dbms_output.put_line(rpad('Table Name',40)||' Dimension');
    dbms_output.put_line(rpad('-',53,'-'));
    cur:= dbms_sql.open_cursor;
    for t in (select column_name,table_name from user_sdo_geom_metadata where regexp_like(table_name, '[^[A-B]_[AB]$'))
    loop
    stmt := 'select p.column_name.get_gtype(), id from '|| table_name p ' where p.column_name.get_gtype() > 2 ';
    dbms_sql.parse(cur, stmt, dbms_sql.native);
    dbms_sql.define_column(cur, 1, rs);
    dbms_sql.define_column(cur, 2, rs1);
    rp:= dbms_sql.execute(cur);
    n:=dbms_sql.fetch_rows(cur);
    dbms_sql.column_value(cur, 1, rs);
    dbms_sql.column_value(cur, 2, rs1);
    dbms_output.put_line(rpad(t.table_name,38,'.')||rpad(rs,15)||rpad(rs1,15));
    end loop;
    dbms_sql.close_cursor(cur);
    dbms_output.put_line(rpad('-',53,'-'));
    end;
    set serveroutput off feedback on feedback 6

  • Using column alias with CASE

    It is possible to use a column alias with a CASE in a SELECT? e.g. I have this code
    SELECT
    CASE WHEN categ_1 = 'BASIC' THEN total_1 WHEN categ_2 = 'BASIC' THEN total_2 END
    FROM totalsBut the results column name comes out as CASEWHENCATEG_1='BASIC'THENTOTAL_1WHENCATEG_2='BASIC'THENTOTAL_2END
    I want to use an alias but can't get it to work with the CASE. I guessed at
    SELECT
    CASE WHEN categ_1 = 'BASIC' THEN total_1 WHEN categ_2 = 'BASIC' THEN total_2 END 'alias'
    FROM totalswhich doesn't work.

    Try without the single quotes after END
    Christopher Soza
    Oracle BI DBA
    Orix Consultancy Services Ltd
    b: http://sozaman.blogspot.com

  • Getting ORA-06512/ORA-00972 ERROR WHILE EXECUTING THE PROCEDURE????

    Hi ,
    while executing this procedure , I am getting follwoing errors:
    Create or Replace procedure ADD_CUSTOM_INDEX is
    INDX_NOT_EXIST Number;
    CREATE_SQL_STATMENT VARCHAR2(1500);
    ALTER_SQL_STATMENT VARCHAR2(150);
    CURSOR C1 IS select INDEX_NAME,CREATE_DDL FROM W_CUSTOM_TEST, WC_COMPANY_G WHERE W_CUSTOM_TEST.SYS_TENANT_ID = WC_COMPANY_G.BU_ID;
    BEGIN
    for V_ROW in C1 loop
         SELECT COUNT(USER_INDEXES.INDEX_NAME) INTO INDX_NOT_EXIST FROM USER_INDEXES WHERE USER_INDEXES.INDEX_NAME = V_ROW.index_name;
         IF INDX_NOT_EXIST = 0 THEN
         CREATE_SQL_STATMENT := ''|| '"'|| V_ROW.CREATE_DDL ||'"' ||'PARALLEL NOLOGGING';
         EXECUTE IMMEDIATE CREATE_SQL_STATMENT;
         ALTER_SQL_STATMENT := 'ALTER INDEX ' ||'"'|| V_ROW.INDEX_NAME ||'"'|| ' NOPARALLEL LOGGING';
         EXECUTE IMMEDIATE ALTER_SQL_STATMENT;
         END IF;
    END LOOP;
    END ADD_CUSTOM_INDEX;
    ERROR at line 1:
    ORA-00972: identifier is too long
    ORA-06512: at "LOLAP.ADD_CUSTOM_INDEX", line 13
    ORA-06512: at line 1.
    sturtuce of W_custom_test table is as below:
    CREATE TABLE "LOLAP"."W_CUSTOM_TEST"
    ("INDEX_NAME" VARCHAR2(30) NOT NULL ENABLE,
         "SYS_TENANT_ID" VARCHAR2(15) NOT NULL ENABLE,
    "CREATE_DDL" VARCHAR2(1200),
    "COMMENTS" VARCHAR2(200),
         "STAT_CD" VARCHAR2(30) DEFAULT 'Active' NOT NULL ENABLE,
         "CREATED" DATE DEFAULT SYSDATE NOT NULL ENABLE,
         "LAST_UPD" DATE DEFAULT SYSDATE NOT NULL ENABLE
    Any Pointer??????

    Hi
    Instead of giving as below, go for the not null constraints.
    "STAT_CD" VARCHAR2(30) DEFAULT 'Active' NOT NULL ENABLE,
    "CREATED" DATE DEFAULT SYSDATE NOT NULL ENABLE,
    "LAST_UPD" DATE DEFAULT SYSDATE NOT NULL ENABLE
    That should help
    Regards
    Sudheer

  • Adding columns to result list in inbox view of web client

    Hi,
    I have a requirement to display custom columns in result list of inbox view of web client. I copied the view and controller to custom name space. In BSP_WD_WORKBENCH , for AUIITEM view, there are two context nodes . AUIITEMTREE is one of thena and has tree structure and under it tree node proxy. Tree node proxy has attributes, I can not add more attributes to Tree node proxy in work bench. Would you please any one suggest the approach to solve this problem.
    Thanks in advance.
    With regards,
    Ravi Kumar

    Hi Ravi,
    Have u got solution for ur problem.I have got same requirement.
    As per my requirement I need to search for Sold To Party for all category and display it in AUIITEM.
    Please provide with some inputs .
    Regards,
    Vikas

  • ORA-00972: identifier is too long

    Hi All,
    I get the error ORA-00972: identifier is too long during installation of NW2004s SR2 Java system with DI. This error is seen on the step Perform post load activites. i have made the changes as suggested by SAP note: 314671. But the error still persists. Can anyone suggest what further more should be done here?
    Oracle is unable to delete : OPS$<14 letter host name>\SAPSERVICESR3 and hence the error.
    the output from ora_sql_results.log
    =============================================================
    2008-04-28, 19:04:56 SAPINST ORACLE start logging for
    @@SAPDBA_ADDITIONAL.SQL
    exit;
    Output of SQL executing program:
    SQL*Plus: Release 10.2.0.1.0 - Production on Mon Apr 28 19:04:56 2008
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    Connected.
    old   3:   :sSchemaUser := upper('&&1');
    new   3:   :sSchemaUser := upper('SAPSR3DB');
    old  19:   if upper('&&2') = 'NT' then
    new  19:   if upper('NT') = 'NT' then
    old  21:     :sDomain := upper('&&3');
    new  21:     :sDomain := upper('[14 letter Host Name]\SIDadm');
    old  32:   elsif upper('&&2') = 'UNIX' then
    new  32:   elsif upper('NT') = 'UNIX' then
    old  37:     RAISE_APPLICATION_ERROR(-20004,'Invalid OS, must be "NT" or "UNIX": ' || upper('&&2'));
    new  37:     RAISE_APPLICATION_ERROR(-20004,'Invalid OS, must be "NT" or "UNIX": ' || upper('NT'));
    using following Parameters:
    .  Schema User:                  SAPSR3DB
    .  Parametervalue os_authent_prefix:   OPS$
    .  OPS$SIDADM:                      OPS$[14 letter Host Name]\SIDADM
    .  SAP SID:                      SR3
    .  DB  SID:                      SID
    .  R/3 Service User:                 OPS$[14 letter Host Name]\SAPSERVICESR3
    .  Computer or Domain:                 [14 letter Host Name]\SIDADM
    old 119:   if upper('&&4') = 'SYN' then
    new 119:   if upper('SYN') = 'SYN' then
    old 137:   if upper('&&4') = 'SYN' then
    new 137:   if upper('SYN') = 'SYN' then
    create synonym: SAP_SDBAH SAPSR3DB.SDBAH
    create synonym: SAP_SDBAH SAPSR3DB.SDBAD
    unable to delete user: OPS$[14 letter Host Name]\SAPSERVICESR3
    begin
    ERROR at line 1:
    ORA-00972: identifier is too long
    ORA-06512: at line 46
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SAPINST: End of output of SQL executing program C:\oracle\product\10.2.0\db_1/bin/sqlplus.
    SAPINST found errors.
    SAPINST The current process environment may be found in sapinst_ora_environment.log.
    2008-04-28, 19:04:56 SAPINST ORACLE stop logging
    Thanks in advance,
    Arun E V

    Hi Markus/Stefan,
    Thanks for the quick answer. I know i am using a unsupported version, but that should not be a problem here. Though i have not run the installer from the script, still the DB is a successful installation and i have used it like this a few times.
    Stefan, I have seen the note and made the required modification but still the issue persists. Is there anything more that i need to do apart from what is mentioned in the note?
    The trouble is we are not in a position to change the host name as suggested and would prefer to continue with the same name.
    Thanks,
    Arun E V

  • BEx analyzer 7.x: How to determine first data column in result table?

    Hi,
    we are upgrading to 2004s where the SAPBEXqueries Sheet is not used anymore. Instead there is BExRepositorySheet. Is there a way to determine first data column in result table?
    Regards, Josko.

    hi dinesh......
    please use  'INTO TABLE' instead of  ' INTO CORRESPONDING FIELDS OF TABLE '.  and use ' FOR ALL ENTRIES '............based on relavence ....coz when I set break point  over the select queries it took me long time to execute .......
    becoz u didnt used the for all entries  in select query ............ u r read statement
    READ TABLE I_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_KNVV-KUNNR.  ..... 
    it is reading wrong kunnr value .............even it took long time to execute ......
    use sort where ever required...
    use for all entries .......and check weather the table initial or not......
    use sy-subrc check where ever reqired ..............

Maybe you are looking for

  • How to develope custom function modules in SAP R/3 system to maintain c...

    How to develope custom function modules in SAP R/3 system to maintain cross referencing tables for sales order number.

  • Presenter forces permanentely the file save dialog even for unchanged documents

    Presenter permanentely forces the "Do you want to save the changes ..." file save dialog to appear even for unchanged documents when I try to close it. To confirm the saving all times is not the solution because then I will loose the file's time/date

  • Drives Going to Sleep

    I've been to the Energy Saver. I have turned off "Put the hard disk (s) to sleep when possible." I have it set to sleep in 3 hours. Yet continuously, the external Firewire drives go to sleep--sometimes even during the long Auto Save (rant previously

  • Migrate GLCS2 to DWCS4 problem.

    I installed the migration extension in Dreamweaver CS4 and repeatedly attempted to import GoLive CS2 site, but I keep getting the error message: "Please select a folder that contains your Adobe GoLive site files." And yes I know that I must select th

  • Printing photo book as pdf vertical problem

    The books are all set out in landscape mode, but when I chose print and save as pdf it become portrait and all the photos are chopped off to fit! Any ideas how to fix this? Cheers Waddo