Using SQL alias column names in same SQL

Hi,
I am converting some Teradata SQL queries and these queries have the ability to use column defined aliases within the same query, something like :
SQL> select 'test' as alias1, 'test2' as alias2, alias1 from dual
Does anyone know how I can get Oracle to do this ????
Many thanks
Ben

Hi,
Yes I did think of that - its just the queries calculated columns are quite large - sample below show a value calculated currently based on alias names - just trying to find an easier way to apply.
I was hoping for some magical syntax that has eluded me !
Ben
(exp(case when (constant_contrib + fsnumber_contrib + herolevel_contrib + is_colmans_contrib + is_heinz_contrib + is_short_life1_contrib + is_short_life2_contrib + is_short_life3_contrib + logcount_prod_contrib + offer_shelf_cap_contrib + promointensity_contrib + std_shelf_cap_contrib + xforprice_add_1_contrib + ( (power(sh_ms_variables.xfspr,1)) * formula_coefficients.coeff_xfspr1 ) + ( (power(sh_ms_variables.xfspr,2)) * formula_coefficients.coeff_xfspr2 ) + ( (power(sh_ms_variables.xfspr,3)) * formula_coefficients.coeff_xfspr3 ) + ( (power(sh_ms_variables.xfspr,4)) * formula_coefficients.coeff_xfspr4 ) + ( sh_ntnl_variables.xnfor2 * formula_coefficients.coeff_xnfor2 ) + ( sh_ms_variables.xnforfs1 * formula_coefficients.coeff_xnforfs1 ) + ( sh_ms_variables.xnforfs2 * formula_coefficients.coeff_xnforfs2 ) + ( sh_ms_variables.xnforfspl * formula_coefficients.coeff_xnforfspl ) + ( sh_ntnl_variables.xnforpl * formula_coefficients.coeff_xnforpl ) + ( (power(sh_ms_variables.xpr,1)) * formula_coefficients.coeff_xpr1 ) + ( (power(sh_ms_variables.xpr,2)) * formula_coefficients.coeff_xpr2 ) + ( (power(sh_ms_variables.xpr,3)) * formula_coefficients.coeff_xpr3 ) + ( (power(sh_ms_variables.xpr,4)) * formula_coefficients.coeff_xpr4 )) < 500 then (constant_contrib + fsnumber_contrib + herolevel_contrib + is_colmans_contrib + is_heinz_contrib + is_short_life1_contrib + is_short_life2_contrib + is_short_life3_contrib + logcount_prod_contrib + offer_shelf_cap_contrib + promointensity_contrib + std_shelf_cap_contrib + xforprice_add_1_contrib + ( (power(sh_ms_variables.xfspr,1)) * formula_coefficients.coeff_xfspr1 ) + ( (power(sh_ms_variables.xfspr,2)) * formula_coefficients.coeff_xfspr2 ) + ( (power(sh_ms_variables.xfspr,3)) * formula_coefficients.coeff_xfspr3 ) + ( (power(sh_ms_variables.xfspr,4)) * formula_coefficients.coeff_xfspr4 ) + ( sh_ntnl_variables.xnfor2 * formula_coefficients.coeff_xnfor2 ) + ( sh_ms_variables.xnforfs1 * formula_coefficients.coeff_xnforfs1 ) + ( sh_ms_variables.xnforfs2 * formula_coefficients.coeff_xnforfs2 ) + ( sh_ms_variables.xnforfspl * formula_coefficients.coeff_xnforfspl ) + ( sh_ntnl_variables.xnforpl * formula_coefficients.coeff_xnforpl ) + ( (power(sh_ms_variables.xpr,1)) * formula_coefficients.coeff_xpr1 ) + ( (power(sh_ms_variables.xpr,2)) * formula_coefficients.coeff_xpr2 ) + ( (power(sh_ms_variables.xpr,3)) * formula_coefficients.coeff_xpr3 ) + ( (power(sh_ms_variables.xpr,4)) * formula_coefficients.coeff_xpr4 )) else 500 end ) - 1) AS uplift,
Edited by: user485052 on Dec 10, 2010 3:08 AM

Similar Messages

  • How to use a calculated column in the same query

    Hi All,
    I need some help with using a calculated column in the same query.
    For eq
    I am joining a couple of tables and some of the select columns are calculated based on the columns of the tables and i want a new column in the same query to use this calculated feild in some other calcualtion.
    something like this...
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    Thanks

    user548171 wrote:
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    ThanksWhat about just repeating the column values:
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( (12+3) / (12-3)  * 100  > 0 )  THEN 'Yes' ELSE 'No'  END FROM DUAL

  • Can I use dynamic alias to name a column?

    I guys. I just want to know if it is possible to assign dynamic names to a column. for instance:
    SQL> select sysdate+1 from dual;
    SYSDATE+1
    09-JUL-08the column name is SYSDATE+1. can I do something like:
    SQL> select 1 as (select sysdate from dual) from dual;(this throws error)
    The reason for this requirement is that I need to assign a column name according to a value that comes from a parameter. So, instead of returning something like:
    SQL> select sysdate, sysdate+1 from dual;
    SYSDATE   SYSDATE+1
    08-JUL-08 09-JUL-08I need to find a way to return something like:
    SQL> select sysdate as <<dynamic column name based on parameter that has been passed in>>, sysdate+1 AS <<dynamic column name based on parameter that has been passed in>> from dual;Obviously I can use something like:
    select sysdate as "08-JUL-08", sysdate+1 AS "09-JUL-08" from dual;But in this case I'm hard coding it. I need this alias to be dynamic.
    Any way to do it?

    Why? Column names are a "programming thing" - not a "display thing".
    When you render the columns, you can decide what and how to display them. It does not make any sense to attempt to do this dynamically.
    Why not?
    Sharable SQL.
    Everytime you create a SQL and dynamically change the column aliases, you create a brand new unique SQL - even if the rest of the SELECT is exactly the same. This means you are stuffing the shared pool full of non-sharable SQL.
    This is bad for performance (lots of hard parsing). It is bad for the shared pool (memory fragmentation).

  • Passing parameters to table valued functions and using parameters as column name on select

    I am creating a function where I want to pass it parameters and then use those parameters in a select statement. When I do that it selects the variable name as a literal not a column. How do I switch that context.
    Query:
    ALTER FUNCTION [dbo].[ufn_Banner_Orion_Employee_Comparison_parser_v2]
    @BANNER_COLUMN AS VARCHAR(MAX),
    @ORION_COLUMN AS VARCHAR(MAX)
    RETURNS @Banner_Orion_Employee_Comparison TABLE 
    LAST_NAME nvarchar(max),
    EMPNO int,
    BannerColumnName nvarchar(max),
    BANNER nvarchar(max),
    ORION nvarchar(max)
    AS
    BEGIN
    INSERT INTO @Banner_Orion_Employee_Comparison
    (LAST_NAME, BANNER, ORION)
    SELECT
    a.LAST_NAME, @BANNER_COLUMN, @ORION_COLUMN
    FROM OPENQUERY(ORCLPROD_APDORACLE, 'select LAST_NAME, BANNER_RANK, BADGE, EMP_STATUS from XTRACT_VIEW') AS a
    inner join IWM_Stage.dbo.ViewPersonnel AS b
    on a.BADGE = b.badge
    WHERE a.EMP_STATUS = 'A'
    and a.BANNER_RANK <> b.[rank]
    RETURN;
    END;
    GO
    Output
    I execute this:
    select * from ufn_Banner_Orion_Employee_Comparison_parser_v2 ('a.BANNER_RANK' , 'b.[rank]')
    and get:
    Cerecerez NULL
    NULL a.BANNER_RANK
    b.[rank]
          

    George,
    You could go for using a CASE statement as earlier mentioned by Erland. This would look like below: (Downside is that you need to be mentioning all possible values in the CASE)
    ALTER FUNCTION [dbo].[ufn_Banner_Orion_Employee_Comparison_parser_v2]
    @BANNER_COLUMN AS VARCHAR(MAX),
    @ORION_COLUMN AS VARCHAR(MAX)
    RETURNS @Banner_Orion_Employee_Comparison TABLE
    LAST_NAME nvarchar(max),
    EMPNO int,
    BannerColumnName nvarchar(max),
    BANNER nvarchar(max),
    ORION nvarchar(max)
    AS
    BEGIN
    INSERT INTO @Banner_Orion_Employee_Comparison(LAST_NAME, BANNER, ORION)
    SELECT
    a.LAST_NAME
    , CASE @BANNER_COLUMN WHEN 'a.BANNER_RANK' THEN a.BANNER_RANK WHEN 'a.BADGE' THEN a.BADGE END --put values as required
    , CASE @ORION_COLUMN WHEN 'b.[rank]' THEN b.[rank] END --put values as required
    FROM OPENQUERY(ORCLPROD_APDORACLE, 'select LAST_NAME, BANNER_RANK, BADGE, EMP_STATUS from XTRACT_VIEW') AS a
    inner join IWM_Stage.dbo.ViewPersonnel AS b
    on a.BADGE = b.badge
    WHERE a.EMP_STATUS = 'A'
    and a.BANNER_RANK <> b.[rank]
    RETURN;
    END;
    GO
    Another method that I would suggest is to get all values from the function, then build a dynamic query to obtain results from it .. Something like:
    ALTER FUNCTION [dbo].[ufn_Banner_Orion_Employee_Comparison_parser_v2]()
    RETURNS @Banner_Orion_Employee_Comparison TABLE
    LAST_NAME nvarchar(max),
    EMPNO int,
    BannerColumnName nvarchar(max),
    BANNER nvarchar(max),
    ORION nvarchar(max)
    AS
    BEGIN
    INSERT INTO @Banner_Orion_Employee_Comparison(LAST_NAME, BANNER, ORION)
    SELECT
    * --Returns all the columns
    FROM OPENQUERY(ORCLPROD_APDORACLE, 'select LAST_NAME, BANNER_RANK, BADGE, EMP_STATUS from XTRACT_VIEW') AS a
    inner join IWM_Stage.dbo.ViewPersonnel AS b
    on a.BADGE = b.badge
    WHERE a.EMP_STATUS = 'A'
    and a.BANNER_RANK <> b.[rank]
    RETURN;
    END;
    GO
    --Execution
    DECLARE @BANNER_COLUMN AS VARCHAR(MAX), @ORION_COLUMN AS VARCHAR(MAX),@SQL NVARCHAR(MAX)
    SET @BANNER_COLUMN='BANNER_RANK'
    SET @ORION_COLUMN='[rank]'
    SET @SQL='
    select LAST_NAME,'+@BANNER_COLUMN+','+@ORION_COLUMN+' from ufn_Banner_Orion_Employee_Comparison_parser_v2 ()'
    PRINT @SQL
    EXEC @SQL
    You just need to make sure that the column names returned by the function are UNIQUE (Using proper alias names) so that you don't have a problem referring to them from the outside..
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • How to make dynamic query using DBMS_SQL variable column names

    First of all i will show a working example of what i intend to do with "EXECUTE IMMEDIATE":
    (EXECUTE IMMEDIATE has 32654 Bytes limit, which isn't enough for me so i'm exploring other methods such as DBMS_SQL)
    -------------------------------------------------CODE-----------------------------------
    create or replace PROCEDURE get_dinamic_query_content
    (query_sql IN VARCHAR2, --any valid sql query ('SELECT name, age FROM table') 
    list_fields IN VARCHAR2) --list of the columns name belonging to the query (  arr_list(1):='name';   arr_list(2):='age';
    -- FOR k IN 1..arr_list.count LOOP
    -- list_fields := list_fields || '||content.'||arr_list(k)||'||'||'''~cs~'''; )
    AS
    sql_stmt varchar (30000);
    BEGIN
                   sql_stmt :=
    'DECLARE
         counter NUMBER:=0;     
    auxcontent VARCHAR2(30000);     
         CURSOR content_cursor IS '|| query_sql ||';
         content content_cursor%rowtype;     
         Begin
              open content_cursor;
              loop
                   fetch content_cursor into content;
                   exit when content_cursor%notfound;
                   begin                              
                        auxcontent := auxcontent || '||list_fields||';                    
                   end;
                   counter:=counter+1;     
              end loop;
              close content_cursor;
              htp.prn(auxcontent);
         END;';
    EXECUTE IMMEDIATE sql_stmt;
    END;
    -------------------------------------------------CODE-----------------------------------
    I'm attepting to use DBMS_SQL to perform similar instructions.
    Is it possible?

    Hi Pedro
    You need to use DBMS_SQL here because you don't know how many columns your query is going to have before runtime. There are functions in DBMS_SQL to get information about the columns in your query - all this does is get the name.
    SQL&gt; CREATE OR REPLACE PROCEDURE get_query_cols(query_in IN VARCHAR2) AS
    2 cur PLS_INTEGER;
    3 numcols NUMBER;
    4 col_desc_table dbms_sql.desc_tab;
    5 BEGIN
    6 cur := dbms_sql.open_cursor;
    7 dbms_sql.parse(cur
    8 ,query_in
    9 ,dbms_sql.native);
    10 dbms_sql.describe_columns(cur
    11 ,numcols
    12 ,col_desc_table);
    13 FOR ix IN col_desc_table.FIRST .. col_desc_table.LAST LOOP
    14 dbms_output.put_line('Column ' || ix || ' is ' ||
    15 col_desc_table(ix).col_name);
    16 END LOOP;
    17 dbms_sql.close_cursor(cur);
    18 END;
    19 /
    Procedure created.
    SQL&gt; exec get_query_cols('SELECT * FROM DUAL');
    Column 1 is DUMMY
    PL/SQL procedure successfully completed.
    SQL&gt; exec get_query_cols('SELECT table_name, num_rows FROM user_tables');
    Column 1 is TABLE_NAME
    Column 2 is NUM_ROWS
    PL/SQL procedure successfully completed.
    SQL&gt; exec get_query_cols('SELECT column_name, data_type, low_value, high_value FROM user_tab_cols');
    Column 1 is COLUMN_NAME
    Column 2 is DATA_TYPE
    Column 3 is LOW_VALUE
    Column 4 is HIGH_VALUE
    PL/SQL procedure successfully completed.I've just written this as a procedure that prints out the column names using dbms_output - I guess you're going to do something different with the result - maybe returning a collection, which you'll then parse through in Apex and print the output on the screen - this is just to illustrate the use of dbms_sql.
    best regards
    Andrew
    UK

  • How to spool the null alias column names in sppol file

    Hi,
    I have to spool the data and having some issues.
    SELECT DISTINCT a.market_name,a.market_code,*''as empid* from ssp2_pcat.markets a ;
    in the above select sql I have created extra null column as empid
    when I spool with tild dilimited I am not getting column name(empid) in spool file.
    a.market_name||'~'||a.market_code||'~'||'''empid'
    SSB ~25010~' empid
    In the feed file it should be null. but the alias column is populted with empid
    Can you please let me know what is wrong here?
    Thanks,

    SELECT DISTINCT a.market_name,a.market_code,*''as empid* from ssp2_pcat.markets a ;
    in the above select sql I have created extra null column as empid
    when I spool with tild dilimited I am not getting column name(empid) in spool file.
    a.market_name||'~'||a.market_code||'~'||'''empid'
    SSB ~25010~' empid
    In the feed file it should be null. but the alias column is populted with empid
    Can you please let me know what is wrong here?
    Thanks,Try this one
    SELECT DISTINCT a.market_name||'`'||a.market_code as empid from ssp2_pcat.markets a ;

  • What is the use of Position Column Name in USER_CONS_COLUMNS Table

    Please let me know the purpose of POSITION Column Name in USER_CONS_COLUMNS Table.
    Example :
    Created this below Table having two constraints 1.Primary Key 2.Check Constraint
    CREATE TABLE A(ID NUMBER PRIMARY KEY,NAME VARCHAR2(30),SAL NUMBER CHECK (SAL > 0))
    When i execute the below query
    SELECT POSITION,CONSTRAINT_NAME FROM USER_CONS_COLUMNS WHERE TABLE_NAME = 'A'
    it displays the data :
    POSITION CONSTRAINT_NAME
    1 SYS_C005488
    SYS_C005487
    Only for the first record it displays the POSITION but not for the second row.
    Kindly help me on this.

    SQL> CREATE TABLE A(
      2     ID1 NUMBER
      3   , ID2 NUMBER
      4   , NAME VARCHAR2(30)
      5   , SAL NUMBER CONSTRAINT A_SAL_POSITIVE CHECK (SAL > 0)
      6   , CONSTRAINT A_PRIMARY_KEY PRIMARY KEY (ID1, ID2)
      7  )
      8  /
    Table created.
    SQL> SELECT CONSTRAINT_NAME, POSITION, COLUMN_NAME
      2    FROM USER_CONS_COLUMNS
      3   WHERE TABLE_NAME = 'A'
      4   ORDER BY CONSTRAINT_NAME, POSITION
      5  /
    CONSTRAINT_NAME                  POSITION COLUMN_NAME
    A_PRIMARY_KEY                           1 ID1
    A_PRIMARY_KEY                           2 ID2
    A_SAL_POSITIVE                            SALA primary key constraint can have multiple columns - the position shows the order the columns are in the primary key definition (and thus also in the pk supporting index.)
    A check constraint does not have any such ordering of the columns involved, so therefore position is null.

  • Wrap report column header when using heading type : Column Names

    The headers for my report is actual data from the database. In order to get it to work I'm using aliases on my columns that correspond to the header name that I want. However, I have been unable to get the headers to wrap. I have tried using <br> and chr(10) but it seems to be stripping them out since it's a column alias. Any ideas? Region source is listed below...r1.fc_desc is the column header that I need to have wrapped.
    declare
    v_sql varchar2(4000);
    v_sql2 varchar2(4000);
    cursor c1 is select distinct fc_code, fc_desc from
    [email protected] where FG_ID=v('G_FINANCIAL_GROUP') order by fc_desc;
    begin
    for r1 in c1 loop
    if v_sql is null then
    v_sql:='select to_char(trans_week_end_thur,''mm/dd/yyyy'') as "Week Ending",sum(decode(fc_code,'''||r1.fc_code||''',payments,0)) as "'||r1.fc_desc||'"';
    v_sql2:='select ''Average:'' as "WeekEnding", avg(sum(decode(fc_code,'''||r1.fc_code||''',payments,0))) as "'||r1.fc_desc||'"';
    else v_sql:=v_sql||' ,sum(decode(fc_code,'''||r1.fc_code||''',payments,0)) as "'||r1.fc_desc||'"';
    v_sql2:=v_sql2||' ,avg(sum(decode(fc_code,'''||r1.fc_code||''',payments,0))) as "'||r1.fc_desc||'"';
    end if;
    end loop;
    if v_sql is null then
    v_sql := 'select ''No records found for weekly analysis by insurance class for this financial group '' as " " from dual;';
    else
    v_sql:= v_sql||' from [email protected] where fg_id=:G_FINANCIAL_GROUP group by trans_week_end_thur';
    v_sql2:=v_sql2||' from [email protected] where fg_id=:G_FINANCIAL_GROUP group by trans_week_end_thur;';
    v_sql:=v_sql||' union '||v_sql2;
    end if;
    return v_sql;
    end;

    I've resorted to creating a separate function to return a colon-separated list of column names, in which you can include a br tag or whatever, until I get a chance to research this more thoroughly.
    I thought it would just be a case of asking APEX not to strip the HTML, but it's clearly not as simple as that.
    Regards,
    John.

  • How to use SIZE as column name

    I have a database that I am trying to move from MSAccess to ORACLE. There is a column in one of the tables called 'SIZE'. I have moved the table into ORACLE, but I cannot insert or update any rows of the SIZE column is involved. There is a lot of legacy here and I do not want to rename the column. In MS Access I was able to say [SIZE]='44' But that does not seem to work in ORACLE.
    Is there a similar syntax in ORACLE? I have tried (SIZE), 'SIZE', tablename.SIZE, "SIZE" nothing seems to work.
    Please help.
    Thanks in advance.

    As long as you surround the column name with double quotes and specify the case for the column name correctly, you should have no error.
    SQL> create table sizes ("SIZE" number, "Size" number, "size" number) ;
    Table cr&eacute;&eacute;e.
    SQL> insert into sizes ("SIZE", "Size", "size") values (1, 2, 3) ;
    1 ligne cr&eacute;&eacute;e.
    SQL> select * from sizes ;
         SIZE      Size      size
            1         2         3
    SQL> update sizes set "size" = 4 where "SIZE" = 1 ;
    1 ligne mise &agrave; jour.
    SQL> select * from sizes ;
         SIZE      Size      size
            1         2         4

  • Content Type Column Names with same display Name ???

    Hi everyone,
    I have a SharePoint Sitecollection where are Site Column Display Names are the same (see Image)
    If I view the URL links, the internal names are different, that's ok.
    But how is this possible ? You can't rename the columns with existing names ?
    Thanks
    Stephan

    Like Enrique I would say these werent created via the interface. Doubt a migration would have done anything only Lookups seem to be duplicating. Could these be used in a form of some kind?
    If this is helpful please mark it so. Also if this solved your problem mark as answer.

  • Using data as column names

    Hi Guys,
    The data is like in the format below:
    Item ID
    COMM
    PL
    AC
    RV
    ESTB_ID
    1
    Q4-2013
    Q4-2013
    3
    2
    Q4-2013
    Q4-2013
    3
    12
    Q3-2013
    Q3-2013
    Q4-2013
    3
    The requirement is to group the data by establishment id and the no of items commissioned, planned, revised and actual in a quarter.
    The result set should be like:
    ESTB_ID
    Item ID
    PL Q3-2013
    AC Q3-2013
    RV Q3-2013
    PL Q4-2013
    AC Q4-2013
    RV Q4-2013
    3
    1
    0
    0
    0
    1
    0
    1
    3
    2
    0
    0
    0
    1
    0
    1
    3
    12
    1
    0
    0
    0
    1
    0
    What is the best way of achieving this result?
    Thanks

    Take a look at the links in the FAQ:
    Re: 4. How do I convert rows to columns?
    Especially: PL/SQL 101 : Cursors and SQL Projection
    and How to pipeline a function with a dynamic number of columns?

  • Issue in Column NAMES Printing in SQLPLUS

    Hi All,
    I am connecting to 2 databases through a 10.1.0.4.2 Version of SQLPLUS.
    1st Database runs with - 10.2.0.4 Patchset
    2nd Database runs with - 10.2.0.1.0 Patchset
    From both the Databases we are running a long query with columns using Decode funtions. We are not able to see the column names completely in the 1st DB i.e 10.2.0.4 Patchset. Whereas in 2nd DB - Version 10.2.0.1.0 - Its working properly. I am not sure whether here DB version is the problem.
    This is the query i am firing from both DB's. Here in the 1st column with decode function doesnt prints the column heading in SQLPLUS.
    SELECT DECODE('ENG','ENG',A.PC_DESC,A.PC_DESC_BL)
    FROM PCOM_CODES A, PCOM_CODES_APPL_CODES B
    WHERE CAC_TYPE = 'VEH_CC_TYPE'
    AND A.PC_TYPE = CAC_PC_TYPE_2
    AND A.PC_CODE = B.CAC_PC_CODE_2
    AND ROWNUM < =2
    DECODE('ENG','ENG',A.PC_DESC,A.PC_DESC_BL) - This is the column name which doesnt prints properly in a 10.2.0.4.0 Database.
    Is there any specific User specific or DB specific setting for such issues. We dont want to use any alias column names for specific purpose to be handled with that column name.
    We have already tried out the following.
    1) All SQLPLUS environment variables like SET SERVEROUT ON SIZE etc.
    2) In the same PC where DB is installed.
    3) Checked even if its a Data issue but really not.
    4) We cannot set any alias column for this due to functional restrictions.
    I appreciate a quick response from the forum users on this issue.
    Thanks in advance.

    check this out.
    I still believe it is a formatting issue.
    SQL> select decode(empno,7369,job||hiredate||sal||deptno,deptno) from emp;
    /*Output */
    DECODE(EMP
    30
    20
    30
    20
    10
    /* now*/
    SQL> set line 1200;
    SQL>  select decode(empno,7369,job||hiredate||sal||deptno,deptno) from emp;
    DECODE(EMPNO,7369,JOB||HIREDATE||SAL||DEPTNO,DEPTNO)
    CLERK17-DEC-8080020
    30
    30
    20
    30
    30
    10
    20
    10
    30
    20
    try setting set line 1200 and then running that query.
    Cheers!!!
    Bhushan

  • SQL Alter Column Name

    I am trying to change the name of a column in my Oracle database using SQL PLUS. This is what I'm doing:
    ALTER TABLE projects
    RENAME COLUMN thomas_comp_type TO thomas_comp_shipped_via;
    When I do this it gives me an error stating ORA-14155 Missing PARTITION or SUBPARTITION keyword.
    What does this mean and how do I fix it?

    Hang on: you're trying to rename a column called NAME?
    That's one of Oracle's reserved keywords so should never have been used as a column name in the first place:
    SQL> select * from v$reserved_words where keyword like 'NAME';
    KEYWORD                            LENGTH R R R R D
    NAME                                    4 N N N N NThat said, you are able to do such a rename without an issue in 10g:
    SQL> create table t1 (name varchar2(10));
    Table created.
    SQL> alter table t1 rename column name to fred;
    Table altered.
    SQL> desc t1;
    Name                                      Null?    Type
    FRED                                               VARCHAR2(10)Oracle 9i is obviously a different matter ...and it doesn't help that it's such an old version, because I don't have a machine running that to hand to test things out on. You could try double-quoting the column name:
    SQL> alter table t1 rename column "FRED"  to barney;
    Table altered.But I can't guarantee that will work.

  • EA 2.1 - SQL autoformat does not capitalize some column names

    Hi,
    If I put this bit of SQL into the worksheet, select it, and click the A->a formatting button to cycle through the options:
    SeLecT Id, NaMe, MY_SpecIal_Column, yEAr fROm DuAl;
    turns into
    INITCAP - Select Id, Name, My_special_column, Year From Dual;
    UPPER - SELECT ID, NAME, MY_SPECIAL_COLUMN, YEAR FROM DUAL;
    LOWER - select id, name, my_special_column, year from dual;
    UPPER_KW - SELECT ID, NAME, my_special_column, YEAR FROM dual;;
    LOWER_KW_UPPER_ID - select id, name, MY_SPECIAL_COLUMN, year from DUAL;
    You can see in the last two cases that ID, NAME, and YEAR are treated as keywords instead of column names.

    Hi,
    I think it is due to Oracle keywords which can be used as column names.
    SQL Dev thinks the column given is a keyword instead of column name.
    In my opinion, it works just fine.
    In the first place, we should avoid using keywords as column name.
    However, as in your case, when we need the column to be formatted as desire,
    Perhaps the developer should give some handling over the keywords themselves.
    SELECT <to be treated as column> FROM <to be treated> WHERE <to be treated>
    UPDATE <to be treated> SET <to be treated> WHERE <to be treated>
    CREATE TABLE / VIEW <to be treated>
    Wow... that would be a long list of handling.
    And it would turn out to be double time efforts on the case conversion though.
    Regards,
    Buntoro

  • Dynamic Column Names using Refcursors

    Hi,
    I have a stored procedure which returns a refcursor. The refcursor contains a SQL query in which the column names and number of columns vary dynamically based on the date parameters passed.
    "My objective is to return certain XYZ details of employees for a certain month range."
    For ex: For the month of Aug-2011, the column names would be '1-AUG-11' to '31-AUG-11 and for Feb-2011 '1-FEB-11' to '28-FEB-11'
    My issue is, when I execute the refcursor query using "EXEC", my column names/headings are preserved.
    FIELD NAMES: EMPLOYEE_CODE XYZ_TYPE *1-AUG-11* *2-AUG-11* ... *31-AUG-11*
    DATA: EMPCODE_Z TYPE1 VALUE_1 VALUE_1 ... VALUE_31
    Whereas when I fetch the refcursor into a collection of nested table and display, my column names are lost.
    DATA: EMPCODE_Z TYPE1 VALUE_1 VALUE_1 ... VALUE_31
    Is there a way where I can preserve the column names from the refcursor after fetching into pl/sql collections?
    Any help would be highly appreciated.
    Thank you.
    Edited by: 867622 on Nov 11, 2011 4:38 PM

    867622 wrote:
    If not dynamic SQL, how can the number of columns be altered based on the input parameters?Cannot. A dynamic SQL projection means dynamic SQL (there's an exception to this, and despite interesting is not relevant to 99.99% of problems dealing with dynamic SQL projections).
    You can however still use a dynamic projection and wrap that into a user defined type interface.
    Here's the basic approach:
    // create a user define type that will provide the wrapper for the SQL projection
    create or replace type TString as table of varchar2(4000);
    // build dynamic SQL projections via this type, e.g.
    select
      TStrings( object_id, object_name, created )
    from user_objects
    select
      TStrings( emp_id, dept_id, salary, commission )
    from employeesDespite the SQL cursors being different and the columns and number of columns being selected different, the SQL projection of both are the same. The Count method tells you the number of columns in the projection. Referencing an applicable column is simply done by using the column's sequential number in the projection.
    You also do not have to use a collection or varchar2 as the wrapper type - you can create complex user objects and use the collection type for that, as the SQL projection.
    Another alternative is converting the ref cursor into a DBMS_SQL cursor and using the latter's describe interface to dynamically determine the structure of the SQL projection and fetching the column values from it. But 11gr1 or later is needed for doing this.

Maybe you are looking for

  • HP LaserJet 1300 no longer prints from OS 10.7.5.

    My HP LaserJet 1300 has suddenly stopped printing various files, most notably PDFs from Acrobat X. I had no problems previously. Did an OS update to 10.7.5 cause this problem?

  • Dynamic End Point Lookup in BPEL from Oracle Service Registry

    Hi, I have configured the OSR as mentioned in the configuration document, http://download-east.oracle.com/docs/cd/B31017_01/integrate.1013/b28982/service_config.htm#BABBHJAF I am able to connect to the OSR using JDeveloper in BPEL Project, but when I

  • Burned CD's now "Not authorized to play.."

    I have upgraded to Itunes 7.3 for Winders. When I Sync my Ipod 63 songs will not make it over. Many of these are songs from CD's I have burned to iTunes! The error displayed when I attempt to play one of these 63 songs is You have already authorized

  • BUG??? Overridden prepareModel not being called all the time

    I have an ADF/struts application that was originally developed with Jdev 10.1.2. I then migrated it to 10.1.3 and have been maintaining it with that for that past two months. Recently, I added some new pages and in those new pages I need to do some p

  • Unable to View Monitor Diagram in Oracle Workflow 2.6.5

    Hi When I click 'View Diagram' button in Oracle Workflow in Internet explorer, a blank grey page is displayed. I get following error in java console: Error loading class: oracle.apps.fnd.wf.Monitor java.lang.NoClassDefFoundError java.lang.ClassNotFou