Dynamically write data to a column named in a table

I'd like to write a query that will look up a code, aggregate some data based on the results of that lookup, and store the result in a column named in the lookup table. This isn't real clear; I need an example.
pseudo code:
lookup_table(target_column, lookup_code)
values('target_col_1', 'A')
values('target_col_2', 'B')
select target_column as target ,
lookup_code as code
from lookup_table
for each row {
update results_table r
set target =(
select sum(somecol),
pk_id
from source_table src
where code_col = code
where r.pk_id = src.pk_id
Does this make any sense?

End-User wrote:
I'd like to write a query that will look up a code, aggregate some data based on the results of that lookup, and store the result in a column named in the lookup table.Storing code or parts of code in database tables is a really bad idea.
{message:id=10590811}
You will need to construct the SQL dynamically, which is difficult, error prone and resource intensive if it runs.
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/dynamic.htm#LNPLS011

Similar Messages

  • To find Common data in 2 columns in two different tables.

    Hi,
    Could someone help me out with a querry to find out common data from 2 columns in two different tables??
    Thanks
    Rajesh

    966915 wrote:
    suppose i hav 2 tables
    Table A
    s.No name EID
    1 aaa 123
    2 bbb 234 ... etc..
    and Table B
    S.no salary eid location
    1 mmm$ 123 india
    2 ddd$ 556 Uk
    3 fff$ 236 US
    How do i select the common entry in both the tables??why do you post in forum for SQL & PL/SQL; yet never post anything in either language?
    what do you mean by "common enrty"?
    does every column value must match exactly across 2 rows in different table?

  • Inserting data into a column from 2 different tables

    Hi,
    I need to insert data into a table using 2 other tables. The tables that contain data have identical column names.
    Is using a UNION statement the only option?
    Also, if I need to insert data into columns from only one of the either tables, how do i do it?
    Thanks.

    For future reference, "doesn't seem to work" is a rather generic description... Posting the particular error message will be quite helpful, though I'm reasonably confident that I know the particular problem here.
    First, if only for sanity, you probably want to explicitly list the columns of the destination table in your INSERT statement.
    Second, it doesn't make sense to have DISTINCT clauses in queries that are UNION-ed together. A UNION has to do a sort to remove duplicates already.
    Third, the two queries you are UNIONing together have to return the same number of columns, with the same names, in the same order.
    You probably want something like
    INSERT INTO new_table( col1, col2, col3, col4, col5 )
      SELECT 'ABC'  col1,
             a.colA col2,
             a.colB col3,
             a.colC col4
             a.colD col5
        FROM table1 a
      UNION
      SELECT 'ABC'  col1,
             b.colA col2,
             b.colB col3,
             b.colC col4
             NULL   col5
        FROM table2 bJustin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Retrieve data from 2 columns of 2 different tables and display in 1 column

    Hi,
    Is it possible to retrieve data from 2 different columns of 2 different tables and display it in the same column of a datablock in a form.
    For example:
    Table A
    Col1
    1
    2
    3
    Table B
    Col1
    2
    4
    5
    The column from the datablock in the form should display the following:
    1
    2
    3
    2
    4
    5

    You can create a view
    select ... from table_a
    union
    select ... from table_b
    and base the block on that.
    However, if you want to allow DML on the block it gets more complicated.

  • Column naming standard..table naming  standard..

    Currently I am working in one of my clients place..and here i see column names more than 35 characters..
    According to me column name should not be more than 15 characters...
    Is there a limit ??
    Is there any table naming column naming standard..

    I found couple of link for Oracle Naming convensions:
    http://www.oracle-base.com/articles/misc/NamingConventions.php
    http://www.dba-oracle.com/standards_schema_object_names.htm
    http://www.gplivna.eu/papers/naming_conventions.htm
    http://ss64.com/ora/syntax-naming.html
    Hth
    Girish Sharma

  • How do you write an output in columns to an html table?

    Ive written two programs. My first program compares the difference of two text files and prints the differences in an output. My second program creates a simple Html table. I would like to write my output to this table. How would I go about doing this in java?
    Thanks in advance for your help.

    Thanks guys for the insight. Im very new to java so I'm a complete novice when it comes to writing code. What I came to realize was I needed to do was build a dynamic table. My issue was that I was building a static table and I couldint populate the table with my results. Below is an example of the code I wrote for my table. My apologies if didnt format my code correctly.
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Set;
    public class HtmlDataTable {
      public void writehtmltable(Set<String> filenameSet){
      //creates table in the following path
      File htmltable = new File("C:/Output.html");
      try {
      BufferedWriter bw = new BufferedWriter(new FileWriter(htmltable));
      //write html data table
      bw.write(htmltop);
      for (String jarfilename:filenameSet){
      String line="<tr>  <td> </td>      <td> </td> </td>      <td>"+jarfilename + " </tr>";
      bw.write(line);
      bw.write(htmlbottom);
      //close the resource
      bw.close();
      } catch (IOException e) {
      e.printStackTrace();
    private static String htmltop = "<!DOCTYPE html>\n"+
                                      "<html>\n"+
                                         "<head>"+
                                         "<title>Jar Filename Existance Check</title>"+
                                         "<style>"+
                                         "table, th, td {"+
                                         "    border: 2px solid black;"+
                                         "}"+
                                         "</style>"+
                                         "</head>"+
                                         "<body>"+
                                         "<table>\n"+
                                         "   <tr>     <th colspan='100'>" +
                                         "<h3><br>Jarfilename Existance Check</h3>      </th>   </tr>" +
                                         "<th>POM File Data</th> <th>Lib Directory Files</th> <th>Missing Jarfiles</th>";
      private static String htmlbottom = "</table></body></html>";
    public static void main(String[] args) {
      new HtmlDataTable().writehtmltable(null);

  • Writing data to a column

    I cant figure this out. I havent used labview in a little while and now I have to use these things you people call "arrays" and I'm confused.
    Anyway, I want to dynamically write data to a column and/or a row depending on where in the program I am.
    I'm having an issue writing to a column, please help me. What am i doing wrong
    Attachments:
    labview3.JPG ‏22 KB

    The term "array" is a pretty common term in computer programming, so if you aren't familiar with it, then you probably will have lots of problems.  I suggest you start with some online LabVIEW tutorials
    LabVIEW Introduction Course - Three Hours
    LabVIEW Introduction Course - Six Hours
    You are using Insert into Array.  It looks like you are inserting into column 2.  Are you sure you don't want "Replace Array Subset"?
    It is hard to debug a screenshot.  A copy of your VI would be better.  Is your 2-d string array going into the initializer terminal of the feedback node an empty array?  You can't insert new data into an array in an area past the end of an array.  (i.e.  if column 0 is blank, you can't insert data into column 2, what would column 1 get?)

  • How to show current date in a column of dimension table in ssas

    Hi,
    I have 2 dimension tables (ALLWORK and YOURWORK) and 1 measure table (STATS). In ALLWORK dim table, I have 4 columns, one of them is END_DATE. Based on END_DATE and current date I want to create a named calculation field. To achieve this, I
    want to show the current date in 5th column (of ALLWORK dim table) as calculated member (as named calculation wont show me correct date).
    Problem is, I am not able to create the column in the dimension table. While creating the calculated member, I am not able to select the ALLWORK dimension table, it always selects MEASURE by default. Please help.
    thanks
    Tarique
    thanks and regards Tarique Aslam

    Hi Tarique,
    According to your description, you want to add a column to your dimension to show the current date, right?
    In data source view, we can add named calculation to your table. A named calculation is a SQL expression represented as a calculated column. This expression appears and behaves as a column in the table. A named calculation lets you extend the relational
    schema of existing tables or views in a data source view without modifying the tables or views in the underlying data source.
    Reference
    http://msdn.microsoft.com/en-in/library/ms174859.aspx
    http://devmau5.wordpress.com/2010/03/25/the-getdate-of-mdx/
    If I have anything misunderstand, please point it out.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Creating a dynamic lov based on a column

    Hi,
    I want to create a dynamic lov based on a column in a database-table.
    Eg. the query
    'select code, description from code_table'
    is the contents of the column 'lov_query' in the table 'parameters'.
    For every parameter there can be a different lov-query, but the result is always
    two columns (code and description, number and name, etc.), exactly what you need to use in a lov.
    I've written a (dbms_sql) function that takes the parameter-id and returns the lov_query.
    create or replace function "GET_PMR_LOV"
    (pmr_id in NUMBER)
    return VARCHAR2
    is
    cur INTEGER := DBMS_SQL.OPEN_CURSOR;
    fdbk INTEGER;
    l_pmr_id NUMBER(9) := pmr_id;
    l_stmnt VARCHAR2(2000);
    begin
    DBMS_SQL.PARSE
    (cur, 'select pmr.lov_query from parameters pmr where pmr.ID ' || ' = 'L_PMR_ID', DBMS_SQL.NATIVE);
    DBMS_SQL.BIND_VARIABLE (cur, 'L_PMR_ID', l_pmr_id);
    DBMS_SQL.DEFINE_COLUMN (cur, 1, l_stmnt, 2000);
    fdbk := DBMS_SQL.EXECUTE (cur);
    fdbk := DBMS_SQL.FETCH_ROWS (cur);
    IF fdbk > 0
    THEN
    DBMS_SQL.COLUMN_VALUE (cur, 1, l_stmnt);
    return (l_stmnt);
    ELSE     
    return null;
    END IF;
    DBMS_SQL.CLOSE_CURSOR (cur);
    END;
    But now I'm stuck on how to pass on this statement in HTMLDB
    as an dynamic lov, I don't seem to be able to execute this statement
    into the two display and return columns. Any ideas?

    Hello again,
    This lov is on an updatable report-column where the user has to make a choice from an non-named, popup and query-based lov. In the lov-query box I have just put:
    "return get_pmr_lov(:p41_param_id)" (without the quotes ;-)
    Here's my latest version plus an alternative, which both seem to work fine:
    create or replace function "GET_PMR_LOV"
    (pmr_id in NUMBER)
    return VARCHAR2
    is
    cur INTEGER := DBMS_SQL.OPEN_CURSOR;
    fdbk INTEGER;
    l_pmr_id NUMBER(9) := pmr_id;
    l_stmnt VARCHAR2(1000);
    begin
    DBMS_SQL.PARSE (cur, 'select pmr.lov_query from paramaters pmr where pmr.ID ' || '= :L_PMR_ID', DBMS_SQL.NATIVE);
    DBMS_SQL.BIND_VARIABLE (cur, 'L_PMR_ID', l_pmr_id);
    DBMS_SQL.DEFINE_COLUMN (cur, 1, l_stmnt, 1000);
    fdbk := DBMS_SQL.EXECUTE (cur);
    fdbk := DBMS_SQL.FETCH_ROWS (cur);
    IF fdbk > 0 THEN
    DBMS_SQL.COLUMN_VALUE (cur, 1, l_stmnt);
    return (l_stmnt);
    ELSE
    return null;
    END IF;
    DBMS_SQL.CLOSE_CURSOR (cur);
    END;
    create or replace function "GET_PMR_LOV2"
    (pmr_id in NUMBER)
    return VARCHAR2
    is
    l_pmr_id NUMBER(9) := pmr_id;
    l_stmnt VARCHAR2(1000);
    BEGIN
    EXECUTE IMMEDIATE 'select pmr.lov_query from parameters pmr where pmr.ID = :1'
    INTO l_stmnt USING l_pmr_id;
    return l_stmnt;
    END;
    The error-message remains the same, unable to bind :p41_param_id !

  • How much space a Date , time , TimeStamp column occupy?

    Hi
    what is size of a Date , Time and TimeStamp type ?
    i mean how much bytes they require ?
    Thanks

    Apologies if this posts more than once. I got server errors.
    Laurent:
    Sysdate and systimestamp are actually different types than a date or timestamp column.
    SQL> CREATE TABLE dt (dt DATE, ts TIMESTAMP);
    Table created.
    SQL> INSERT INTO dt VALUES(sysdate, systimestamp);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    DUMP(DT)
    Typ=12 Len=7: 120,106,6,2,17,43,10
    SQL> SELECT DUMP(ts) FROM dt;
    DUMP(TS)
    Typ=180 Len=11: 120,106,6,2,17,43,10,28,185,249,48
    SQL> SELECT DUMP(sysdate) from dual;
    DUMP(SYSDATE)
    Typ=13 Len=8: 7,214,6,2,16,50,17,0
    SQL> SELECT DUMP(systimestamp) from dual;
    DUMP(SYSTIMESTAMP)
    Typ=188 Len=20: 7,214,6,2,20,50,30,0,48,111,78,168,252,0,5,0,0,0,0,0I seem to recall reading somewhere that sysdate is actually a representation of the C struct_t time structure, while a date column is Oracle's internal format. It looks like something similar is going on with systimestamp, and with the date and timestamp casts you are doing.
    The inserts into the table above were done minutes before the selects, but definitely within the same hour. The byte values have no correlation, between the date field and sysdate, nor between the timestamp field and systimestamp, while the the date and timestamp fields are identical to the second. Similarly, the sysdate and systimestamp dumps are identical to the second.
    The vsize function reports the physical storage required for the expression passed. My guess would be that it is implicitly casting sysdate and systimestamp to the equivalent internal representation before calculating the size.
    John

  • Cannot enter data into table with column named DATE

    I have a table as follows:
    CREATE TABLE PACKINGLINE (
    SNO VARCHAR2(13),
    "DATE" DATE DEFAULT SYSDATE,
    PRDORDNO VARCHAR2(12),
    NOW DATE DEFAULT SYSDATE,
    CONSTRAINT PACKINGLINE_PK PRIMARY KEY ("SNO", "DATE"));
    Note the "cleaverly" named DATE and NOW columns (yes, that is the name of the column... our company was bessed with a very clear SQL server DBA in the past)
    This SQL statement works:
    INSERT INTO PACKINGLINE (SNO, PRDORDNO) VALUES ('1000808972', '100080897');
    However when I try use SQL Developer as follows I cannot enter data:
    1. Open SQL Developer
    2. Click on "Tables" then on my table named PACKINGLINE
    3. Click the "Data" tab
    4. Click the [+] "Insert Row" Icon
    5. Enter the same data as above
    6. Click Commit
    7. The following error is shown in the log window and I cannot commit the data change.
    Error message
    ==================
    INSERT INTO "DBO"."PACKINGLINE" (SNO, PRDORDNO) VALUES ('1000808971', '100080897')
    One error saving changes to table "DBO"."PACKINGLINE":
    Row 5: ORA-06550: Row 1、Column 25:
    PL/SQL: ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: Row 1、Column 7:
    PL/SQL: SQL Statement ignored
    ==================
    I can copy and paste the above query into a normal SQL statement window and the data commits fine.

    Its so flaky there really must be something wrong Mr Adobe support person....
    If I load a PDF, do nothing, gently save it, reopen and then waiting for my trial dialogue to wake up so that I can click on continue trial... then save as extended reader blah.... then close. I have finally saved one that works!!!! but how difficult is that????
    WHAT IS WRONG ADOBE??

  • IP: Dynamic Data and Lead Columns

    Hello,
    In IP, there is not such thing as "Dynamic Data and Lead Columns" which we have used successfully in BPS. We have quite normal case where accounts are on rows and columns are defined as follows:
    Column 1): KF Qty1, Period #, Year "Var Current year (single value)"
    Columns 2-n): KF Amt1, Period "Var periods current year (multiple values)", Year "Var Current year"
    Column n+1): Sum columns 2-n
    Number of periods in variable "Var periods current year" is not fixed and maintained by superuser, so number of columns is somewhere between 3 and 14 (at least one open period, maximum 12, plus the Qty1 and Sum columns).
    How would you fix this in IP?
    Thanks for answers!
    Aki

    Hello Aki,
    you could put the period into the columns as char.
    if you make a selection to value # and the variable you will se as many columns as periods are selected in the variable plus the one column for #.
    regards
    Cornelia

  • How to read and write data in to a specified range of cells(it include multiple row & columns) in excel

    How to read and write data in to a specified range of cells(it include multiple row & columns) in excel

    CVI Comes with a sample project that explains how to read/write to a Excel file: choose "Explore examples..." in CVI welcome page and navigate to <cviSampleDir>\activex\excel folder where you can load excel2000dem.prj.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Question on Dynamic Query Data Source and Form Folders in Oracle Forms 6i

    Hi there -
    I have one interesting requirement in Oracle Forms.
    This is what I wanted to do.
    1. Have a LOV and Go button on Form.
    2. From LOV, I will select a pre-defined custom table and click Go.
    3. Based on the selected custom table, I have to populate the Block (Tabular Format).
    4. User should be able to do update, delete, insert on this block.
    5. User should be able to use the Oracle Form folders functionality (select only necessary column and save views etc. Std folder functionality).
    6. If user selects a different custom table name in the LOV on top, I need to refresh the data from the block based on this new table. Remaining functionality should be as it is (steps 3 to 5).
    You can see here, I am going to have dynamic query data source (Table Name as well as column mapping) on the block. I do not know before hand how many columns the user selected table has!
    This is what I have planned for this so far but I have some major questions before I can move on with this design:
    1. I am going to create a table structure with fixed number of column in form (40 cols assuming that the custom table will not have more that 40 cols). (Kind of limitation but it's okay as of now).
    2. Dynamically populate the block based on the table name selected by the user from LOV. Dynamically change the table column names based on the table selected etc.
    3. Perform insert, update, delete using PL/SQL package.
    So far it looks okay.
    Now my real question is,
    Can user still be able to user "Folders" functionality here? I have never done this kind of development before and I doubt the dynamic column naming, dynamic column data source will really work for "folders"!
    Also, I am not really sure whether user will be able to save these "folder" queries?
    Okay so form experts, can you ppl suggest me if this is really going to work? Are there any better ways to do this?
    Initially I tried to do this in OA Framework but I got stuck at because as per OAF developer guide "I cannot user OAF personalization for dynamic items, regions etc".
    For more info on that thread see this link...
    Re: setUserCustomizable issue!
    Thanks in advance for the help.

    Any suggestion anyone?

  • Dynamically read data from a txt document

    I try to dynamically read data from a txt document
    in swf
    stop ();
    var pafh=this;
    import flash.events.*;
    var Araray_id:Array =new Array();
    var v_length:Number;
    var myTextLoader:URLLoader = new URLLoader();
    myTextLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
    myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
    function onLoaded(e:Event):void {
            Araray_id = e.target.data.araray_id.split(",");
            trace("Araray_id: "+Araray_id);
            v_length=Araray_id.length;
            trace("v_length: "+v_length);
            for (var i:Number=0;i<v_length;i++){
                pafh["Id_"+i]=new Array();
                trace("pafh[Id_+i]: "+pafh["Id_"+i]);
                var v_help:Object="id_"+i;
                trace("v_help: "+v_help);
                //pafh["Id_"+i]= e.target.data.v_help.split(",");????? Here stops the script
                //pafh["Id_"+i]= e.target.data.(v_help).split(",");????Here stops the script
                //pafh["Id_"+i]= e.target.data.[v_help].split(","); ????Here stops the script
            play();
    myTextLoader.load(new URLRequest("myText1.txt"));
    in text
    araray_id=aa,bb,cc,dd,ee,ff
    &id_0=aa1,aa2,aa3,aa4
    &id_1=bb1,bb2,bb3,bb4,bb5
    &id_2=cc1,cc2,cc3
    &id_3=dd1,dd2,dd3,dd4,dd5,dd6
    &id_4=ee1,ee2
    &id_5=ff1,ff2
    output
    Araray_id: aa,bb,cc,dd,ee,ff
    v_length: 6
    pafh[Id_+i]:
    v_help: id_0
    TypeError: Error #1010: A term is undefined and has no properties.
        at skuskaceatarraybiforas3fromtext_fla::MainTimeline/onLoaded()
        at flash.events::EventDispatcher/dispatchEventFunction()
        at flash.events::EventDispatcher/dispatchEvent()
        at flash.net::URLLoader/onComplete()
    Can you help me with this problem

    More suggestions.
    1. If you align naming conventions between data and your application - reading data could be practically a one-liner.
    If you write pafh["id_" + i] (with small case i) instead of pafh["Id_" + i] (with capital case I) the function can be just:
    function onLoaded(e:Event):void
              for (var prop:String in e.target.data)
                        pafh[prop] = e.target.data[prop].split(",");
              play();
    2. If changing conventions is not feasible, here is another thing you can do:
    function onLoaded(e:Event):void
              for (var prop:String in e.target.data)
                        pafh[prop.replace(/^\w/, String(prop.match(/^\w/)).toUpperCase())] = e.target.data[prop].split(",");
              play();

Maybe you are looking for

  • What does this error2 mean and how do I fix it?

    What does this error mean and how do I fix it?  I am trying to reinstall CS4 on my Windows 8.1 machine.  Adobe Flash Player 10 ActiveX Error: Error 2. Here is the initial error: http://s29.postimg.org/wqy2ju8iv/Untitled.png Here is a screenshot when

  • Photoshop 7 - Compatible with Windows 7?

    I just ordered a new computer (which will have the Windows 7 OS on it) and was wondering if anyone knows if PS 7 would work okay on it? I can't really afford to get any new software right now, and am hoping this works.

  • Error with small sap script program

    REPORT  ZFORM1                                  . TABLES : ZGTABLE. types:begin of warea,       trackid type zgtable-trackid,       artist type zgtable-artist,       end of warea. data:itable like zgtable occurs 0 with header line. CALL FUNCTION 'OPE

  • What is the best app for storing all passwords in a secure area? osx snow leopard

    What is the best app for storing all passwords in a secure area? osx snow leopard

  • Lightroom 5.6 zeigt unter Yosemite die Bilder der Bibliothek nicht an

    Hallo, seit Yosemite ist Lightroom 5.6 recht langsam. Ausserdem werden die Thumbnails nicht angezeigt. Erst, wenn ich ein Foto entwickeln möchte, wird es angezeigt. Das hilft mir beim kategorisieren nicht. Gibt es hier Abhilfe? Grüße Michael