Finding Sum of the column whose column name is numeric value

HI All -
I have column names as years like 1990, 1991, 1992 and there are certain amount like below
*1990 1991 1992*
1000 5000 6000
2000 2000 3000
SUppose I want to find the sum of the amounts for year 1990, and I use the query like Select SUM(1990), it returns the sum of 1990+1990. How to make sure that 1990 is recognized as a column instead as a number.
Thanks

Hi,
To reference a column name that does not follow the normal rules (and starting with a digit does not follow the normal rules), then enclose the column name in double--quotes:
...  SUM ("1990"),  ...You can enclose any identifier in double-quotes, even ones that do follow the normal rules, but remember that anything inside any kind of quotes is case-sensitive.
If your query is assigning column aliases, like "1990", you might want to assign them only in the main query, after all references to them (like the SUM function you mentioned) have been done.
Depending on your front-end, you might get the same results by having the front end do the aliasing. For example, the SQL*Plus COLUMN command can assign an alias (like "1990") to a more gernerically named column (like year_1). Then you could use the noramlly named column throughout the query:
COLUMN  year_1  HEADING "1990"
SELECT  year_1
...     SUM (year_1)
...

Similar Messages

  • How to put the column name and variable value in the alert message.

    Dear,
    how can i put the column name and variable value in the alert message text. i want to display an alert which tell the user about the empty textboxes. that these textboxes must be filled.
    Regards:
    Muhammad Nadeem
    CHIMERA PVT. LTD.
    LAHORE
    [email protected]

    Hello,
    The name of the item that fires the current trigger is stored in the :SYSTEM.TRIGGER_ITEM system variable.
    The value contained in this item can be retrived with the Name_In() built-in
    value := Name_In( 'SYSTEM.TRIGGER_ITEM') ;
    LC$Msg := 'The item ' || :SYSTEM.TRIGGER_ITEM || ' must be entered' ;
    Set_Alert_Property('my_alert_box', ALERT_MESSAGE_TEXT, LC$Msg ) ;
    Ok := Show_Alert( 'my_alert_box' ) ;
    ...Francois

  • How to replace variant to the column name to set value?

    e.g.:i have many columns in my table.now i need to control of the visual attribute.now i hope iterator the columns to set visual value.
    for example:i have a node testNode and a value attribute named testValue of it.i bind it to the some context.
    now i hope used such code to operate it:
    <b>String x="testValue";
    wdContext.currentTestNodeElement.setx(WDVisibility.VISIBLE);</b>
    you know it cann't run.who can give me some advices on it.

    Create a value node called "ColumnVisibility" ( <b>with cardinality 1:1 </b>) under the root context.
    Create as many value attributes ( datatype: ddic:com.sap.ide.webdynpro.uielementdefinitions.Visibility ) as the number of columns in your table and bind them to the visibility property of the appropriate columns.
    (For example: The attributes ColumnOneVisibility, ColumnTwoVisibility, ColumnThreeVisibility are bound to column1, column2, column3).
    Now use this code to control the visibility of columns
    String[] attributeNames = {"ColumnOneVisibility", "ColumnThreeVisibility","ColumnTwoVisibility"};
        for(int k = 0; k < attributeNames.length; k++)
             IWDNodeElement columnVisibilityElement =
    (IWDNodeElement)wdContext.currentColumnVisibilityElement();
             /** Use your condition here */
             /** and set WDVisibility to VISIBLE or NONE depending upon the requirement*/
    columnVisibilityElement.setAttributeValue(attributeNames[k],(WDVisibility) WDVisibility.NONE);
    Bala
    Message was edited by: Bala Krishnan

  • Sorting a column as a numeric value

    Hello,
           I have created a SQL Report using collections and having problems with sorting one of the column as a numeric value.
    I have used create_collection_from_query2 to assign my numeric value as n001 variable. But, when i use the same in my SQL Report, it is considering the column as string.
    Please advise if i am doing anything incorrect which is causing this issue.
    Thank you in advance,
    Madan

    MadanN wrote:
    An update to my above question:
          I have used to_number() function in the select statement. But, i get an error "Invalid Number" error. I have checked the underlying data and confirmed that the data is a numeric value with a 2 point decimal value.
    Just an FYI., i was using to_number() on  apex_item.display_and_save function.
    A function that clearly returns a VARCHAR2 result:
    APEX_ITEM.DISPLAY_AND_SAVE(
       p_idx IN NUMBER,
       p_value IN VARCHAR2 DEFAULT NULL,
       p_item_id IN VARCHAR2 DEFAULT NULL,
       p_item_label IN VARCHAR2 DEFAULT NULL)
       RETURN VARCHAR2;
    SQL> with t as (
       2        select trunc(dbms_random.value(0, 100)) n from dual connect by level <= 5)
       3  select
       4      n
       5    , apex_item.display_and_save(1, n) d
       6  from
       7      t
       8  order by
       9      n;
              N D
              0 <input type="hidden" name="f01" value="0" /><span>0</span>
              6 <input type="hidden" name="f01" value="6" /><span>6</span>
             27 <input type="hidden" name="f01" value="27" /><span>27</span>
             68 <input type="hidden" name="f01" value="68" /><span>68</span>
             74 <input type="hidden" name="f01" value="74" /><span>68</span>
    Making attempts to convert such results to a number using to_number clearly doomed to failure:
    SQL> with t as (
       2        select trunc(dbms_random.value(0, 100)) n from dual connect by level <= 5)
       3  select
       4      n
       5    , to_number(apex_item.display_and_save(1, n)) d
       6  from
       7      t
       8  order by
       9      n;
       , to_number(apex_item.display_and_save(1, n)) d
    ERROR at line 5:
    ORA-01722: invalid number
    To make the column properly sortable in a SQL report:
    Include the original number column in the query.
    Reference the apex_item.display_and_save column name in the number column's HTML Expression property using column reference syntax (#COLUMN_ALIAS#).
    Make the apex_item.display_and_save column hidden.

  • How to find the column name and table name with a value

    Hi All
    How to find the column name and table name with "Value".
    For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
    Any help is highly appricatable
    Thanks & Regards
    Srikkanth.M

    2 solutions by Michaels (the latter is 11g upwards only)...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from cols,
           xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
           columns result varchar2(10) path '.'
    where table_name in ('EMP', 'DEPT')
    TABLE_NAME           COLUMN_NAME          SEARCH_STRING        RESULT   
    DEPT                 DNAME                ES                   RESEARCH 
    DEPT                 DNAME                ES                   SALES    
    EMP                  ENAME                ES                   JONES    
    EMP                  ENAME                ES                   JAMES    
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   PRESIDENT
    EMP                  JOB                  ES                   SALESMAN 
    9 rows selected.

  • Find the column name for a constraint

    Hi Guru,
    I know the constraint name, now i need the column name and table name for the constraint?
    Thanks

    Query the USER_CONS_COLUMNS  then you will find the column name and table Name
    SQL> Select  *  from  USER_CONS_COLUMNS  where Constraint_Name='<Your_constraint_Name>';

  • How to use the column names generated from Dynamic SQL

    Hi,
    I have a problem with Dynamic SQL.
    I have written an SQL which will dynamically generate the Select statement with from and where clause in it.
    But that select statement when executed will get me hundreds of rows and i want to insert each row separately into one more table.
    For that i have used a ref cursor to open and insert the table.
    In the select list the column names will also be as follows: COLUMN1, COLUMN2, COLUMN3,....COLUMNn
    Please find below the sample code:
    TYPE ref_csr IS REF CURSOR;
    insert_csr ref_csr;
    v_select VARCHAR2 (4000) := NULL;
    v_table VARCHAR2 (4000) := NULL;
    v_where VARCHAR2 (4000) := NULL;
    v_ins_tab VARCHAR2 (4000) := NULL;
    v_insert VARCHAR2 (4000) := NULL;
    v_ins_query VARCHAR2 (4000) := NULL;
    OPEN insert_csr FOR CASE
    WHEN v_where IS NOT NULL
    THEN 'SELECT '
    || v_select
    || ' FROM '
    || v_table
    || v_where
    || ';'
    ELSE 'SELECT ' || v_select || ' FROM ' || v_table || ';'
    END;
    LOOP
    v_ins_query :=
    'INSERT INTO '
    || v_ins_tab
    || '('
    || v_insert
    || ') VALUES ('
    || How to fetch the column names here
    || ');';
    EXECUTE IMMEDIATE v_ins_query;
    END LOOP;
    Please help me out with the above problem.
    Edited by: kumar0828 on Feb 7, 2013 10:40 PM
    Edited by: kumar0828 on Feb 7, 2013 10:42 PM

    >
    I Built the statement as required but i need the column list because the first column value of each row should be inserted into one more table.
    So i was asking how to fetch the column list in a ref cursor so that value can be inserted in one more table.
    >
    Then add a RETURNING INTO clause to the query to have Oracle return the first column values into a collection.
    See the PL/SQL Language doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/returninginto_clause.htm#sthref2307

  • Changing the Column names / alias

    Hi,
    I have an oracle query and it works fine.
    select q.sname,
    SUM( decode(p.nprofile1,10,1,0)) as "0 - 5",
    SUM( decode(p.nprofile1,9,1,0)) as "6 - 10",
    SUM( decode(p.nprofile1,8,1,0)) as "11 - 15",
    SUM( decode(p.nprofile1,7,1,0)) as "16 - 19",
    SUM( decode(p.nprofile1,6,1,0)) as "20 - 20",
    SUM( decode(p.nprofile1,5,1,0)) as "21 - 27",
    SUM( decode(p.nprofile1,4,1,0)) as "28 - 30",
    SUM( decode(p.nprofile1,3,1,0)) as "31 - 40",
    SUM( decode(p.nprofile1,2,1,0)) as "41 - 45",
    SUM( decode(p.nprofile1,1,1,0)) "46 - Over",
    COUNT(q.sname) "TOTAL"
    from task_core@cds t, cor_queue q, profile_core@crb p
    where t.nmboxid = q.nmboxid
    and p.ncodaid = t.nobjectid
    and p.ntype=2
    GROUP BY q.sname
    ORDER BY q.sname
    It generates a Cross-tab sort of result and I am using the decode function to generate the result.
    My problem is that right now I am using hardcoded column names or alias for the columns generated by the decode function. eg. "0-5", "6-10" etc.
    I have another table which contains these values ("0-5","6-10"). I would like to know instead of hard coding the column names like
    SUM( decode(p.nprofile1,10,1,0)) as "0 - 5"
    can we retrieve the values from the Other table that contains the values "0-5","6-10" etc and display it there in the decode function?
    Pls help me with this issue
    Thanks
    Gilles

    hi,
    the column names are always fixed. You can try dynamic sql in pl/sql or spool then execute, but in pure sql, it is not possible

  • How to get the column names of the table into the Dashboard prompt

    how to get the column names of the table into the Dashboard prompt
    Thanks & Regards
    Kishore P

    Hey john,
    My requirement is as follows
    I have created a Rank for Total sales by Region wise i.e RANK(SUM(Dollars By Region)) in a pivot table.
    My pivot table looks like this
    COLUMN SELECTOR: TOTAL US , REGION , DISTRICT , MARKET
    ---------------------------------------------------- JAN 2009          FEB 2009        MAR 2009
    RANK              REGION                  DOLLARS           DOLLARS        DOLLARS DOLLARS
    1 CENTRAL 10 20 30 40
    2 SOUTHERN 10 30 30 70
    3 EASTERN 20 20 20 60
    4 WESTERN 10 20 30 40
    When i select the District in column selector
    Report has to display rank based on Total Sales by District. i.e
    ------------------------------------------------- JAN 2009         FEB 2009       MAR 2009
    RANK             DISTRICT              DOLLARS           DOLLARS        DOLLARS DOLLARS
    for this i need to change the fx of rank i.e RANK(SUM(Dollars By Region)) to RANK(SUM(Dollars By District)) and fx of Region i.e Markets.Region to Markets.District dynamically.
    so , i need to capture column name of the value selected from the column selector and dynamically i need to update the fx 0f RANK & fx of region.
    do you have any solution for this?
    http://rapidshare.com/files/402337112/Presentation1.jpg.html
    Thanks & Regards
    Edited by: Kishore P on Jun 24, 2010 7:24 PM
    Edited by: Kishore P on Jun 24, 2010 7:28 PM

  • Can I show the column name for my legend?

    I have a bunch of graphs where the legend labels (ie. the values from the column) aren't really informative (ie. simple numeric values), and are part of a dimensional hierarchy, so you might see a graph whose legend has 1, 14, 38, 141 and you click on one of them and get another graph whose legend is 345, 6546, 2342. My current solution is to create a logical column prepending the value with a column name, so my values are now "District 1", "District 14", "District 38", "District 141". But it would be so much nicer if I could just show "District" above the legend. Is there any way to do this?

    My be this can give you a help:
    [code]
    SELECT *
    FROM   ALL_CONSTRAINTS
    WHERE  R_CONSTRAINT_NAME IN (SELECT CONSTRAINT_NAME
                                                               FROM   ALL_CONSTRAINTS
                                                               WHERE  TABLE_NAME = 'TABLE_NAME'
    [/code]

  • Reading csv file how to get the Column name

    Hi,
    I am trying to read a csv file and then save the data to Oracle.
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection c = DriverManager.getConnection("jdbc:odbc:;Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=.;Extensions=csv,txn");
    Statement stmt = c.createStatement();
    ResultSet rs = stmt.executeQuery("select * from filename.csv");
    while(rs.next())
       System.out.println(rs.getString("Num"));
    My csv file looks like this:
    "CHAM-23","COMPANY NAME","Test","12",20031213,15,16
    Number,Environ,Envel,Date,Time
    "1","2",3,"4",5
    "6","7",8,"9",9
    Now is there anyway using the above code I start processing the file from the second row that holds the names of the columns and skip the first row. And also can I get the name of the column using ResultSet something like:
    if columnName.equals("Number")
    Because I may have a csv file that could have more columns:
    "CHAM-24","COMPANY NAME","Test","12",20031213,16,76
    Number,Environ,Envel,Date,Time,Total,Count
    "1","2","3","4","5",3,9
    "6","7","8","9",9",,2
    So I want to get the column name and then based on that column I do some other processing.
    Once I read the value of each row I want to save the data to an Oracle Table. How do I connect to Oracle from my Application. As the database is on the server. Any help is really appreciated. Thanks

    The only thing I could think of (and this is a cluj) would be to attempt to parse the first element of each row as a number. If it fails, you do not have a column name row. You are counting on the fact that you will never have a column name that is a number in the first position.
    However, I agree that not always placing the headers in the same location is asking for trouble. If you have control over the file, format it how you want. If someone else has control over the file, find out why they are doing it that way. Maybe there is a "magic" number in the first row telling you where to jump.
    Also, I would not use ODBC to simply parse a CSV file. If the file is formatted identically to Microsoft's format (headers in first row, all subsequent rows have same number of columns), then it's fine to take a shortcut and not write your own parser. But if the file is not adhering to that format, don't both using the M$ ODBC driver.
    - Saish
    "My karma ran over your dogma." - Anon

  • How to get the column name and table name with value

    Hi All
    I have one difficult requirement
    I have some column values and they have given some alias column names but i need to find the correct column name and table name from the database.
    For example value is "SRI" and i dont know the table and exact column name so is there any possibilities to find the column name and table name for the given value
    Thanks & Regards
    Srikkanth.M

    Searching all the database for a word...
    Courtesy of michaels...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    11g upwards
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from (select column_name,
                   table_name,
                   'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
              from cols
             where table_name in ('EMP', 'DEPT')),
           xmltable (str columns result varchar2(10) path '.')
    TABLE_NAME                     COLUMN_NAME                    SEARCH_STRING                    RESULT   
    DEPT                           DNAME                          es                               RESEARCH 
    EMP                            ENAME                          es                               JAMES    
    EMP                            JOB                            es                               SALESMAN 
    EMP                            JOB                            es                               SALESMAN 
    4 rows selected.

  • If variable name is the same as the column name in procedure ?

    If variable name is the same as the column name in procedure , What should i do?
    For Example :
    CREATE OR REPLACE PROCEDURE "TEST_PROC" (MIN_SALARY in UMBER)
    as
    begin
    INSERT INTO TEST SELECT JOB_ID,MIN_SALARY FROM JOBS WHERE MIN_SALARY = MIN_SALARY;
    end;

    You could follow a better naming convention and have the parameters to the procedures named in a way so as not to be confused with column names.
    You could prefix the variable names with the name of the procedure they appear in but then what if your have procedure names same as table names?
    SQL> create or replace procedure test_proc(sal in number) is
      2    cnt number ;
      3  begin
      4    select count(*) into cnt from scott.emp where scott.emp.sal = test_proc.sal ;
      5    dbms_output.put_line('cnt='||cnt) ;
      6  end ;
      7  /
    Procedure created.
    SQL> set serveroutput on
    SQL> exec test_proc(800) ;
    cnt=1
    PL/SQL procedure successfully completed.
    SQL>If you search you can find several posts here itself on naming convention to avoid such issues in first place.

  • Query the column names from Public database links

    Greetings,
    I would like to retrieve the list of all the column names from a public database link. A regular ALL_TAB_COLUMNS doesn't seem to be working.
    Thanks
    John9569

    Hi,
    I think your DBA needed to create a synonym for you to have access of that remote database view.
    CREATE SYNONYM synonym_name
    FOR view_name@db_link;Then you can find the column names by
    DESC   synonym_nameGuru's , please correct me If I am wrong.
    Thanks
    Edited by: user10679113 on Mar 12, 2009 12:28 PM
    Edited by: user10679113 on Mar 12, 2009 12:33 PM

  • How to find what are the columns actually used in BMM

    Hi All,
    Is there any way(Utility) in RPD to find out whether the columns present in physical layer are used in BMM layer? One option is to Rt click on physical layer tables and do 'Query related logical column'. This will not allow me to export the result into CSV or any file.
    Is there any beeter way?
    Thanks,
    Anilesh

    Anilesh,
    Try with BI Administrator - Tools -- > Utilities --> Repository Documentation --> execute give your file name (rep_doc.csv)
    Thanks -

Maybe you are looking for

  • Problem with Hyper v console

    I have a Hyper v setup in which the VMs are not listed in the Hyper v manager console. If I right click the server and start service it lists all the servers. ( this issue happens very frequently.) I can see the start up type of Hyper V Virtual machi

  • Multiple Delimiters from a Text File

    I am having an issue trying to figure out how to seperate this text file into 4 columns so I can use the data, S, 0, { }, {a, d} a, 7, {S}, b, 5, {a}, {c, h} c, 2, {b, d}, {f} d, 10, {S}, {c, e} e, 1, {d}, {f} f, 3, {c, e, h}, {g} g, 4, {f}, {F} h, 4

  • Thousands of reference errors in TCMRuntimeManager.as

    I'm working on a fairly large AIR app and in the process of trying to find the cause of an out of memory error, I see that the class TCMRuntimeManager.as is throwing thousands of reference errors...just letting my app sit for 10 minutes had over 350,

  • Is there a way to close background apps on my iPhone 3G running iOS 4.2.1? I'm getting crazy!!!

    I'm running iOS 4.2.1 on my iPhone 3G and it's getting very slow because i cant close the apps that i finished to use (can't close bg apps). If you would help me i'll appreciate il very much

  • Procedure to Copy Database Files Between Servers

    I am currently in the process of installing Oracle 9i on a Solaris platform. When this has been completed, I will be attempting to copy two databases from one server (also Solaris) to this server. What is the best way to copy these databases over to