Getting an extra column value in a group by expression

I have the following table-
CREATE TABLE dummy_data (
ID number NOT NULL , mark number not null
,test_Timestamp timestamp NOT NULL
insert into dummy_data (id,mark,test_TimeStamp) values (1,12,'08-MAR-10 09.43.30.922000000');
insert into dummy_data (id,mark,test_TimeStamp) values (2,12,'08-MAR-10 09.46.30.922000000');
insert into dummy_data (id,mark,test_TimeStamp) values (3,16,'08-MAR-10 09.23.30.922000000');
insert into dummy_data (id,mark,test_TimeStamp) values (4,18,'08-MAR-10 09.26.30.922000000');
insert into dummy_data (id,mark,test_TimeStamp) values (5,20,'08-MAR-10 09.13.30.922000000');
insert into dummy_data (id,mark,test_TimeStamp) values (6,22,'08-MAR-10 09.12.30.922000000');
select TO_CHAR(TO_DATE (ceil(to_number(to_char(test_Timestamp, 'yyyymmddhh24mi'))/5)*5,'yyyymmddhh24mi'),'yyyy-mm-dd hh24:mi') as ts , id
from dummy_data
group by TO_CHAR(TO_DATE (ceil(to_number(to_char(test_Timestamp, 'yyyymmddhh24mi'))/5)*5,'yyyymmddhh24mi'),'yyyy-mm-dd hh24:mi'), id;
I use the below query to get the id grouped by 5 minutes interval.
Now I also need to get the Mark associated with the id, in a single query. Is there a way to get it ?
Thanks
_Pete                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

I am sorry should have given little more details on my request and I am not sure even if it possible to do that in sql.
Though I am grouping by 5 minute interval. If the mark is there for the last one hour, show that entry only once.
In other words, in my example
Take this to samples (see same mark)
insert into dummy_data (id,mark,test_TimeStamp) values (6,12,'08-MAR-10 09.12.30.922000000');
insert into dummy_data (id,mark,test_TimeStamp) values (2,12,'08-MAR-10 09.46.30.922000000');
When you group by id, you will get separate values for 9:10-9:15 5 minute interval and another one for 9:45-9:50 interval.
What I want is if the mark has already appeared in that one hour interval, I don't want it to be repeated.
Thanks
_Pete                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • How can i select other column values('-' separated) in group by function

    CREATE TABLE EMP (
         EMPNO NUMBER(4) NOT NULL,
         ENAME VARCHAR2(10),
         JOB VARCHAR2(9),
         SAL NUMBER(7)
    INSERT INTO EMP(EMPNO, ENAME, JOB, SAL) VALUES (7369, 'SMITH', 'CLERK', 800);
    INSERT INTO EMP(EMPNO, ENAME, JOB, SAL) VALUES (7499, 'SMITH', 'SALESMAN', 1600);
    INSERT INTO EMP(EMPNO, ENAME, JOB, SAL) VALUES (7521, 'ALLEN', 'SALESMAN', 2400);
    In Output I want 3 columns : EMP,SUM(SAL),JOB(hyphenSeparated)
    Means i want my output like
    First row : SMITH,2400,CLERK-SALESMAN
    Second row : ALLEN,2400,SALESMAN
    I tried to write following sql : select ename,sum(sal) from emp group by ename
    But i want other colummn value in '-' separated. but group by is only allowing agreegated function.
    How can i select other column value using group by function.

    SQL>  select ename,sum(sal), listagg(job, '-') within group (order by job) as job  from emp group by ename;
    ENAME        SUM(SAL) JOB
    ALLEN            2400 SALESMAN
    SMITH            2400 CLERK-SALESMANnote: LISTAGG is a feature of 11.2

  • Is there a way to get notification when column value is updated ?

    Is there a way to check when a column value has been updated?
    Example: "Project Start Date" has changed from March to June. RMS report will be sent via iBot to notify users.

    Find out if (in your country) there is a landline phone with a "ring" light on it. (In some countries, it's possible to buy a phone which is easily plugged in at home by the user.)

  • Can i get summary column value of one group appears at the last page once

    Hi,
    I am having one group G_Item.I need the summary column(CS_Total_quantity->source as :cp_quantity) value as Total quantity value of the report andprint it on the last page.How can i get that value?Please advise me.Urgent......Waiting for reply.
    Thank You

    try this...
    put a summery column outside the quey.
    & take sum of "CS_Total_quantity".
    set its reset at property to "report". & print object on "last page".
    hope this 'll work for u.
    Capri...

  • How to get all the column values from a table source

    Hi,
    I have created one table source on a employee table and some customized attributes using global settings>search attributes.
    Now these customized attributes mapped with the table columns through attribute mapping from the sorce tab.
    Using doOracleSearch method i passed last parameter i.e. Integer array of customized attributes.
    After execution of doOracleSearch method i am getting the results but customized attributes are not coming.
    getCustomAttributes method returns null instead of some values.
    Please refer following code for more info:
    Integer[] fetchAttr=new Integer[2];
    fetchAttr[0]=new Integer(137);
    fetchAttr[1]=new Integer(138);
    result =
    stub.doOracleSearch("BTM",
    new Integer(1),
    new Integer(10),
    Boolean.TRUE,
    Boolean.TRUE,
    group,
    "en",
    "en",
    Boolean.TRUE,
    null,
    null,
    fetchAttr);
    ResultElement[] resElements = result.getResultElements();
    for(int i = 0; i < resElements.length; i++)
    System.out.println("Title : " + resElements[0].getTitle());
    System.out.println("Snippet : " + resElements[0].getSnippet());
    System.out.println("URL : " + resElements[0].getUrl());
    System.out.println("non default : " + resElements[0].getCustomAttributes()); // it returns null here
    }

    Confirm the attributes you are asking SES for match those on the data source being searched. One thing to try is to simply tell SES to return all custom attributes for your search. Here is a snippet to build a list of all attribute IDs and pass them to your search...
    // Create and set SOAP URL
    OracleSearchService searchService = new OracleSearchService();
    searchService.setSoapURL("http://myserver:7777/search/query/OracleSearch");
    // Set attributes to fetch (all)
    Attribute[] attributesAll = searchService.getAllAttributes("en");
    ArrayList<Integer> attributeIds = new ArrayList<Integer>();
    for(Attribute a: attributesAll)
    attributeIds.add(a.getId());
    Integer attributeIdArrayAll[] = new Integer[attributeIds.size()];
    attributeIdArrayAll = attributeIds.toArray(attributeIdArrayAll);      
    // Query
    OracleSearchResult result = searchService.doOracleSearch("some text", ..........[other params], attributeIdArrayAll);
    // Print out results
    ResultElement[] resElements = result.getResultElements();
    for(int i = 0; i < resElements.length; i++)
    // Get document
    ResultElement doc = resElements;
    // Print Title
    System.out.println("Title: " + doc.getTitle());
    // Print custom attributes
    CustomAttribute[] attributes = doc.getCustomAttributes();
    for(int j = 0; j < attributes.length; j++)
    CustomAttribute attr = attributes[j];
         System.out.println("[Custom Attribute] " + attr.getName() + ": " + attr.getValue());
    Hope this helps.

  • Getting last year column value from a single table

    I am having the following columns in my table
    BRANCH_CD
    YYMM
    VNDR#
    VGROUP#
    SALES_TRGT_AMT
    SALES_ACTL_AMT
    CUM_TRGT_AMT
    CUM_ACTL_AMT
    i need to get sales_actl_amt from this year and sales_actl_amt from last year from a single table
    pls help
    thank you
    Edited by: 960991 on Nov 19, 2012 11:13 PM

    Hi ashish,
    but i can't use unions in my reports.
    once view my query :
    select t.branch_cd,b.branch_e_name,t.vndr#,v.vndr_name,
    sum(nvl(t.sales_actl_amt,0)) sales_actl_amt
    from inv_sales_trgt_val t,branches b,vendor v where
    t.branch_cd=b.branch_cd and
    t.vndr#=v.vndr# and
    (t.yymm between :fiscal_month and :fiscal_month2) and
    (:fiscal_month<>trunc(:fiscal_month2,-2)) and :fiscal_month2<>trunc(:fiscal_month2,-2)) and t.branch_cd between :from_branch and to_branch and
    t.vndr# between :from_vndr and :to_vndr
    group by t.vndr#,v.vndr_name,t.branch_cd,b.branch_e_name
    order by t.vndr#,t.branch_cd;
    how can i get last year sales_actl_amt .

  • UPDATE_ROW_CONFLICT error, get the details (columns, values)

    Hi,
    I am getting the following error:
    Error :Number of conflicts while synchronizing: 1 SyncResolver.UPDATE_ROW_CONFLICT row 0 attempt to update a row that has been updated or deleted by another user
    has anybody an idea how to get more information about the conflic?
    In what column is the conflic ? The values ?
    regards,
    Andorn

    Hi,
    Please go through the tutorial titled "Performing Inserts, Updates, and Deletes" which is available at: http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/inserts_updates_deletes.html
    Also, go through the below forum threads:
    http://swforum.sun.com/jive/thread.jspa?threadID=95174&tstart=15
    http://forum.sun.com/jive/thread.jspa?forumID=123&threadID=65088
    Hope this helps.
    RK

  • A task of getting an extra column using ssis

    hi...
    I need a help in solving this task. I did this in sql but don't know, why I am getting error in ssis.
    the task is about creating a new column, in this column I should get the id in such a way that the first two letters and the last two letters before @ are displayed and other letters are replaced by *.
    my source column:                                              
    MY DESTINATION COLUMN
    ID  NAME    EMAILID                                             
    ID    NAME         EMAILID                    NEWEMAILID
    1   AKHI     AKHI1985@                                         
    1      AKHI         AKHI1985@               AK****85@
    2 SRESHTA SRESH_GG@                                        2     
    SRESHTA  SRESH_GG@              SR****GG@     
    3 RENU      RENU_COOL1989@                               3      
    RENU       RENU_COOL1989@     RE********89@
    please solve this.

    If your source is database table you can do this in sql itself
    ie use a query like below in OLEDB source
    SELECT ID,NAME,EMAILID,STUFF(EMAILID,3,CHARINDEX('@',EMAILID)-5,REPLICATE('*',CHARINDEX('@',EMAILID)-5)) AS NewEmailID
    FROM SourceTable
    And just map the new column to destination table NEWEMAILID column
    If your source is a file or some other type then you need to do this inside a derived column in SSIS data flow task
    for that use an expression like
    ColumnName Expression
    NEWEMAIL ID <Add As New Column> SUBSTRING([EMAILID],1,2) + REPLICATE('*',FINDSTRING([EMAILID],"@",1)-5) + SUBSTRING([EMAILID],FINDSTRING([EMAILID],"@",1) + 1,LEN([EMAILID]))
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Query to get combinations of column values

    -- Input Data
    with t as (select 'H' as symbol, 1 as id from dual union all
              select 'H' as symbol, 2 as id from dual union all
              select 'H' as symbol, 3 as id from dual union all
              select 'H' as symbol, 4 as id from dual
    ,s as (select 'L' as symbol, 1 as id from dual union all
              select 'L' as symbol, 2 as id from dual union all
              select 'L' as symbol, 3 as id from dual union all
              select 'L' as symbol, 4 as id from dual
    --select * from t,s
    [pre]
    -- Required output is four columns with the below values. The column headings are the ids from the original query. Therefore I suspect the solution would have some sort of crosstab..
    id1---id2---id3---id4
    HHHH     
    HHHL          
    HHLH     
    HHLL                    
    HLHH     
    HLHL          
    HLLH     
    HLLL     
    LHHH     
    LHHL          
    LHLH     
    LHLL                    
    LLHH     
    LLHL          
    LLLH     
    LLLL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    select REPLACE(sys_connect_by_path(symbol,'-'),'-','' ) "id1---id2---id3---id4"
    from (select*from t union all
    select*from s)
    where connect_by_isleaf = 1
    start with id=1
    connect by prior ID=ID-1
    ORDER BY 1
    I THINK U WANT THIS ........
    select substr(regexp_substr(scbp, '-[^-]*', 1, 1),2) as ID1,
    substr(regexp_substr(scbp, '-[^-]*', 1, 2),2) as ID2,
    substr(regexp_substr(scbp, '-[^-]*', 1, 3),2) as ID3,
    substr(regexp_substr(scbp, '-[^-]*', 1, 4),2) as ID4
    from (
    select sys_connect_by_path(symbol, '-') scbp
    from (select*from t union all
    select*from s)
    where connect_by_isleaf = 1
    start with id=1
    connect by prior ID=ID-1
    Edited by: user12108669 on Nov 12, 2009 9:42 PM
    Edited by: user12108669 on Nov 12, 2009 9:43 PM

  • How to get one column value from a DOCUMENT TYPE attribute

    Hi,
    I have created a DOCUMENT TYPE attribute which queries from a table and all the column values( For Ex: Customer Name, Contact Name and Address) are displayed in the message body.
    I want one column value(For Ex: Customer Name) to be displayed in the SUBJECT of the message.
    How can this be done? Please let me know.
    Thanks in advance.

    Thanks Matt. I have used SETITEMATTRTEXT to get a single column value into an ITEM ATTRIBUTE.
    Please see the following procedure...
    ==========================================================
    PROCEDURE MisNotifyDataDesk(
         itemtype IN VARCHAR2
         , itemkey IN VARCHAR2
         , actid IN NUMBER
         , funcmode IN VARCHAR2
         , resultout OUT VARCHAR2
         ) IS
    p_Cart_Id               VARCHAR2(30);
    p_ORG_NAME                     VARCHAR2(360);
    BEGIN
         IF funcmode != WF_ENGINE.ENG_RUN THEN
              wf_log_pkg.string(5,'Notify_Cust_Data_Desk','Not in RUN mode');
         RETURN;
         END IF;
    p_Cart_Id := WF_ENGINE.GetItemAttrText ( itemtype => itemtype
    , itemkey => itemkey
    , aname => 'CART_ID' );
    p_code_position := 10;
         SELECT
              ORG_NAME
         INTO
              p_ORG_NAME                     
         FROM
              MISIBE_END_CUST_DETAILS
         WHERE
              QUOTE_HEADER_ID = p_Cart_Id;
    -- For TEXT BODY
    WF_ENGINE.SETITEMATTRTEXT(itemtype => itemtype , itemkey => itemkey , aname => 'ORG_NAME',avalue => p_ORG_NAME);
    resultout := WF_ENGINE.ENG_COMPLETED||':'||CUST_DATA_CHECK(p_Cart_Id);
    EXCEPTION
         WHEN OTHERS THEN
              WF_CORE.context (
              'WFCustCheck',
              'MisNotifyDataDesk',
              itemtype,
              itemkey,
              TO_CHAR(actid),
              funcmode,
              SQLERRM
    RAISE_APPLICATION_ERROR (-20005, SQLERRM);
    ===========================================================
    I am using &ORG_NAME in the body and subject of my message. But the value is
    not retrieved into the ITEM ATTRIBUTE when I run my process. It is just displaying in the message and the subject of hte message as "&ORG_NAME"
    CUST_DATA_CHECK used in the resultout, is a function which returns 'T' or 'F'. That part is working fine. Just retrieving the ORG_NAME in the ITEM ATTRIBUTE is not working.
    Am I going wrong somewhere? Please let me know.
    Thanks,

  • How to get the Row and Column values in ALV (without using Objects)

    Hi All,
    I need to get the Row / Column when double click is used in ALV, I can use the double click event for this. However, I do not want to use the Object Oriented ALV. I want to implement the same functionality using general (using functions) ALV.
    Is there any way to get the row / column values for a Generia (non-OOPs) ALV report.
    Please help.
    Thanks,
    Vishal.

    Hello,
    The only think you have to do is to get the index where the user clicked, and then read the internal table you sent to the alv
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = 'prg_name'
          i_callback_pf_status_set = 'SET_PF_STATUS'
          i_callback_user_command  = 'USER_COMMAND' " this is to the click event!!
          i_callback_top_of_page   = 'TOP_OF_PAGE'
          is_layout                = alv_layout
          it_fieldcat              = alv_fieldcat
          i_save                   = 'A'
          it_events                = alv_events[]
        TABLES
          t_outtab                 = i_totmez.  ---> TOUR IT.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    " then....
    FORM user_commandUSING r_ucomm     TYPE sy-ucomm
                                    ls_selfield TYPE slis_selfield.
    " r_ucomm -> HAS THE STATUS
    " ls_selfield-tabindex  -> HAS THE SELECTED INDEX
    " THEN READ THE INTERNAL TABLE
    " HERE YOU WILL HAVE THE SELECTED ROW
    READ TABLE i_totmez INDEX ls_selfield-tabindex.
    ENDFORM.
    cheers,
    Gabriel P.

  • Join to get 'Note' Column value  from CS_SR_NOTES_V - Ramya

    Hi All,
    what is the join to get the 'NOTE' column value from the CS_SR_NOTES_V while joining to the cs_incidents_all _b table.
    One join is joining with the INCIDENT_ID of CS_INCIDENTS_ALL_B
    to the INCIDENT_ID of the CS_SR_NOTES_V....but the other column 'ID' of
    CS_SR_NOTES_V is to join to which column of CS_INCIDENTS_ALL_B ??????

    APP_OBJ_CODE='SR'
    ID IS JTF_NOTE_ID
    APP_OBJ_ID IS same AS incident_id
    I don't think you need additional join apart from incident_id since view CS_SR_NOTES_V retrieves only SR notes, and an SR can have multiple notes.

  • Find hidden column value in a dynamacally bind html table with Sharepoint list - Javascript

    I have following code. Now I want to get the hidden column value based on user selected row. I also want to highlight the entire row, not only the e.target.
    Can someone please help me.
    function getTermdetailsQuerySuccsess(sender, args) {
    var listEnumerator = Termsitems.getEnumerator();
    var datatable = document.getElementById("TermList");
    while (listEnumerator.moveNext()) {
    var oListItem = listEnumerator.get_current();
    //var firstName = listEnumerator.get_current().get_item('Title');
    //var secondName = listEnumerator.get_current().get_item('LastName');
    var termID = listEnumerator.get_current().get_item('ID');
    var startdate = listEnumerator.get_current().get_item('startdate');
    var enddate = listEnumerator.get_current().get_item('Enddate');
    var termtype = listEnumerator.get_current().get_item('TermType');
    var Hours = listEnumerator.get_current().get_item('Hours');
    var EdNone = listEnumerator.get_current().get_item('EdNoned');
    var Specialty = listEnumerator.get_current().get_item('Specialty');
    var Subspecialty = listEnumerator.get_current().get_item('Subspecialty');
    var Hospital = listEnumerator.get_current().get_item('Hospital');
    var DEMT = listEnumerator.get_current().get_item('DEMT');
    var Supervisor = listEnumerator.get_current().get_item('Supervisor');
    rowcount = rowcount + 1;
    $("#TermList").append("<tr style='border-bottom:1px silver solid' align='middle' class='gradeA'>" +
    "<td align='left' style='display:none'>" + termID + "</td>" +
    "<td align='left'>" + startdate + "</td>" +
    "<td align='left'>" + enddate + "</td>" +
    "<td align='left'>" + termtype + "</td>" +
    "<td align='left'>" + Hours + "</td>" +
    "<td align='left'>" + EdNone + "</td>" +
    "<td align='left'>" + Specialty + "</td>" +
    "<td align='left'>" + Subspecialty + "</td>" +
    "<td align='left'>" + Hospital + "</td>" +
    "<td align='left'>" + DEMT + "</td>" +
    "<td align='left'>" + Supervisor + "</td>" +
    "</tr>");
    $('#TermList').click(function (e) {
    var tr = $(e.target).parent().index() ;
    alert(tr);
    alert($(e.target).text()); // using jQuery
    // var Cells = tr.e.getElementsByTagName("td");
    $(e.target).addClass('row-highlight');
    var confirmationM = confirm("Do you want to edit this term deatils ?");
    if (confirmationM == true) {
    confirmation = "You pressed OK!";
    else {
    confirmation = "You pressed Cancel!";
    $(e.target).removeClass('row-highlight');
    $('#TermList').click(function (e) {
    var tr = $(e.target).parent().index() ;
    alert(tr);
    alert($(e.target).text()); // using jQuery
    // var Cells = tr.e.getElementsByTagName("td");
    $(e.target).addClass('row-highlight');
    var table = $("#TermList")[0];
    var cell = table.rows[tr].cells[1];
    alert(cell);
    var confirmationM = confirm("Do you want to edit this term deatils ?");
    if (confirmationM == true) {
    confirmation = "You pressed OK!";
    else {
    confirmation = "You pressed Cancel!";
    $(e.target).removeClass('row-highlight');
    d.n weerasinghe

    Hi,
    According to your post, my understanding is that you want to customize a table to display the list items.
    We can write CSS to customize the table style(background color, highlight, hover).
    The following is an example for your reference:
    Code:
    <style>
    #TermList table {
    border-collapse: collapse;
    margin-bottom: 2em;
    width: 100%;
    background: #fff;
    #TermList td, th {
    padding: 0.75em 1.5em;
    text-align: left;
    #TermList th {
    background-color: #31bc86;
    font-weight: bold;
    color: #fff;
    white-space: nowrap;
    #TermList tbody tr:nth-child(2n-1) {
    background-color: #f5f5f5;
    transition: all .125s ease-in-out;
    #TermList tbody tr:hover {
    background-color: rgba(129,208,177,.3);
    #TermList .HiddenColumn {
    display:none;
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    ExecuteOrDelayUntilScriptLoaded(getAllListItems, "sp.js");
    $("#TermList tbody").click(function(e){
    //get hidden column value
    var hiddenColumn=$(e.target).parent().find(".HiddenColumn").text();
    alert(hiddenColumn);
    function getAllListItems(){
    var listName="CustomList01";
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle(listName);
    var query = SP.CamlQuery.createAllItemsQuery();
    allItems = list.getItems(query);
    context.load(allItems);
    context.executeQueryAsync(Function.createDelegate(this, this.getSuccess), Function.createDelegate(this, this.failed));
    function getSuccess() {
    var ListEnumerator = this.allItems.getEnumerator();
    while (ListEnumerator.moveNext()) {
    var currentItem = ListEnumerator.get_current();
    var itemID=currentItem.get_item("ID");
    var name=currentItem.get_item("Title");
    var email=currentItem.get_item("Email");
    $("#TermList tbody").append('<tr><td class="HiddenColumn">'+itemID+'</td><td>'+name+'</td><td>'+email+'</td></tr>');
    function failed(sender, args) {
    alert("failed. Message:" + args.get_message());
    </script>
    <table id="TermList">
    <thead>
    <tr>
    <th>Name</th>
    <th>Email</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
    </table>
    Result:
    Best Regards
    Dennis Guo
    TechNet Community Support

  • PL/SQL - column value is updated as 0 instead of numeric value

    Declare
    v_cnt varchar2(20);
    v_cnd varchar2(20);
    v_total varchar2(20);
    begin
    select count(emp_id) into v_cnt from emp1;
    select count(emp_id) into v_cnd from emp2;
    v_total:=v_cnt+v_cnd;
    dbms_output.put_line('before');
    dbms_output.put_line(v_total);
    update emp3 set total_emp=v_total where dept_no=40;
    commit;
    dbms_output.put_line('after');
    dbms_output.put_line(v_total);
    end;
    In the above program, value for the column total_emp is getting updated as 0 instead of numeric value. However, when I use dbms_output statement to print the value, for both the cases, before and after , I'm getting the numeric value for the variable v_total.
    v_total value is not getting updated to column value in table.
    table column definition for total_emp is varchar2(20).
    Also, I tried to hard code value for total_emp column in the above statement and it worked.
    So, the problem is variable value when used in the update statement it's not getting updated to column.
    Please help me.

    Post a reproducable test case for us...
    SQL> create table emp1 as select * from emp;
    Table created.
    SQL> create table emp2 as select * from emp;
    Table created.
    SQL> create table emp3 as select * from emp;
    Table created.
    SQL> alter table emp3 add (total_emp varchar2(20));
    Table altered.
    SQL> ed
    Wrote file afiedt.buf
      1  Declare
      2    v_cnt varchar2(20);
      3    v_cnd varchar2(20);
      4    v_total varchar2(20);
      5  begin
      6    select count(empno) into v_cnt from emp1;
      7    select count(empno) into v_cnd from emp2;
      8    v_total:=v_cnt+v_cnd;
      9    dbms_output.put_line('before');
    10    dbms_output.put_line(v_total);
    11    update emp3 set total_emp=v_total where deptno=10;
    12    commit;
    13    dbms_output.put_line('after');
    14    dbms_output.put_line(v_total);
    15* end;
    SQL> /
    before
    28
    after
    28
    PL/SQL procedure successfully completed.
    SQL> select * from emp3;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO TOTAL_EMP
          7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10 28
          7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10 28
          7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
          7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10 28
    14 rows selected.Works for me.. even with the incorrect datatypes.
    You demonstrate exactly what you are doing.

  • To get the count of records and able to access the column value in a single

    Hi
    Is there any way to get the number of records in the query and access the column values
    e.g
    select count(*)
    from
    (SELECT department, COUNT(*) as "Number of employees"
    FROM employees
    WHERE salary > 25000
    GROUP BY department ) a
    This wil only get the Count, if i want to access each row from the inline view how can i do that.

    Your question is not clear.
    Are you looking for total record count as well as count by department ?
    Something like this?
    SQL>
    SQL> with temp as
      2  (
      3  select 1 dept ,10000 sal from dual union
      4  select 1 dept ,25100 sal from dual union
      5  select 1 dept ,30000 sal from dual union
      6  select 1 dept ,40000 sal from dual union
      7  select 2 dept ,10000 sal from dual union
      8  select 2 dept ,25100 sal from dual union
      9  select 2 dept ,30000 sal from dual union
    10  select 2 dept ,40000 sal from dual )
    11  select count(*) over( partition by 1 ) total_count,dept,
    12  count(*) over(partition by dept) dept_cnt  from temp
    13  where sal>25000;
    TOTAL_COUNT       DEPT   DEPT_CNT
              6          1          3
              6          1          3
              6          1          3
              6          2          3
              6          2          3
              6          2          3
    6 rows selected
    SQL>

Maybe you are looking for

  • Key mapping for JOptionPane

    My problem is pretty simple. When presented with a YES_NO_CANCEL option, I want the escape key to trigger the CANCEL operation. I've tried numerous methods including creating my own JOptionPane, adding/removing KeyListeners, etc., but I can't seem to

  • ?xml version="1.0" encoding="UTF-8" ? is missing

    HI, My scenario: Http Post ->PI---->Siebel When they post from source to PI. In source file  <?xml version="1.0" encoding="UTF-8" ?> is missing. It is failing in Request Message Mapping step in pipeline. Can we append this <?xml version="1.0" encodin

  • Report links to Report

    Greetings all, I have no idea why I am confused on what I am trying to do. I have a Report that Generates a tabluar view off all tickets the actual ticket has 25 fields to be filled in, but of course on the tabular view, I only have four of the relev

  • Appraisal Objects created in 'Approved' Planning status

    Good day, When creating Appraisal Template objects, they are created in 'Approved' Planning Status. We want them created in 'Active' Planning Status. We suspect this is the reason why we can't configure/define the process configuration for our templa

  • Is a 100 point increase in 4-6 months feasible?

    Current Scores: EQ-536, TU-548, EX-554 (3) Collections Paid in Full today 12/23(3) Collections will be Paid in Full Friday 12/26(1) Judgement for Portfolio Recovery that I'm clueless on.. having trouble making contact at the courts (calling from out