Transfer values of ROWTYPE in ROWTYPE with different COLUMN specifications. keeping the Default_Data values

Hello

I have a problem on dynamically the transfer values of different columns in two variables given rowtype type.

My intention is to transfer values from table1 into table2.

Basically, I stated to vars of v_table1 and v_table2% rowtype, each of them contains columns with the same, and also the individual column names.

v_table2% rowtype must be initialized with default values.

I would like to insert v_table2 values in table2 later by practice 'INSERT INTO TABLE2 VALUES v_table2'.

Before inserting, I need to change several values of column by different rules, but these rules are not relevant for my actual demand.

The point is, how can I transfer the values of v_table1 in v_table2 for the hanving of columns with the same column name, without hard-coding the names of columns, because these two tables contain many columns.

In addition values initialized with v_table2 default_data values should not be overwritten by data does not exist in the same named column of v_table1.

Example: If v_table1. D is NULL, it should not replace the default value initialized former "Monday".

Conditions:

Table 1 contains the following values:

Column name Value
A'1'
B'2'
CNULL VALUE
D'somedata '.
ENULL VALUE
F« 3 »

After the transfer of the values of v_table1 in v_table2, I guess that the following data:

Column name Value Source
CNULL VALUETable1.C
D'somedata '.Table1.D
E"Tuesday".DATA_DEFAULT from Table2
F« 3 »Table1.F
GNULL VALUE
HNULL VALUE

Right now I am already able to fill the v_table2 with the default values:

declare
  lv_query varchar2(1000);
  
  type cur_typ is ref cursor;
  rcur_typ cur_typ;
  
  v_table2 table2%rowtype;

begin
    for rec in (select *
                from user_tab_columns
                where table_name = 'TABLE2'
                order by column_id
                )
    loop
      if rec.data_default is null then
          lv_query := lv_query||', null';
        elsif rec.data_type = 'NUMBER' then
          lv_query := lv_query||', '||rec.data_default;
        elsif rec.data_type = 'DATE' then
          lv_query := lv_query||', '||rec.data_default;
        else
          lv_query := lv_query||', '||rec.data_default||'';
      end if;
    end loop;
    
    lv_query := 'SELECT'||substr(lv_query, 2)||' FROM DUAL';
    dbms_output.put_line(lv_query);
    
    open rcur_typ for lv_query;
    fetch rcur_typ into v_table2;
    close rcur_typ;
end;

I have no idea how to achieve the transfer of v_table1 to v_table2 without substitute default values of table2.


As far as I know I can find these columns with column names by querying:

select column_name from user_tab_cols where table_name='TABLE1' intersect select column_name from user_tab_cols where table_name='TABLE2'

Maybe you can give me some advice.

Thank you very much.

Sample data:

CREATE TABLE "TABLE1" 
   (    "A" VARCHAR2(20 BYTE), 
    "B" VARCHAR2(20 BYTE), 
    "C" VARCHAR2(20 BYTE), 
    "D" VARCHAR2(20 BYTE), 
    "E" VARCHAR2(20 BYTE), 
    "F" VARCHAR2(20 BYTE)
   );

  CREATE TABLE "TABLE2" 
   (    "C" VARCHAR2(20 BYTE), 
    "D" VARCHAR2(20 BYTE) DEFAULT 'Monday', 
    "E" VARCHAR2(20 BYTE) DEFAULT 'Tuesday', 
    "F" VARCHAR2(20 BYTE) DEFAULT 'Wednesday', 
    "G" VARCHAR2(20 BYTE) DEFAULT 'Thursday', 
    "H" VARCHAR2(20 BYTE)
   );

INSERT INTO "TABLE1" (A, B, D, F) VALUES ('1', '2', 'somedata', '3');

INSERT INTO "TABLE1" (A, B, D, F) VALUES ('1', '2', 'somedata', '3');

Banner:

Oracle Database 11 g Release 11.2.0.3.0 - 64 bit Production

PL/SQL Release 11.2.0.3.0 - Production

CORE Production 11.2.0.3.0

AMT for Linux: Version 11.2.0.3.0 - Production

NLSRTL Version 11.2.0.3.0 - Production

You can build a dynamic query that checks the values of all columns in the table 1,

and if a column contains null, then retrieves the default value of the column in table2,

or null if this column doesn't have a default vallue.

Something like this pseudocode

SELECT
   if column A is not null then take A from table1, else take default for column A from table2
   .....
   if column X is not null then take A from table1, else take default for column X from table2
FROM table1

The default budget can be extracted from USER_TAB_COLUMNS

select column_name, data_default from user_tab_columns
where table_name = 'TABLE2'
order by column_id
;

Tags: Database

Similar Questions

  • How to import photos from a different catalog and keep the setting in this catalogue?

    How can I import photos from a different catalog and keep the setting in this catalogue?

    In a catalog, select the photos you want, then use file-> export as catalog

    In the 2nd catalog, use the file-> import from another catalog

  • How to read the data with different XML schemas within the unique connection?

    • I have Oracle database 11g
    • I access it via JDBC: Slim, version 11.2.0.3, same as xdb.
    • I have several tables, each has an XMLType column, all based on patterns.
    • There are three XML schemas different registered in the DB
    • Maybe I need to read the XML data in multiple tables.
    • If all the XMLTypes have the same XML schema, there is no problem,
    • If patterns are different, the second reading will throw BindXMLException.
    • If I reset the connection between the readings of the XMLType column with different schemas, it works.

    The question is: How can I configure the driver, or the connection to be able to read the data with different XML schemas without resetting the connection (which is expensive).

    Code to get data from XMLType is the implementation of case study:

     1   ResultSet resultSet = statement.executeQuery( sql ) ; 
    2   String result = null ;
    3    while(resultSet.next()) {
    4   SQLXML sqlxml = resultSet.getSQLXML(1) ;
    5   result = sqlxml.getString() ;
    6   sqlxml.free();
    7   }
    8   resultSet.close();
    9    return result ;

    It turns out, that I needed to serialize the XML on the server and read it as BLOB. Like this:

     1    final Statement statement = connection.createStatement() ;  2    final String sql = String.format("select xmlserialize(content xml_content_column as blob encoding 'UTF-8') from %s where key='%s'", table, key ) ;  3   ResultSet resultSet = statement.executeQuery( sql ) ;  4   String result = null ;  5    while(resultSet.next()) {  6   Blob blob = resultSet.getBlob( 1 );  7   InputStream inputStream = blob.getBinaryStream();  8   result = new Scanner( inputStream ).useDelimiter( "\\A" ).next();  9   inputStream.close(); 10   blob.free(); 11   } 12   resultSet.close(); 13   statement.close(); 14  15   System.out.println( result ); 16    return result ; 17
    

    Then it works. Still, can't get it work with XMLType in resultset. On the customer XML unwrapping explodes trying to pass to another XML schema. JDBC/XDB problem?

  • How to make a NULL handle with different columns

    Hi gurus,

    I need the Oracle in the reports:

    For example:-J' have a Temp table with three columns A, B and C

    My requirement is IF the columns A, B and C are null in the report he should return C 0, B as none and none.
    If all values are there in columns A, B or C, then report output should return these values.

    All your contributions are much appreciated.

    Thank you

    When column c is null, column should return zero and column b return zero and column c 0.
    If column C is not null, then it must return the values that are present in their respective columns.

    select nvl2 (c, a, 'None') a, nvl2 (c, b, 'None') b, nvl (c, 0) c from temp
    
  • How to create a table with a column that is the value in another table?

    Hi all,

    It's my first post n I changed my ODI of DATASTAGE platform. Help me friends n I know basic steps in 11 ODI version which I was training in my company. I hope to have your support and can do everything an action ODI related documents.

    My question is...

    Table T1 > > > > > > > > > >

    service id / / / attr.name / / / attr.value

    S1 / / / product_code / / / P1

    S1 / / / provider / / / pro1

    S2 / / / product_code / / / P2

    S3 / / / provider / / / pro3

    Table T2 > > > > > > > > > > > > > > >

    ID / / / product_code / / / provider

    S1 / / / p1 / / / pro1

    S2 / / / p2 / / / nullvalue

    S3 / / / nullvalue / / / pro3


    I have a table T1 since I should show the table T2 is released. Can we say everything on how to write a logic and steps to follow.

    Thanks in advance.

    Published by: 854662 on April 26, 2011 01:59

    Hello

    U go.

    1 the interface:

    "Put a filter in your 1 on attr.name = array ' PRODUCT_CODE.

    In the map target TABLE2
    SERVICE_ID = TABLE1. SERVICE_ID
    PRODUCT_CODE = TABLE1. ATTR_VALUE

    Use SQL IKM append control

    Interface 2:

    "Put a filter in your 1 on attr.name = array ' PROVIDER '.

    In the map target TABLE2
    SERVICE_ID = TABLE1. SERVICE_ID
    PROVIDER = TABLE1. ATTR_VALUE

    Do SERVICE_ID as KEY (when you click the column target in properties, you can see KEY under properties of the target column) and use the incremental update of the IKM Oracle.

    PS: I assume that Oracle as the source and target.

    And you can refer to the documentation,

    https://Apex.Oracle.com/pls/Apex/f?p=44785:24:4413167952886630:no:24:P24_CONTENT_ID, P24_PREV_PAGE:5185, 29

    http://odiexperts.com/

    And of course this OTN.

    Thank you
    Guru

  • Thunderbird allows synced on mutiple computers in different places? keeping the inboxes of folders, address books, even at home and work

    I want to use Tbird on several machines and locations. and keep the address books and folders synchronized

    Yes, with some work on your part.

    E-mail is synchronized automatically if you use IMAP on all machines.

    Address book synchronization can be achieved by synchronizing to a "service of address book based on the net. I use Google Contacts and the add-on gContactSync in Thunderbird.

    You have not asked about the calendar, but you can also synchronize the lightning calendar in Thunderbird for a service like Google Calendar.

    I am able to share email address books and my calendar between Thunderbird (under LInux and Windows 7) and also on Android based tablets and phones.

    If you want to do the hard, you can synchronize Thunderbird on multiple computers by porting its profile among them.

    You also might consider Portable Thunderbird running from a USB key and just get your email on your.

  • I need an html link tag in answers + concatenate with another column, so that the link may open the site with the countries

    Please share me your ideas for this problem

    in the responses, I need to add a link to HTML and parallel to concatenate it with another column

    example of think this link as https:\\google.com + another column (column for the google link concatenation)

    https:\\google.com + column country so that it can turn directly to page-> https:\\google.com\India

    so that helps me to access a particular site of my organization and opening of a given page

    Hi 3051369,

    Glad it worked.

    Could you please mark this question as answered?

    Thank you

    JeromeFr

  • How to transfer photos and documents between iPads with different apple ID

    I know I can't transfer apps, music... etc.  I don't want to transfer photos, audio and files Pages.  How to do this easily?  Thank you!

    You could try dropbox.com. It will be everything automatically synchronize you photos with the cloud dropbox.com store.  You can disable auto-sharing.  There is an option in the settings of dropbox in the app. You would then share your account with others.  You will need to see if you can share a folder read only with the free version.  You can acquire more control with the professional version.

    You must manually copy the pages in your dropbox app.

    iWork iOS 8 and Dropbox

    In addition, see drive Box.com and google.

  • Edited the photo transfer from one computer to another with different versions of the items.

    My old macbook pro has 12 items, my new macbook pro has 14 items.  The old laptop doesn't have the appropriate osx version to run 14.  I will be able to transfer photos has changed since the new computer (w / 14) to the old computer (w / 12)?

    I suggest put the .psd for your slide show files in a single folder on your DHM and connect via USB or love at first sight.

  • Build & write to text with different column formatting

    3 days, I just pass on what appears to be a simple problem:

    I have a VI that reads a significant length TDMS file containing data sampled at 1 MHz 2-channel (very large files of course). The VI only runs 1 second at a time and looking for threshold crossing points and calculates the energy at this time there. In any case, I'm writing a text file where a column contains the number of the sample and the second column contains energy, annexed whenever the VI iterates (the number of rows generated by iteration may vary). It's simple by using the function 'Write to Spreasheet', the problem is I want a different format on each column. The sample number must be set to zero decimal and energy must be set on, say, 3 significant digits.

    A typical few lines should look like (delimited by tab characters, commas are there to represent the tabs):

    Time (samples), energy

    267935, 0.0000346

    545227, 0.000298

    1298655, 0.0000000122

    1314522, 0.00854

    'Write to Spreasheet' allows only a single format, so I have either a large number of DPs on my number of sample or energy value is 0.

    If I use 'Table in chain worksheet', I can set the formatting, but I can't seem to be concatenated, to build or to transpose the outputs in the right direction, no matter what I try.

    In the attached image I use Ch1 as my experience; CH2 using the traditional but unsatisfactory method "to write to the spreadsheet. The current VI returns on Ch1:

    Time (samples), energy

    267935

    545227

    0.0000346

    0.000298

    1298655

    1314522

    0.0000000122

    0.00854

    I hope that the image of the relevant part of the VI just go. I can reach the VI if necessary, but it seems unnecessary that I won't be able to share the data files for the tests.

    You can use the 'number of fractional string' primitive to convert data DBL to the chain with the required precesion. Then when you use this string 2D array and write in the file using 'write to the worksheet VI' it should work fine.

    If you still face any question please include the code with the data in a constant and registered in the 2012 version.

  • It is always possible to search with different search engines in the search bar and address bar?

    I used to use the address bar of Firefox to search for things on Google and the search bar to search for things on Wikipedia. The convenience, especially with the shortcuts Ctrl + L and Ctrl + K has been incredible and I don't understand why this feature would disappear so I guess that it simply was hidden without subject: config somewhere. How can I go on revenant Firefox which is previous feature?

    Note: I use the Nightly build of Firefox for 64-bit systems, if this issue must be addressed specifically to this branch of development please directly to where I can do.

    From 23 of Firefox, the address bar uses the search engine selected in your search bar.

    Assign keywords to your search engines, then the prefix of your search in the address bar query, for example

    g gingerbread recipes
    

    Google search for revenues of gingerbread.

    For more information, see the section "Key words" in the following article.

    If you can't stand absolutely avoid typing two extra characters, then you can try the following extension. It has not been considered by a Firefox Add-ons site editor, so use it at your own risk.

  • Several lines in a row with different column name

    Hello
    I have the table "v_Profile_ID" and "v_Trasaction".

    V_profile_ID columns
    1 profile_nbr
    2 idendifaction_number

    V_Trasaction columns (a historical data)
    1 profile_nbr
    2 Transaction_ID
    3.TransactionDate_Time
    4.Transaction_amount


    common profile_nbr in the tables 'v_Profile_ID' and 'v_Trasaction '.

    Are values in the v_profile_ID table

    profile_nbr Identification_nbr

    1001 Au1002
    1001 BD9089
    1001 FC3900


    To view the identification_3 of v_profile_ID, identification_2, identification_1, Profile_nbr
    and TransactionDate_Time Transaction_amount of v_Trasaction

    Profile_nbr identification_1 identification_2 identification_3 TransactionDate_Time Transaction_amount

    1001 Au1002 BD9089 FC3900 1000 2 April 2011


    Please can someone help me

    Thank you
    Petrilla

    Hello

    Try this... !!

    Select profile_nbr,
    max(decode(seq,1,identification_nbr,null)) identification_1,
    max(decode(seq,2,identification_nbr,null)) identification_2,
    max(decode(seq,3,identification_nbrl,null)) identification_3
    
    from (select profile_nbr,identification_nbr,row_number()
        over(partition by profile_nbr
           order by identification_nbr) seq
            from table_name) where seq<=3;
             group by profile_nbr;
    

    Concerning
    KPR

    * If it's OK... then do as correct
    * If it's useful... then make it as useful

    Published by: KPR on April 29, 2011 04:53

  • How to create an application to display the 3 windows of each with different time zones as the window?

    Hi, I need to create a windows application using c# that will create three windows that display areas and the current time, the title of the window?

    PS: I use an event handler to update the current time.

    Hello

    To improve assistance to this subject, you can ask your question in the MSDN Forums.

    http://social.msdn.Microsoft.com/forums/en/category/visualcsharp

  • How to have a menu with a submenu and keep the rollover State when on submenues

    I'm trying to find a way to have my top menu bar to stay on the status of "rolling" when the mouse pointer is on the submenus. My menu has different colors for each part with turning single images for icons. I would like to have my submenu visible and rest in its condition of bearing on the main part of the menu. Is this possible? I tried to watch the forums here, but did not find it.

    Please see this for what I mean: http://demos.go2eventlink.com/Eventlink-temp/temp/

    Hello David, I got it figured out. The Setup program knows a blank publication and I even had a black composition inside for a menu with submenu.  I also checked the options as Position: stacked, see the target on turnover, hide in slowing. Then the key is to have the bounding box of the 'zone' covering the menu and submenu area which will then eject the mouse if still considered in the area of "churn" even if it is out of the menu and above or around the area of submenu. Also the bearing is the same State as the mouse downwards and the condition of the assets.

    Here's what I did. I hope this helps.

    Web site - 1.muse - Google Drive

  • Update a column to keep the old values and by adding a new

    I have to update a column...

    Select * from test;

    TYPE_TEXTE RULE_NBR
    -----------------------------------
    30 AAX, AAR, AAV, AAB, AAK
    40 BBD, WWN, AAF, AAB, AAK

    now, I have to add BBB, WWW where rule_nbr = 30 and CCC, TTT where rule_nbr = 40

    so this stmt update will do...


    UPDATE TEST
    Type_texte SET = "AAX, AAR, AAV, AAB, AAK, BBB, WWW.
    WHERE rule_nbr = '30';


    Update test
    Set the argument type_texte = "BBD, WWN, AAF, AAB, AAK, CCC, TTT.
    where rule_nbr = '40';


    I was wondering is there an another way to update the same

    LPS says:
    UPDATE TEST
    SET Type_texte = concat (type_text, 'BBB, WWW')
    WHERE rule_nbr = '30';

    Update test
    Set the argument type_texte = concat (type_text, 'CCC, TTT')
    where rule_nbr = '40';

    Check your answer ;) should be concat(type_text,',BBB,WWW') or type_texte |', BBB, WWW'
    You missed the point.

    See you soon,.
    Manik.

Maybe you are looking for