Count of schema based on the value in a column

I have to write a query to count the number of schema that have the value in a column as '1' in a table For ex
I have a table called Vendor in all the schemas(schema1 through 50) I have to look for the value in a column(Benefits) if it 1 or 0 . I need to do the count of the number of schema who have the Benefits turned ON (value '1')
suppose the value in benefits(col) in Vendor (tbl) for schema1 is 0 than donot count that schema
and if the value in benefits(col) in Vendor (tbl) for schema2 is 1 than count
do i connect as a system manager? Do I need a Pl/sql table to put the count in it
anybody please help.
TX
KK

As I understand from 325537 description, the table VENDOR contains only one row and column BENEFITS_TRACKING is either 0 or 1
In this case the total can be calculated by simply summing the values of all BENEFITS_TRACKING
In case VENDOR has more than one row you need some grouping function like SUM or COUNT
I don't unterstand why you loop through dba_users.
Im quite sure that you won't find a VENDORS table in the SYSTEM schema. The 'execute immediate' will fail with a table not found exception.
Another problem in your code is, you will get no_data_found exception when benefits_tracking=0 because of your where condition
(remove the where-condition or use a grouping function as explained above)
declare
  v_count      pls_integer := 0;
  v_curr_count pls_integer := 0;
begin
  for rec in (select owner from all_tables where owner like 'SCHEMA%' and table_name='VENDORS') loop
      execute immediate 'select SUM(BENEFITS_TRACKING) from '||rec.owner||'.VENDORS' into v_curr_count;
--      execute immediate 'select COUNT(BENEFITS_TRACKING) from '||rec.owner||'.VENDORS where BENEFITS_TRACKING=1' into v_curr_count;
--      execute immediate 'select BENEFITS_TRACKING from '||rec.owner||'.VENDORS' into v_curr_count;
      v_count := v_count + v_curr_count;
  end loop;
  dbms_output.put_line(v_count);
end;

Similar Messages

  • Setting the Link Group Name in  Deep Link based on the value of a column

    Using Jdeveloper 11g, Jheadstart 11g
    Is it possible to override the link group name in deep linking. For example can I conditionally set that field based on the value of the item.
    Regards
    Edited by: aliegeh on Jul 25, 2010 8:35 AM
    Edited by: aliegeh on Jul 25, 2010 8:43 AM

    Thanks for the suggestion.
    Here is what I am trying to do:
    I have a table with one visible column that has the following entries:
    1. Create
    2. Modify
    3. Verify
    4. Approve
    5. View
    If the user clicks on row 1 (Create) then the link group name should be "CreateEmployees" to create new employees
    If the user clicks on row 3 (Verify) then the link group name should be "MaintainEmployees" for verification and so on.
    (This is role based and each role will have access to one or more of the rows in the tabler)
    It basically mimics a work-flow type of scenario.
    I tried to modify the template and looked at the line:
    action="$JHS.facesConfigGenerator.addItemGroupLinkTaskFlowCall((${JHS.Current.item})}" but got stuck there.
    Is there a way to change "JSH.current.item" in the template to read the group link name from another column say by using #if statements.
    One way I also tried was to introduce a column for each action such as CreateAction, VerifyAction etc which kind of agrees with your suggestion but the drawback is the need to modify the table if another task is required.
    Regards
    Edited by: aliegeh on Jul 25, 2010 8:36 AM
    Edited by: aliegeh on Jul 25, 2010 8:42 AM

  • How to get the total number of occurrences based on the value of a column.

    Hello everyone,
    This is the first time that I will ask question here on your forum but has been following several threads ever since. I guess that now is my turn to ask a question. So anyway here is the thing, I have a query that should return count the number of rows depending on the value of SLOT. Something like this:
    WIPDATAVALUE          SLOT             N            M
    1-2                   TRALTEST43S1     1            3
    1-2                   TRALTEST43S1     2            3
    3                     TRALTEST43S1     3            3
    4-6                   TRALTEST43S2     1            4
    4-6                   TRALTEST43S2     2            4
    4-6                   TRALTEST43S2     3            4
    7                     TRALTEST43S2     4            4-----
    As you can see above, on the SLOT TRALTEST43S1, there are three occurrences so M (Total number of occurrences) should be three and that column N should count it. Same goes with the SLOT TRALTEST43S2. This is the query that I have so far:
    SELECT DISTINCT
    WIPDATAVALUE, SLOT
    , LEVEL AS n
    , m
    FROM
      SELECT
        WIPDATAVALUE
        , SLOT
        , (dulo - una) + 1 AS m
      FROM
        SELECT
          WIPDATAVALUE
          , SLOT
          , CASE WHEN INSTR(wipdatavalue, '-') = 0 THEN wipdatavalue ELSE SUBSTR(wipdatavalue, 1, INSTR(wipdatavalue, '-')-1) END AS una
          , CASE WHEN INSTR(wipdatavalue, '-') = 0 THEN wipdatavalue ELSE SUBSTR(wipdatavalue, INSTR(wipdatavalue, '-') + 1) END AS dulo
        FROM trprinting
        WHERE (containername = :lotID OR SLOT= :lotID) AND WIPDATAVALUE LIKE :wip
    ) CONNECT BY LEVEL <= m
    ORDER BY wipdatavalue;And that it results to something like this:
    WIPDATAVALUE          SLOT             N            M
    1-2                   TRALTEST43S1     1            2
    1-2                   TRALTEST43S1     2            2
    3                     TRALTEST43S1     1            1
    4-6                   TRALTEST43S2     1            3
    4-6                   TRALTEST43S2     2            3
    4-6                   TRALTEST43S2     3            3
    7                     TRALTEST43S2     1            1-----
    I think that my current query is basing its M and N results on WIPDATAVALUE and not the SLOT that is why I get the wrong output. I have also tried to use the WITH Statement and it works well but unfortunately, our system cant accept subquery factoring.
    I know you guys will be helping out because you are all awesome. Thanks everyone
    Edited by: 1001275 on Apr 19, 2013 8:07 PM
    Edited by: 1001275 on Apr 19, 2013 8:18 PM

    Hi,
    Sorry, it's still not clear what you want.
    Are you saying that, given this table:
    CREATE TABLE trprinting
      WIPDATAVALUE       VARCHAR2(255)
    , SLOT               VARCHAR2(255)
    INSERT INTO trprinting (wipdatavalue, slot) VALUES ('1-2',  'TRALTEST43S1');
    INSERT INTO trprinting (wipdatavalue, slot) VALUES ('3',    'TRALTEST43S1');
    INSERT INTO trprinting (wipdatavalue, slot) VALUES ('4-6',  'TRALTEST43S2');
    INSERT INTO trprinting (wipdatavalue, slot) VALUES ('7',    'TRALTEST43S2');you want to produce this output:
    WIPDATAVALUE SLOT                     N          M
    1-2          TRALTEST43S1             1          3
    1-2          TRALTEST43S1             2          3
    3            TRALTEST43S1             3          3
    4-6          TRALTEST43S2             1          4
    4-6          TRALTEST43S2             2          4
    4-6          TRALTEST43S2             3          4
    7            TRALTEST43S2             4          4? If so, here's one way:
    WITH     got_numbers     AS
         SELECT     wipdatavalue
         ,     slot
         ,     TO_NUMBER ( SUBSTR ( wipdatavalue
                               , 1
                           , INSTR ( wipdatavalue || '-'
                                ) - 1
                     )          AS low_number
         ,     TO_NUMBER ( SUBSTR ( wipdatavalue
                               , 1 + INSTR ( wipdatavalue
                     )          AS high_number
         FROM     trprinting
    SELECT       wipdatavalue
    ,       slot
    ,       ROW_NUMBER () OVER ( PARTITION BY  slot
                                 ORDER BY          low_number
                        )                    AS n
    ,       COUNT (*)     OVER ( PARTITION BY  slot )     AS m
    FROM       got_numbers
    CONNECT BY     LEVEL               <= high_number + 1 - low_number
         AND     low_number          = PRIOR low_number
         AND     PRIOR SYS_GUID ()      IS NOT NULL
    ORDER BY  low_number
    ,            n
    ;Much of the complexity here is caused by storing 2 numbers in 1 VARCHAR2 column, wipdatavalue. Relational databases work best when there is no more than 1 item in any given column of any given row. This is so basic to datbase design that it is called First Normal Form. Also, numbers belong in NUMBER columns, not VARCHAR2. If you stored your data like that in the fist place, then you wouldn't need the sub-query I called got_numbers, which is about 60% of the code above. (That could be reduced by replacing SUSTR and INSTR with the less efficient REGEGP_SUBSTR.)

  • Input field validation in a Table based on the value of other column

    Hi all
    I have a table with 2 columns. column1 is of text view and  column2 is Input field.
    The user should not be allowed to enter a value  in the column2 ( input field) greater than the value populated in column1(textview).
    So for Eg; if the column1 is populated with value 100, The user should not be able to enter a number greater than 100 in the column2  input field.
    Please let me how this can be achieved.
    I appreciate the help.
    Thanks

    Hi,
    Let me make sure u r working with table control.
    First u have to create a event(VALIDATE) to do the validation.
    Inside the event,
    1. First get the current index where user has pointed the curson
    2. Once u get the index read the internal table with index value.
    3. Now u can compare the col1 and col2 values and populate the error message.
    1. DATA : lo_elt TYPE REF TO if_wd_context_element,
                   l_index type i.
    lo_elt = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
         CALL METHOD LO_ELT->GET_INDEX( RECEIVING  MY_INDEX = l_index.
    above code should be written inside the event.
    Thanks,

  • How can I select and delete rows based on the value in one column?

    I searched through the discussion board, and found a thread on deleting blank rows, but not sure how to modify it to work with my issue.
    I have put together a rather complicated spreadsheet for designing control systems, it calculates parts needed based on check boxes selected in a second spreadsheet.
    Since not all systems require all parts there are many rows that have a 0 quantity value, I would like to select these rows and delete them once I have gone through the design phase (checking off required features on a separate sheet).
    I like the way the other thread I found will gather all the blank rows at the bottom without changing the order of the rows with data in them.
    I don't understand exactly how the formula in the other thread works well enough to modify it to look for a certain column.
    I hope I made myself clear enough here, to recap, I would like to sort the rows based on a zero value in one (quantity) column, move them (the zero quantity rows) to the bottom of the sheet, and then delete the rows with a zero quantity (I can delete them manually, but would like to automate the sorting part).
    Thanks for any help anyone can provide here.
    Danny

    I apologize but, as far as I know, Numbers wasn't designed by Ian Flemming.
    There is no "this column will be auto-destructing after two minutes"
    You will have to use your fingers to delete it.
    I wish to add a last comment :
    if your boss has the bad habit to look over your shoulder, it's time to find an other one.
    As I am really pig headed, it's what I did. I became my own boss so nobody looked over my shoulder.
    Yvan KOENIG (VALLAURIS, France) mercredi 13 juillet 2011 20:30:25
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • Calling multiple sub-reports based on the values in a column in the main report

    All,
    Say, I have a main report with 4 parameters and 8 columns in it's tablix, there is 1 column in this main report that can have 3 values, say A,B,C. If the user clicks on "A", he will be directed to Subreport A, clicks on "B", he will be
    directed to Subreport B and if he clicks on "C", then he'll be taken to Subreport C. All works fine when I call subreport A and B from that column, because both of them have the 4 parameters that we can map back to the parameters of the main report
    in the "Go To Report" section.
    Now, for Subreport C, I'll need to map all those 4 parameters + I will also need to map the parameters in my Subreport C to the FIELDS in the main report. Subreport C has 8 parameters, so 4 of them get mapped to the parameters of the main report and
    the other 4 get mapped to the fields in the main report.
    Now, when I call the Subreport C from my main report, that runs fine, but, I get an error when I try to call my other subreports A and B. The error says "Parameters in the subreport are not defined", probably because it tries to map the fields
    in the main report to the non-existing parameters in mu Subreport A and B.
    Any ideas/suggestions/workarounds would help a lot. Also, if someone can point me to a link where multiple subreports are being called from the column of a main report would be a great help too.

    One simple solution would be to add the additional 4 parameters to subreports A and B. Just don't use them.
    I assume you are calling the subrebort using Go to report action property of the tablix cell control. Try switching to Go to URL. Then use expression builder to dynamically create your url:
    ="http://YourReportServer/Reports/Pages/Reports.aspx?ItemPath=%2fYour%2fReport%2fPath%2fReport"+Fields!Column1.Value+"&Parameter1Name="+Parameters!Param1.Value+"&Parameter2Name="+Parameters!Param2.Value+"&Parameter3Name="+Parameters!Param3.Value+"&Parameter4Name="+Parameters!Param4.Value+IIf(Fields!Column1.Value="C","&Param5="+Fields!F1.Value+""&Param6="+Fields!F2.Value+""&Param7="+Fields!F3.Value+""&Param8="+Fields!F41.Value,"")
    Now this is a rather long formula which is why I prefer just adding the other 4 parameters to all of the subreports but this expression opens the report from the url and only when Column1 field is "C" does it also pass the additional 4 parameters.
    "You will find a fortune, though it will not be the one you seek." -
    Blind Seer, O Brother Where Art Thou
    Please Mark posts as answers or helpful so that others may find the fortune they seek.

  • Conditionally Formatting One Column Based On The Value of Another Column

    I have the following requirement:
    I have 2 columns in a report showing Actual Sales & Budget Sales each year. I am using a bar chart to show the different values for these 2 columns.
    I need to conditionally format the column "Actual Sales" so that if it is less than the "Budget Sales" it will appear in red, and green if "Actual Sales" is greater than "Budget Sales." So in a nutshell,
    CASE WHEN "Actual Sales" < "Budget Sales" THEN
    RED
    ELSE
    GREEN
    END
    Thoughts anyone?

    CASE WHEN (COL1 - COL2) < 0 then Red else Green end
    regards
    John
    http://obiee101.blogspot.com

  • Problem in the code to update a column value based on the value of a column

    Merge into item_TMP S using items I on (S.ITL_ITEM= I.ITEM_ITEM)
    when matched then
    update set
    S.ITL_UOM = I.ITEM_UOM;
    when not matched then null;

    Try
    update Item_TMP set ITL_UOM = (select ITEM_UOM from ITEMS
                                                     where Item_TMP_TMP.ITL_ITEM = ITEMS.ITEM_ITEM
                                                      and items.ITEM_UOM is not null )
    where ITL_ITEM in   (select  ITEMS.ITEM_ITEM from ITEMS
                                                     where items.ITEM_UOM is not null )
    /Cheers, APC
    blog: http://radiofreetooting.blogspot.com

  • Count the number of rows based on the values!!!

    Hi all,
    What I am using:
    I am working with a multidimensional database in Visual Studio 2010 using its Data source view and calculation member and dimension usage.
    What I want to do:
    I have a fact table that has five columns(leg(s),hand(s), Head and body,overall) that shows the category of how severe the injury is. Let say for the records all columns never have an empty value(no injury is stated with 'No injury' ) . These five columns
    are connected with a dimension that has all the available values (Category A-E of injury).The overall has the most severe from the other four columns. I want to create a bar chart with five different measure
    values, one for each column, and count the values in those columns. 
    For example : I have a slicer in the excel and a bar chart and the slicer has all the values of the Category of the injury ( Cat a,Cat B, Cat C, ... Cat E, No injury ) and when i select one of them, lets say
    Cat C,  the bar chart should update and show how many Cat C each measurement column has. 
    Example FACT table:
    ID      LEG      HAND    HEAD   BODY OVERALL
    1        No         A           No        No        A
    2        No        D            C          C         C
    3    E         C            D           A         A
    4         E          E           B            C         B
    So if i selected C the bar chart will count   (Leg = 0, Hand = 1, Head = 1, body = 2 and Overall = 1).
    Any ideas ?
    Thanks for the help and the time :) 

    Hi DBtheoN,
    According to your description, you want to create a chart on excel worksheet to count the rows based on the value, right? If in this case, I am afraid this issue is related to Office forum, I am not the expert of Office, you can post the issue on the corresponding
    forum.
    However, this requirement can be done easily on SQL Server Reporting Services. You can using the expression below to count the rows.
    =COUNT(IIF(Fields!LEG.Value=Parameters!TYPE.Value,1,NOTHING))
    Regards,
    Charlie Liao
    TechNet Community Support

  • Plot a chart dynamically based on the values selected

    Hi All,
    I have some requirement like this i want to plot a chart . The chart should change dynamically based on target_name and date. What type of UI should I use ? I tried using multiselect or shuttle for choosing the target_name and date picker tool for date once i choose all this the chart should appear. Can I have a custom button called submit so once all the values are entered it plots chart ? Please help me out with our ideas.
    Thanks in Advance

    Hi,
    Using the dependent value sets you can govern the values which can be selected based on a specific value selected in a particular segment. Example if Country name is selected in segment 1 then specific states names as per the country selected can be displayed in segment 2.
    As per the requirement described you want to enable different fields based on the value selected in segment1, currently there is no standard mechanism available to enable/disable fields based on a value and you will have to do an extension/customization to meet this requirement.
    Thanks,
    Sanjay

  • Is there an easy way to filter a 2-d array based on the values of two of the fields?

    Is there an easy way to filter a 2-d array based on the values of one of the fields. In my attached VI the output array has the following format:
    TimeStamp        Ident                Frame Type          Bytes    Data
    10:57:07.621   3AD00016   CAN Data Frame   8          0000000000000000
    10:57:07.622   3AD00017   CAN Data Frame   8          000005E000000000
    10:57:07.624   3AD00018   CAN Data Frame   8          0000000003300000
    10:57:07.625   2DC00000   CAN Data Frame   8          0000000000000000
    10:57:07.626   3AD00019   CAN Data Frame    4         0000030000000000
    I would like to delete any rows that do not have an "Ident" between the values of 3AD00000 and 3AD0001E. So for the above data the fourth row would be deleted. The only way I can see to do it is to form a 1-d array. Is there a better approach?
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    CMM_SN_MULTI.vi ‏20 KB

    Hi chuck72352,
    after you have sorted your data, you can use the InRange Function. Combined with a "search 1D Array" you'll get the range you really want.
    Mike
    Attachments:
    ArraySubset.PNG ‏25 KB

  • Autopopulate data in listitem based on the value of data in other itemlist

    Hi,
    In my project there is requirement of populating the data in based on the value populated in other list item.
    For ex in list box item we select value 'PE' then in second list box based value of PE should be populated.If we select other value for ex 'PA' then in second list other valu is populated.So how can we populate the data in second itemlist based on the value selected in the first listitem

    Hello,
    <p>In this article, you can find a dialog sample that does that (section : 2.4.2)</p>
    Francois

  • SSIS - Loop through files from a file path based on the value in the variable

    Experts,
    I have a requirement where I'll be loading multiple files in to a SQL server table and archive the files when loaded. However, the challenge is , the file path should be dynamic based on the value of a variable (say, @ProductName).
    For example: If I am running the package for variable @ProductName="Product", the file path would be "\\....\Src\Product", in that case the ForEachLoop will loop through all the files in that folder, load them to the table and Archive
    the files to the "\\....\Src\Product\Archive" folder.
    Similarly, if the @ProductName="Product_NCP", the foreachloop container should loop through files in the "\\....\Src\Product_NCP" folder, load them to the table and archive them to the ""\\....\Src\Product_NCP\Archive"
    folder.
    Any suggestions? I should be able to run the package manually just by passing the "@Product" value, create Archive folder if it doesn't exist, load the data and archive the files.

    Yes
    1. Have a variable inside SSIS to get folder path. Set path based on your rule using an expression
    like
    (@[User::ProductName] == "Product" ? "\\....\Src\Product" : (@[User::ProductName] == "Product_NCP" ? \\....\Src\Product_NCP:..))
    similary archive
    (@[User::ProductName] == "Product" ? "\\....\Src\Product\Archive" : (@[User::ProductName] == "Product_NCP" ? "\\....\Src\Product_NCP\Archive" :..))
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • F4 help based on the Value in other field

    Hello
    I have a requirement in which there are two fields say field1 and field 2 in an ALV grid (in which  new data can be entered). The F4 help of field 2 should be based on the value  the user enters on field1.I have checked out the BC_ALV* programs but there are no clear help .
    I have tried setting the parameter id of the first field value and then get that parameter id on_f4 event of the second field.But where can i set the parameter id of the first field . on_f4 of first field does not have its value and there is no event after_f4 . There is a parameter e_afterf4 in data change event but to tirgger that there shud be some event right.
    Moreover If at all i get the first field value , i can use FM F4_int_table_value_request to show the refined f4 in field 2 . But I am passing the a field symbol table in my grids set table for first display . what can i pass as parameters here to the FM  F4_int_table_value_request?

    hello Kallu ,
      gt_f4_wa-getbefore  = 'X'. --->refreshing layout before F4
      gt_f4_wa-chngeafter = 'X'--> refreshing layout after f4.
    see the sample code of F4...no need to pass dynpro details.....
    *---locals.
      data:  lt_return type table of ddshretval,
             ls_return type ddshretval,
             begin of lt_kostl occurs 0,
              kokrs type kokrs,
              datbi type datbi,
              bukrs type bukrs,
              prctr type prctr,
             end of lt_kostl,
             ls_f4           type  lvc_s_modi.
      field-symbols: <ls_wa>         type any,
                    <t_f4> type lvc_t_modi.
    *---get defalut values.
      refresh lt_kostl.
      select kokrs
             kostl as prctr
             datbi
             bukrs
        from csks
        into  corresponding fields of table lt_kostl
               where kokrs eq g_kokrs
                 and datbi ge sy-datum
                 and bukrs eq yfit_00049-bukrs.
    *---call fm to display int values.
      call function 'F4IF_INT_TABLE_VALUE_REQUEST'
        exporting
          retfield        = 'YFIT_00050-PRCTR'
          window_title    = 'Profit Center list'
          value_org       = 'S'
          display         = space
        tables
          value_tab       = lt_kostl
          return_tab      = lt_return
        exceptions
          parameter_error = 1
          no_values_found = 2
          others          = 3.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      else.
        read table lt_return into ls_return
                   with key fieldname = 'F0004'.
        if sy-subrc eq 0.
          assign er_event_data->m_data->* to <t_f4>.
          ls_f4-fieldname = e_fieldname.
          ls_f4-row_id    = es_row_no-row_id.
          ls_f4-value     = ls_return-fieldval.
          ls_f4-error     = space.
          ls_f4-tabix     = space.
          ls_f4-style     = space.
          ls_f4-style2    = space.
          ls_f4-style3    = space.
          ls_f4-style4    = space.
          append ls_f4 to <t_f4>.
        endif.
      endif.
      er_event_data->m_event_handled = 'X'.
    regards
    Prabhu

  • ADF Table cell color based on the value in that field

    Dear All,
    I want to create a table for our new application which contains a table used to represent the data in a chart format or matrix format,
    and each cell of the table should be filled with a colour out of three colors, based on the value belongs to which range eg:(1-8 ->green, 9-20 - yellow etc),
    I dont know how to implement this. Please help...
    Ranjith

    Check this out.
    How to highlight ADF table row based on column value?
    -Arun

Maybe you are looking for

  • Cant update Itunes/MacOS. say installer package is in trash

    I was trying to update my itunes so i could use the itunes store. When I install the MacOS update a message pops up saying that the installer package is in the trash. There are no files in the trash and Im guessing It was deleted. Anyone have a way o

  • Stamps not on printed document

    When I print a document that has stamps on it (check mark, etc) the stamps do not show up. 

  • Pixma MG5320 won't print to CD

    I just bought a new Canon printer to replace my old Epson R200. But now I feel very disappointed because I have tried to print to a CD with the software included and also with Surething Disc Labeler Gold 6, but it does not matter what I do, the print

  • Hyperion Financial Reports Run-time error '429' ActiveX error:

    Hi All, When i open a Hyperion Financial Reports i am getting an error: Run-time error '429' ActiveX component can't create object, If anybody having same issue, please let me know, any help will be appreciated.. Thanks

  • Question about downloading of Lightroom 4

    Hi, I bought Lightroom 4 in 2012. Now I have a new PC. Anyone who knows what to do to get access to the sw on my new PC?