View with a dynamic formula column

Hi all,
I have a view that has stock transaction columns like quantity received, quantity issued,receive unit price, issue unit price.
I want to calculate the moving average cost which depends on all of these columns.
Can i create a column in the view that calculates the moving average cost for any transaction, which is dependant on all the previous transactions to finally get the moving average cost for all the transactions ( like what we get from Excell) ?
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Prod
PL/SQL Release 10.1.0.2.0 - Production
CORE 10.1.0.2.0 Production
TNS for 32-bit Windows: Version 10.1.0.2.0 - Production
NLSRTL Version 10.1.0.2.0 - Production
Please help me

Hi
In addition to the procedure i told before, i also wrote this code to get the moving average cost and it's giving the required result, the next step is to update the base tables with moving average cost from this query.
select t1.*
,sum(rate*qty ) OVER (partition by store_no,stock_code order by store_no,stock_code ROWS BETWEEN UNBOUNDED PRECEDING AND
CURRENT
ROW ) AS cum_amount
,(sum(rate*qty ) OVER (partition by store_no,stock_code order by store_no,stock_code ROWS BETWEEN UNBOUNDED PRECEDING AND
CURRENT
ROW )
/cum_qty) moving_avg_cost
from
select store_no,stock_code,qty
, decode(sign(Qty),-1,
lag(avg_cost,1,avg_cost)OVER (partition by store_no,stock_code order by store_no,stock_code ),rcv_ucost) rate
,(qty*decode(sign(Qty),-1,
lag(avg_cost,1,avg_cost)OVER (partition by store_no,stock_code order by store_no,stock_code ),rcv_ucost) ) amount
,cum_qty
from
(with a as
(select '1' store_no,'0101001' stock_code,10 qty,5 rcv_ucost
FROM dual
union all
select '1' store_no,'0101001' stock_code,-5 qty,null rcv_ucost
FROM dual
union all
select '1' store_no,'0101001' stock_code,30 qty,8 rcv_ucost
FROM dual
union all
select '1' store_no,'0101001' stock_code,-10 qty,null rcv_ucost
FROM dual
union all
select '1' store_no,'0101001' stock_code,8 qty,12 rcv_ucost
FROM dual
union all
select '1' store_no,'0101002' stock_code,10 qty,10 rcv_ucost
FROM dual
union all
select '1' store_no,'0101002' stock_code,-3 qty,null rcv_ucost
FROM dual
union all
select '1' store_no,'0101002' stock_code,20 qty,12 rcv_ucost
FROM dual
union all
select '1' store_no,'0101002' stock_code,-5 qty,null rcv_ucost
FROM dual
union all
select '1' store_no,'0101002' stock_code,4 qty,14 rcv_ucost
FROM dual)
select store_no,stock_code,qty,rcv_ucost,sum(qty) OVER (partition by store_no,stock_code order by store_no,stock_code ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT
ROW ) AS cum_qty
,(sum(qty*rcv_ucost ) OVER (partition by store_no,stock_code order by store_no,stock_code ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT
ROW ) /
sum(qty) OVER (partition by store_no,stock_code order by store_no,stock_code ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT
ROW )) avg_cost
from a ) T
)t1;
If you have any improvments to this code don't hesitate to tell me.
Regards
Mostafa Abolaynain

Similar Messages

  • DB view with flexible number of columns?

    In my Oracle 10 I have these tables
    Customer table:
    id      customer
    1       John
    2       Bob
    Item table
    id      item_name
    1       itemA
    2       itemB
    3       itemC
    4       itemD
    Purchase table:
    id      item_id date    customer_id
    1       3       070202  2
    2       6       070203  5
    ...I'd like to create a view like this:
            itemA   itemB   itemC   itemD   ...
    John    3       4       0       0       ...
    Bob     0       3       0       0       ...
    ...The view showed John purchased itemA 3 times, item B 4 times. Bob purchased itemB 3 times. This assume each customer only by one item at a time, which is a reasonable simplification of my situation.
    Such a view (with variable number of columns) is needed not in our web application but also provide an understandable data source for non IT professional to use report software. If my approach of solving this problem is completely wrong, I'd also like to know what's the common practice. Thank you very much in advance!
    Message was edited by:
    user609663

    I have tried to ask the question in a way that greatly simplify current problem to make it easy for others to understand without having to explain a lot of background information and 'the situation'; it seems I over-simplified the issue to make it even not worth solving or a wrong question being asked. So here I explain the complete problem and look for advice again (be prepared, pretty long description following:). I am a purchased customer of Oracle 10 DB and I reasonably expect being considered as Oracle user looking for help rather than students trying to play smart with assigned data normalization course exercises.
    We are working on a system that collects data from interview results. The questionnaires for the interviews are formatted with a coded question, followed by user's answer to the question, like the following:
         Question Code   Question content   Answer
         H001            ...                123
         H002            ...                45
         H003            ...                33
         H004            ...                66
         H005            ...                4,66
         ...             ...                ...The users answer question with a digit, for some special questions, e.g. H005, they are allowed to answer with a set of digits. There are thousands of interviews each year, the simplest solution to collect the interview answers is to use such a db table:
    simple_db_table:
    id   H001  H002  H003  H004  H005  H006  H007
    1    123   45    33    66    4     82    9
    ...This solution have two problems:
    1. It doesn't properly store answers to questions that requre a set of digits, like H005.
    2. The number of questions and their codes change from one survey to another, but the table have fixed number of columns and column names.
    And two benefit:
    1. With such simple table, people who use report software that directly access oracle db can creat their reports on easy-to-understand data presentation;
    2. calculation based on questionnaire data is simple, e.g. get the average of H007/H009 for questionnaires that have H002 > H003 * 600 would be:
    SELECT SUM(H007) / SUM(H009) FROM simple_db_table WHERE H002 > H003 * 600;Next solution we have normalized tables:
    questionnaire_entry_table:
    id                 NUMBER
    questionnaire_name CHARquestionnaire_definition_table:
    id                 NUMBER
    questionnaire_id   NUMBER
    question_code      CHAR
    question_content   VARHCARinterview_table:
    id                 NUMBER
    questionnaire_id   NUMBER
    date               DATEquestionnaire data table: itv_data
    id                 NUMBER
    interview_id       NUMBER
    question_code      CHAR
    answer             NUMBERWith the new structure, it just turn the problems of simple_db_table to its benefit and simple_db_table's benefit become the problem:
    1. Personnel who use report creation software feel too confused to make report based on such tables, because they do not understand the normalized modeling. In our case, effective training is difficult because there will be many geographically distributed people make reports based on this structure and they have lower IT knowledge than database administrators. These personnel can make reports based on simple_db_table.
    2. calculation based on questionnaire data is very difficult.
    To explain 2, let's take the same example, we still wish to get the average of H007/H009 for questionnaires that have H002 > H003 * 600, my method is:
    setp 1: create a view with by using:
           CREATE VIEW v (id, H002, H003) AS
           SELECT a.itv_id, a.H002, b.H003
             FROM itv_data a, itv_data b
           WHERE a.interviewee_id=b.interviewee_id
             AND a.question_code='H002' AND b.question_code='H003';step 2: create a stored procedure to get the calculation result:
           CREATE OR REPLACE PROCEDURE get_result (result OUT NUMBER) IS
             sh007 NUMBER := 0;
             sh009 NUMBER := 0;
           BEGIN
             SELECT SUM(H007) INTO sh007 FROM itv_data
               WHERE itv_id in (SELECT id FROM v WHERE H002 > H003 * 683);
             SELECT SUM(H009) INTO sh009 FROM itv_data
               WHERE itv_id in (SELECT id FROM v WHERE H002 > H003 * 683);
             idc := sh007/sh009;
           END get_idc;As you can see the calculation become much more complex and might involve overhead.
    There might be better way to calculate the result that I don't know yet. We have some 100 different formulas to calculate different results, so it's important to get them right and efficiently.
    The best solution seems to me is that to create such a view from itv_data and other tables so that to reflect the same structure of simple_db_table. So here comes the question I originally asked how is it possible to create a view with flexible number of columns. I made the very simple example in my original posted message wishing to get an idea of this is possible or the way to go.
    I may be taking a completely wrong approach to attack the problem, e.g. perhaps there is a simpler way to get_result from itv_table and for report creation users I should use a metadata layer on top of the normalized table structure (e.g. by using Metadata Query Language from Pentaho BI). But anyway I'd like to get some insightful ideas from the forum. Again thanks for help in advance.

  • Problems on selecting views with french characters into column names

    Hi All,
    I have views with column names such as "Détermination Planimétriq" or "Année de construction:*";
    I can get in my c# function this columns names from ALL_VIEWS dictionary table, but if I try to make a selectionby use of an OracleCommand, Oracle returns an "Invalid identifier" error:
    SELECT "Détermination Planimétriq" FROM mytable;
    System.Data.OracleClient.OracleException (0x80131938): ORA-00904: "Determination Planimetriq": invalid identifier at System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc) at ...
    Any suggestion?...

    Be wary of using character codes outside the Western European "simple" alphanumeric [A-Z0-9] for object names, i.e. columns, table names, function and procedure names, and so on.
    First reason, there is a 30 character limit for most object names, and characters that have to be spelled out with unicode characters take more space, i.e.:
    select dump( 'Détermination Planimétriq'  ) from dual;
    DUMP('D?TERMINATIONPLANIM?TRIQ')
    Typ=96 Len=29: 68,239,[ ... ]Although the varchar string for that column name looks like 25 characters, it needs room for 29 to store the e<acute> character. And could also depend on the client settings. Using case sensitive names is not a best practice, its better to avoid specifying objects with the double quotes.
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements008.htm#i27570

  • Materialized view with  a dynamic column.

    Hi,
    Is it possible to use the materialized view as a function.
    A column of the view is dynamic, meaning we enter a parameter in the view.
    thanks

    Once I called exp/imp from forms. That didn't make export errors due to data corruption a forms problem...
    cheers

  • List "View" with current time in column

    Hi.
    I know that list view does not support fields calculated on page load. But I have to realize such functionality.
    Can someone provide options for realizing this?
    "Hack" some internal SQL query, inject JS on a view page, use .NET code somehow?
    Using JS seems as the best solution, but how can I do this?
    Thanks.

    Hi,
    According to your post, my understanding is that you wanted to display the current time in colum.
    The following code snippet for your reference.
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    function date(format, timestamp) {
    var that = this,
    jsdate, f, formatChr = /\\?([a-z])/gi,
    formatChrCb,
    // Keep this here (works, but for code commented-out
    // below for file size reasons)
    //, tal= [],
    _pad = function(n, c) {
    n = n.toString();
    return n.length < c ? _pad('0' + n, c, '0') : n;
    txt_words = ["Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    formatChrCb = function(t, s) {
    return f[t] ? f[t]() : s;
    f = {
    // Day
    d: function() { // Day of month w/leading 0; 01..31
    return _pad(f.j(), 2);
    D: function() { // Shorthand day name; Mon...Sun
    return f.l().slice(0, 3);
    j: function() { // Day of month; 1..31
    return jsdate.getDate();
    l: function() { // Full day name; Monday...Sunday
    return txt_words[f.w()] + 'day';
    N: function() { // ISO-8601 day of week; 1[Mon]..7[Sun]
    return f.w() || 7;
    S: function() { // Ordinal suffix for day of month; st, nd, rd, th
    var j = f.j();
    if (j < 4 || j > 20) {
    return (['st', 'nd', 'rd'])[j % 10 - 1];
    else {
    return 'th';
    w: function() { // Day of week; 0[Sun]..6[Sat]
    return jsdate.getDay();
    z: function() { // Day of year; 0..365
    var a = new Date(f.Y(), f.n() - 1, f.j()),
    b = new Date(f.Y(), 0, 1);
    return Math.round((a - b) / 864e5);
    // Week
    W: function() { // ISO-8601 week number
    var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3),
    b = new Date(a.getFullYear(), 0, 4);
    return _pad(1 + Math.round((a - b) / 864e5 / 7), 2);
    // Month
    F: function() { // Full month name; January...December
    return txt_words[6 + f.n()];
    m: function() { // Month w/leading 0; 01...12
    return _pad(f.n(), 2);
    M: function() { // Shorthand month name; Jan...Dec
    return f.F().slice(0, 3);
    n: function() { // Month; 1...12
    return jsdate.getMonth() + 1;
    t: function() { // Days in month; 28...31
    return (new Date(f.Y(), f.n(), 0)).getDate();
    // Year
    L: function() { // Is leap year?; 0 or 1
    var j = f.Y();
    return j % 4 === 0 & j % 100 !== 0 | j % 400 === 0;
    o: function() { // ISO-8601 year
    var n = f.n(),
    W = f.W(),
    Y = f.Y();
    return Y + (n === 12 && W < 9 ? 1 : n === 1 && W > 9 ? -1 : 0);
    Y: function() { // Full year; e.g. 1980...2010
    return jsdate.getFullYear();
    y: function() { // Last two digits of year; 00...99
    return f.Y().toString().slice(-2);
    // Time
    a: function() { // am or pm
    return jsdate.getHours() > 11 ? "pm" : "am";
    A: function() { // AM or PM
    return f.a().toUpperCase();
    B: function() { // Swatch Internet time; 000..999
    var H = jsdate.getUTCHours() * 36e2,
    // Hours
    i = jsdate.getUTCMinutes() * 60,
    // Minutes
    s = jsdate.getUTCSeconds(); // Seconds
    return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3);
    g: function() { // 12-Hours; 1..12
    return f.G() % 12 || 12;
    G: function() { // 24-Hours; 0..23
    return jsdate.getHours();
    h: function() { // 12-Hours w/leading 0; 01..12
    return _pad(f.g(), 2);
    H: function() { // 24-Hours w/leading 0; 00..23
    return _pad(f.G(), 2);
    i: function() { // Minutes w/leading 0; 00..59
    return _pad(jsdate.getMinutes(), 2);
    s: function() { // Seconds w/leading 0; 00..59
    return _pad(jsdate.getSeconds(), 2);
    u: function() { // Microseconds; 000000-999000
    return _pad(jsdate.getMilliseconds() * 1000, 6);
    // Timezone
    e: function() { // Timezone identifier; e.g. Atlantic/Azores, ...
    // The following works, but requires inclusion of the very large
    // timezone_abbreviations_list() function.
    /* return that.date_default_timezone_get();
    throw 'Not supported (see source code of date() for timezone on how to add support)';
    I: function() { // DST observed?; 0 or 1
    // Compares Jan 1 minus Jan 1 UTC to Jul 1 minus Jul 1 UTC.
    // If they are not equal, then DST is observed.
    var a = new Date(f.Y(), 0),
    // Jan 1
    c = Date.UTC(f.Y(), 0),
    // Jan 1 UTC
    b = new Date(f.Y(), 6),
    // Jul 1
    d = Date.UTC(f.Y(), 6); // Jul 1 UTC
    return ((a - c) !== (b - d)) ? 1 : 0;
    O: function() { // Difference to GMT in hour format; e.g. +0200
    var tzo = jsdate.getTimezoneOffset(),
    a = Math.abs(tzo);
    return (tzo > 0 ? "-" : "+") + _pad(Math.floor(a / 60) * 100 + a % 60, 4);
    P: function() { // Difference to GMT w/colon; e.g. +02:00
    var O = f.O();
    return (O.substr(0, 3) + ":" + O.substr(3, 2));
    T: function() { // Timezone abbreviation; e.g. EST, MDT, ...
    // The following works, but requires inclusion of the very
    // large timezone_abbreviations_list() function.
    /* var abbr = '', i = 0, os = 0, default = 0;
    if (!tal.length) {
    tal = that.timezone_abbreviations_list();
    if (that.php_js && that.php_js.default_timezone) {
    default = that.php_js.default_timezone;
    for (abbr in tal) {
    for (i=0; i < tal[abbr].length; i++) {
    if (tal[abbr][i].timezone_id === default) {
    return abbr.toUpperCase();
    for (abbr in tal) {
    for (i = 0; i < tal[abbr].length; i++) {
    os = -jsdate.getTimezoneOffset() * 60;
    if (tal[abbr][i].offset === os) {
    return abbr.toUpperCase();
    return 'UTC';
    Z: function() { // Timezone offset in seconds (-43200...50400)
    return -jsdate.getTimezoneOffset() * 60;
    // Full Date/Time
    c: function() { // ISO-8601 date.
    return 'Y-m-d\\TH:i:sP'.replace(formatChr, formatChrCb);
    r: function() { // RFC 2822
    return 'D, d M Y H:i:s O'.replace(formatChr, formatChrCb);
    U: function() { // Seconds since UNIX epoch
    return jsdate / 1000 | 0;
    this.date = function(format, timestamp) {
    that = this;
    jsdate = (timestamp === undefined ? new Date() : // Not provided
    (timestamp instanceof Date) ? new Date(timestamp) : // JS Date()
    new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
    return format.replace(formatChr, formatChrCb);
    return this.date(format, timestamp);
    $(function() {
    $('.ms-noWrap').text(date('l, F jS, Y, h:i:s A'));
    </script>
    Note: You should change the class name to fit your environment.
    http://jsfiddle.net/licson0729/jHHsm/
    More reference:
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/580b9c50-f945-4931-b68f-da68d84e766e/how-to-display-current-date-time-in-share-point-using-jquery
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Create materialized view with specific column sizes

    Hi all,
    I'm trying to create a materialized view with a specific a column size. Something like
    create materialized view test_mv
    refresh force on demand
    as
    select id,
           cast(my_compound_field as nvarchar2(50))
    from ( select id,
                  field1 || field2 my_compound_field
           from   my_table);But Oracle seems to ignore the cast and takes the maximum size it finds for field1 || field2 in the select query. The resulting table has a column nvarchar2(44) instead of nvarchar2(50).
    This can give a problem when the view is refreshed... there could be new data that exceeds the current size, i.e. where length(field1 || field2) > 44.
    How can I override the column size of a field in a materialized view?
    Edit: Some additional info to clarify my case:
    field1 and field2 are defined as nvarchar2(25). field1 || field2 can theoretically have a length of 50, but there is currently no data in my table that results in that length, the max is 44. I am afraid that there will be data in the future that exceeds 44, resulting in an error when the MV is refreshed!
    Edited by: Pleiadian on Jan 25, 2011 2:06 PM

    Cannot reproduce what you are saying is happening.
    SQL> create table t (a nvarchar2(50), b nvarchar2(50));
    Table created.
    SQL> create materialized view tmv as
      2  select a, b, a || b c from t;
    Materialized view created.
    SQL> desc tmv
    Name                                      Null?    Type
    A                                                  NVARCHAR2(50)
    B                                                  NVARCHAR2(50)
    C                                                  NVARCHAR2(100)
    SQL> drop materialized view tmv;
    Materialized view dropped.
    SQL> create materialized view tmv as
      2  select a, b, substr(a || b, 1, 10) c from t;
    Materialized view created.
    SQL> desc tmv
    Name                                      Null?    Type
    A                                                  NVARCHAR2(50)
    B                                                  NVARCHAR2(50)
    C                                                  NVARCHAR2(10)
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    SQL>Edited by: 3360 on Jan 25, 2011 8:10 AM
    And with data
    SQL> insert into t values ('3123423423143hhshgvcdcvw', 'ydgeew  gdfwe   dfefde  wfjjjjjjj');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> desc tmv
    Name                                      Null?    Type
    A                                                  NVARCHAR2(50)
    B                                                  NVARCHAR2(50)
    C                                                  NVARCHAR2(10)
    SQL> select * from tmv;
    A
    B                                                  C
    3123423423143hhshgvcdcvw
    ydgeew  gdfwe   dfefde  wfjjjjjjj                      3123423423

  • SUB Totals within a Dynamic Data Column

    Has anyone ever calculated SUB Totals in a Layout with a Dynamic Data Column?
        The TOTAL for all data is expressed on the Data Column tab of the Layout as C(1):C(1) - 0FISCPER / Posting Period is the Dynamic Characteristic.  When the system actually displays the 12 columns of data for the Year, the formula for TOTAL is also adjusted - no problem here.  But the user also wants SUB Totals, by Quarter, within the Year.
        Any insight or suggections are appreciated !
    Thanks,
    Lyle

    Hello,
    use variables Q1, ..., Q4 for the quarters and create
    data colums as follows
    1 Q1 dynamic = X
    2 Total C(1)
    3 Q2 dynamic = X
    4 Total C(3)
    5 Q3 dynamic = X
    6 Total C(5)
    7 Q4 dynamic = X
    8 Total C(7)
    9 Year Total C(2)C(4)C(6)+C(8)
    Regards,
    Gregor

  • Table with more than 35 columns

    Hello All.
    How can one work with a table with more than 35 columns
    on JDev 9.0.3.3?
    My other question is related to this.
    Setting Entities's Beans properties from a Session Bean
    bought up the error, but when setting from inside the EJB,
    the bug stays clear.
    Is this right?
    Thank you

    Thank you all for reply.
    Here's my problem:
    I have an AS400/DB2 Database, a huge and an old one.
    There is many COBOL Programs used to communicate with this DB.
    My project is to transfer the database with the same structure and the same contents to a Linux/ORACLE System.
    I will not remake the COBOL Programs. I will use the existing one on the Linux System.
    So the tables of the new DB should be the same as the old one.
    That’s why I can not make a relational DB. I have to make an exact migration.
    Unfortunately I have some tables with more than 5000 COLUMNS.
    Now my question is:
    can I modify the parameters of the ORACE DB to make it accept Tables and Views with more than 1000 columns, If not, is it possible to make a PL/SQL Function that simulate a table, this function will insert/update/select data from many other small tables (<1000 columns). I want to say a method that make the ORACLE DB acting like if it has a table with a huge number of columns;
    I know it's crazy but any idea please.

  • Dashboard view with charts

    Hello,
    I have 10 queries in different workbooks with chart views.  Now I need to create a new workbook for the dashboard view.
    This dashboard view will link all the charts from the 10 workbooks with the queries.  The charts are created from the pivot tables and all the charts are dynamic. I would like to create a dashboard view with similar dynamic charts. 
    I cannot use WAD. I do not want to combine all the queries into one workbook since each query is big and it will affect the performance.
    Any valuable answer with be assigned with points.
    Raadooo
    Edited by: Raadooo on Jul 21, 2008 10:31 PM

    Thanks everyone, after all, this response from Oracle Support helped to solve the problem:
    "Actually this is a refreshing bug in the flash player lower that 11.4 which is used by default in Google Chrome ( see http://code.google.com/p/chromium/issues/detail?id=140415 ), which is used to display charts in 11.1.1.6.2
    This issue is fixed in the latest OBIEE bundle patch 11.1.1.6.5
    Please see the action plan below.
    Thanks,
    Shady
    === ODM Action Plan ===
    Please review the readme of the start-up patch
    Patch 14696072 Patch 11.1.1.6.5 (1 of 7) Oracle Business Intelligence Installer
    for the full steps to apply this patchset.
    Bundled Patch Details
    (1 of 7) Oracle Business Intelligence Installer. Patch 14696072
    (2 of 7) Oracle Real Time Decisions. Patch 14733356
    (3 of 7) Oracle Business Intelligence Publisher. Patch 14678543
    (4 of 7) Oracle Business Intelligence ADF Components. Patch 14733390
    (5 of 7) Enterprise Performance Management Components Installed from BI Installer 11.1.1.6.x. Patch 14733413
    (6 of 7) Oracle Business Intelligence. Patch 14665284
    (7 of 7) Oracle Business Intelligence Platform Client Installers and MapViewer Patch 14733370
    To install this bundle patch, please follow the readme of the first Patch 14696072"

  • View with dynamic columns

    Hello.
    I'm sure this must be a FAQ but can't find it anywhere.
    I'm collecting data from people in a questionnaire style but don't know what/how many questions there are. I need to create a view that displays responses to each of the questions as a view, as follows:
    Name | Company | Favourite Colour | Age Range | Favourite Food
    In this example, there are three 'dynamic' questions. The data is stored as follows:
    People - basic information about the respondents
    Questions - the names of the questions being asked
    Choices - the options that can be chosen from for each question
    Responses - the answers that people provide.
    If I know exactly what questions there are, then I can JOIN to the questions table the appropriate number of times. But I don't! Can this be done without dynamic SQL?
    Very many thanks for help.
    Simplified tables and data follow:
    CREATE TABLE [People](
    [ID] [int] NULL,
    [Name] [varchar](50) NULL,
    [Company] [varchar](50) NULL
    ) ON [PRIMARY]
    GO
    CREATE TABLE [Questions](
    [ID] [int] NULL,
    [QuestionName] [varchar](50) NULL
    ) ON [PRIMARY]
    GO
    CREATE TABLE [Choices](
    [ID] [int] NULL,
    [QuestionID] [int] NULL,
    [ChoiceName] [varchar](50) NULL
    ) ON [PRIMARY]
    GO
    CREATE TABLE [Responses](
    [ID] [int] NULL,
    [PersonID] [int] NULL,
    [QuestionID] [int] NULL,
    [ChoiceID] [int] NULL,
    [OtherText] [varchar](50) NULL
    ) ON [PRIMARY]
    GO
    INSERT [People] ([ID], [Name], [Company]) VALUES (1, N'Ben', N'ACME')
    GO
    INSERT [People] ([ID], [Name], [Company]) VALUES (2, N'Dave', N'My Corp')
    GO
    INSERT [People] ([ID], [Name], [Company]) VALUES (3, N'Sarah', N'Newco')
    GO
    INSERT [Questions] ([ID], [QuestionName]) VALUES (1, N'FavouriteColour')
    GO
    INSERT [Questions] ([ID], [QuestionName]) VALUES (2, N'AgeRange')
    GO
    INSERT [Questions] ([ID], [QuestionName]) VALUES (3, N'FavouriteFood')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (1, 1, N'Red')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (2, 1, N'Blue')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (3, 1, N'Green')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (4, 2, N'<18')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (5, 2, N'18-65')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (6, 2, N'65+')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (7, 3, N'Pasta')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (8, 3, N'Curry')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (9, 3, N'Steak')
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (1, 1, 1, 1, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (2, 1, 2, 1, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (3, 1, 3, 2, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (4, 2, 1, 4, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (5, 2, 2, 5, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (6, 2, 3, 6, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (7, 3, 1, 7, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (8, 3, 2, 9, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (9, 3, 3, 9, NULL)
    GO

    I'm not into reporting tools, but I recall that Kalman has mentioned some component in Reporting Services that can do this. And obviously, if you receive the result set as a DataTable in .NET, you can write code to flip it.
    As I said, a view or a result set in a relational database is a table that is supposed to model an enitity with a finite number of distinct attributes. For this reason, any query where the number of columns is not known until run-time has to build dynamically.
    And since a relational database is not designed for handling such dynamic scenarios, all attempt to work with that dynamically generated result set will be painful.
    So for the filters you mention, there are two options:
    1) Filter in the database on the base tables.
    2) Filter in the client on the pivoted data.
    But don't get the idea to filter in SQL Server after the pivot.
    If the total dataset is large, the first alternative certainly has an advantage, but else it's likely to be easier to do client side.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Materialized view with dynamic column names !

    hello,
    i need some help , i'm trying ( i got no where so far :) ) to create a materialized
    view that has dynamic field name values , so every time the view is refreshed
    the fields are renamed.
    i have been asked to create a decade summary view and to assign year values to field names,the years should be table columns ( not rows !? ) and thus i should reflect this fact to the column names.
    i know its a wierd request but is there anway to do it ?
    i dunno about it at least,
    Thanks !

    ...or you could define the materialised view neutrally e.g. with columns like YEAR1, YEAR2 etc.
    Then create a dynamically-defined view on top of this view, after it's refreshed, using the relevant years as column names. SELECT year1 AS "1991", year2 AS "1992" etc.
    I still don't see how anybody is going to use these views as they won't know what the "year" columns are called.
    And if the same materialised view is going to have different sets of data each time it's refreshed i.e. different sets of years, are you re-defining the selection criteria each time? If so, why not just define separate views?
    It's a weird world out there...

  • How to add a column to a list created with the Dynamic List Wizard to display the values of the fiel

    Hi,
    ADDT, Vista, WAMP5.0
    We have 2 tables: clients_cli (id_cli, name_cli, tel_cli, and several more fields) and cases_cas (id_cas, idcli_cas, court_cas, and a lot of other fields).
    Clients may have many cases, so table cases_cas have a foreign key named idcli_cas, just to determine which case belongs to which client.
    We designed the lists of the two tables with the Dynamic List Wizard and the corresponding forms with Dynamic Form Wizard.
    These two forms are linked with the Convert Dynamic List and Form Wizards, which added a button to clients list named "add case".
    We add a client and then the system returns to the clients list displaying all clients, we look for the new client just added and then press "add case", which opens the Dynamic Form for cases, enter all case details and everything processes ok.
    However, when we view the cases list it display all the details of the case, including the column and values for the foreign key idcli_cas. As you can image, it is quite difficult for a human to remember the clients ids.
    So, in the cases list we added a another column, named it Name, to display the names of the clients along with cases details. We also created another recordset rsCli, selected the clients_cli table, displaying all columns, set filter id_cli = Form Variable = idcli_cas then press the Test button and everything displays perfect. Press ok.
    Then, we position the cursor inside the corresponding cell of the new Name column, go to Bindings, click on name_cli and then click on insert. The dynamic field is inserted into the table cell as expected, Save the page, and test in browser.
    The browser call the cases list but fails to display the values of the Name column. The Name column is simply empty.
    This issue creates a huge problem that makes our application too difficult to use.
    What are we doing wrong?
    Please help.
    Charles

    1.     Start transaction PM01, Create Infotype, by entering the transaction code.
    You access the Create Infotype screen.
    2.     Choose List Screen.
    3.     In the Infotype no. field, enter the four-digit number of the infotype you want to create.
    When you specify the infotype number, please remember to enter any leading zeros.
    4.     In the Screen Number field, enter the screen number of the list screen you want to enhance.
    5.     Choose Create.
    The Dictionary: Initial screen appears:
    6.     Create the list screen structure.
    7.     Choose Activate.
    8.     Return to the Enhance List Screen in the Enhance Infotypes transaction (PM01).
    9.     Choose Create All.
    The additional fields are displayed on the list screen, however, they contain no data.
    The fields can be filled in the FORM routine FILL-LISTSTRUCT in the generated program ZPnnnn00. The FORM routine is called for each data record in the list.
    Structure ZPLIS is identified when it is generated with a TABLES statement in the program ZPnnnn00.
    The fields can be filled from the Pnnnn structure or by reading text tables.

  • Dynamic SQL in Formula Column in OracleReports6i

    Following code is in formula column of my report. passing dynamic sql str1(actullay, this string comes from after parameter trigger form) into SQL and executing thru DBMS_SQL.PARSE function. it's failed with 'Fatal PL/SQL error occured' ...
    Coupld any one help me on this...
    function CF_1FORMULA0006 return Number is
    Credits1 NUMBER(10,2);
    str1 VARCHAR2(50) := 'AND b.PROGRAMID = 2 ';
    c1 INTEGER := dbms_sql.open_cursor;
    c2 INTEGER;
    begin
    begin
    dbms_sql.parse(c1,
    'SELECT NVL(SUM(a.AMOUNT),0) INTO Credits1' &#0124; &#0124;
    'FROM SPONSOR_TRAN_DATA a, SPONSOR b ' &#0124; &#0124;
    ' WHERE ' &#0124; &#0124;
    ' a.TRANTYPE = 41 ' &#0124; &#0124;
    ' AND a.SPONSORID = b.SPONSORID ' &#0124; &#0124;
    str1 &#0124; &#0124;
    'AND a.amount > 0 ' &#0124; &#0124;
    'AND a.timestamp >= :reportdate ' &#0124; &#0124;
    'AND a.timestamp < :reportdate + 1' ,2);
    c2 := dbms_sql.execute(c1);
    exception
    when no_data_found then
    Credits1 := 0;
    end;
    return Credits1;
    end;
    Thanks in advance......

    It looks like forms are not supporting text functions like FR yet, I gave it a try <<MemberName("<Formname>","<POV DIM Name>)>> in the formula header area and it didn't like it. It is just displaying what ever I typed in there.

  • Formula Column with Prompt

    Hi,
    I have a doubt in Column formula. I have a grid with a prompt selection so that users can select a list of members which will be displayed as the columns. The grid also have a total column(formula column) at the end.
    For example, If the user selects three members then the grid will show the selected members and the total column. The total column should be sum of three members similarly when I select 5 members the total should be the sum of 5 members.
    Is there a way to achieve this when the number of columns will be dynamic based on the user's selection?
    Thanks in advance.

    Just choose the sum of particular column e.g. if in Column A you are selecting RTP as 5 members then at the run time it would be 5 columns , but for the summation purpose it is a single column so choose SUM([A]).
    If I am not wrong it will solve your problem as I have used it long time back.
    Please let me know if doesnt solve your problem.
    Thanks
    YSP

  • Ability to query on all columns from a view with multiple tables

    I have view with 4 tables. view has about 50 columns.
    hypothetically, I want to build a form to give the user an ability to query on any of those 50 columns. user can search on one or more fields.
    what is the best way to write the query to retrieve the results without performance impact.
    please let me know if the question is not clear.

    If you want to permit them to query any of 10 fields with no restrictions, you could create 10 separate single-column indexes. The optimizer would have to try to pick the best of these indexes if you specified multiple search criteria. But since you have a view which presumably means that you've got multiple other indexes involved for the underlying join conditions, you'd probably want/need to combine the column lists of the indexes you're adding for searches with the indexes you've created for joins, which requires looking at the text of the view and figuring out the best way to optimize the 10 single-column searches. Of course, it is possible that the optimizer could chose to do something like a b-tree to bitmap conversion on multiple indexes which could allow it to use multiple independent indexes for your queries, but that's generally not ideal performance-wise.
    All this is a fancy way of saying that there probably isn't a cut and dried answer to your question. You need to figure out the queries you're trying to optimize (say, the 10 single-condition queries) and you need to figure out what set of indexes on the various underlying tables provides the best performance weighing those benefits against the cost on other side of maintenance during DML. Which is going to depend on the text of the view, the underlying tables, the existing indexes, etc.
    Justin

Maybe you are looking for

  • Adobe Media Encoder .mp4 not playing on iOS

    trying to get my video to work on iOS. i know it has to be .mp4 and i have various videos i have successfully encoded but some do not work when I  render them as .mp4 I have been taking the .mov files (they were rendered to QT using Animation) using

  • File not going away

    Hello, I have an issue with a file that is sitting on my desktop and I can't delete, neither pop an info window, I right clicked on it and try to show the package content and is all blank, can't rename it... well, I have no clue what to do with this

  • Thumbnail views in Vista Explorer STILL MISSING!

    This is the most aggrevating topic. I've never experienced such an seemingly unsolveable computer problem. I have CS4 (Acrobat 9 Pro), Vista 64 bit PC. I have been trying to get a solution for months as to how to get the preview thumbnail to appear i

  • Telepresence Sx80 Second call became as Audio Calls Only

    Dear all, We have two Telepresnce SX80 (Ext:5001 and 5002) on Different location and Video call working proble but when i try to call One of them from my Cisco Jabber on smart phone the call showing on Panel ( answer call as Audio Only). is there any

  • N97 sync with new OVI suite

    I had my N97 mini and my laptop syncing fine. I have installed the latest OVI suite and now I cannot get the phone into PC suite mode. The OVI suite seems to think it is connected OK but when I click the icon I get a message to change the phone to PC