Extract data from a different node in SQL

Hi friends,

First of all:
        BANNER
1     Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
2     PL/SQL Release 11.2.0.3.0 - Production
3     CORE     11.2.0.3.0     Production
4     TNS for Linux: Version 11.2.0.3.0 - Production
5     NLSRTL Version 11.2.0.3.0 - Production
I have a small but annoying problem. I have create a Bank application that needs to retrieve data in a file entry, and, according to this information, to execute some stored procedures (create a new customer, create a new account, create a transaction for an account).
For example: the input file contains a few new customers (FirstName, LastName, SocialSecurityNumber, birthday, address and PhoneNo), for each customer account at least 1 create 1 or more operations (the amount of the transaction) for each account.

Let me be more precise. It is a XML in an input file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<doc>
  <PERS_INFO>
    <lastname>John</lastname>
    <firstname>Doe</firstname>
    <social_security_no>1800325171545</social_security_no>
    <birthday>25/03/1980</birthday>
    <address>Principal, 15</address>
    <phoneno>0040722222222</phoneno>
    <acc>
      <transaction>200</transaction>
      <transaction>150</transaction>
      <transaction>-23</transaction>
    </acc>
    <acc>
      <transaction>450</transaction>
    </acc>
    <acc>
      <transaction>800</transaction>
      <transaction>320</transaction>
      <transaction>-125</transaction>
    </acc>
  </PERS_INFO>
  <PERS_INFO>
    <lastname>Smith</lastname>
    <firstname>Pop</firstname>
    <social_security_no>2851211173377</social_security_no>
    <birthday>11/12/1985</birthday>
    <address>FirstAvenue, 20</address>
    <phoneno>0040744444444</phoneno>
    <acc>
      <transaction>444</transaction>
      <transaction>550</transaction>
    </acc>
    <acc>
      <transaction>113</transaction>
      <transaction>-50</transaction>
      <transaction>89</transaction>
    </acc>
    <acc>
      <transaction>300</transaction>
    </acc>
  </PERS_INFO>
</doc>
This input file must start the following:

-create 2 new clients (using a stored procedure Pr_Add_New_Cust):
1 John Doe / 1800325171545 / 25.03.1980 / main, 15 / 0040722222222
2 Smith Pop / 2851211173377 / 11.12.1985 / FirstAvenue, 20 / 0040744444444

-for John Doe I create 3 new account (using a stored procedure Pr_Add_New_Account):
-account 1 - for this account, I have to create 3 new operations (using a stored procedure Pr_Create_New_Trans): DEPOSIT $ 200, $ 150 DEPOSIT, WITHDRAW $ 23
-account 2 - for this account, I need to create 1 new operations (using a stored procedure Pr_Create_New_Trans): DEPOSIT $ 450
-count of 3 - for this account, I have to create 3 new operations (using a stored procedure Pr_Create_New_Trans): DEPOSIT $ 800, DEPOSIT $ 320, WITHDRAWAL $ 125

-for Smith Pop I create 3 new account (using a stored procedure Pr_Add_New_Account):
-account 1 - for this account, I need to create 2 new operations (using a stored procedure Pr_Create_New_Trans): DEPOSIT $ 444, DEPOSIT $ 550
-account 2 - for this account, I have to create 3 new operations (using a stored procedure Pr_Create_New_Trans): DEPOSIT $ 113, WITHDRAW $50, DEPOSIT $ 89
-count of 3 - for this account, I need to create 1 new operations (using a stored procedure Pr_Create_New_Trans): DEPOSIT $ 300


Well, I think to do that by loading this XML into a table of staging pre - INS_STG1 - (the part of loading is not an issue at the moment) and by analyzing the XML code in order to get my (insert) in the second staging table INS_STG2 the information required to initiate these procedures.
Something like that (at the moment I only insert customer information since I do not know how to get on the floor):
DECLARE  

   TYPE ty_rec_1    IS RECORD (v_cust_firstname       VARCHAR2(32),
                               v_cust_lastname        VARCHAR2(32),
                               v_cust_persnumcode     VARCHAR2(32),
                               v_cust_birthday        VARCHAR2(32),
                               v_cust_address         VARCHAR2(32),
                               v_cust_phoneno         VARCHAR2(32));
   TYPE ty_cur_1       IS REF CURSOR RETURN ty_rec_1;
   TYPE ty_arr_rec_1   IS TABLE OF ty_rec_1 INDEX BY PLS_INTEGER;
   cur_1               ty_cur_1;
   arr_rec_1           ty_arr_rec_1;
   my_xml              xmltype;
   N_BULK_SIZE         NUMBER := 1000;
  
BEGIN 
  
  SELECT xml_column INTO my_xml FROM INS_STG1;
  
  OPEN cur_1 FOR
    SELECT extractvalue(column_value, '/PERS_INFO/firstname')          "v_cust_firstname",
           extractvalue(column_value, '/PERS_INFO/lastname')           "v_cust_lastname",
           extractvalue(column_value, '/PERS_INFO/social_security_no') "v_cust_persnumcode",
           extractvalue(column_value, '/PERS_INFO/birthday')           "v_cust_birthday",
           extractvalue(column_value, '/PERS_INFO/address')            "v_cust_address",
           extractvalue(column_value, '/PERS_INFO/phoneno')            "v_cust_phoneno"       
    FROM TABLE(XMLSequence(my_xml.extract('/doc/PERS_INFO'))) t;

    LOOP
       FETCH cur_1 BULK COLLECT INTO arr_rec_1 LIMIT N_BULK_SIZE;
       EXIT WHEN arr_rec_1.COUNT() = 0;
       FORALL n_idx1 IN 1..arr_rec_1.COUNT()
         INSERT INTO INS_STG2
           (cust_firstname, cust_lastname, cust_persnumcode, cust_birthday, cust_address, cust_phoneno)
          VALUES 
          (arr_rec_1(n_idx1).v_cust_firstname, arr_rec_1(n_idx1).v_cust_lastname, 
           arr_rec_1(n_idx1).v_cust_persnumcode, arr_rec_1(n_idx1).v_cust_birthday, 
           arr_rec_1(n_idx1).v_cust_address, arr_rec_1(n_idx1).v_cust_phoneno);
     END LOOP;
   CLOSE cur_1;  
  COMMIT;              

END;
This procedure is based on the SQL query that I'm starting to fold with in order to understand how to get the information from XML using SQL (the XML is hardcoded)
SELECT extractvalue(column_value, '/PERS_INFO/firstname')    "First Name",
       extractvalue(column_value, '/PERS_INFO/lastname')     "Last Name",
       extractvalue(column_value, '/PERS_INFO/social_security_no')  "Social Security No",
       extractvalue(column_value, '/PERS_INFO/birthday')     "Birth-day",
       extractvalue(column_value, '/PERS_INFO/address')      "Address",
       extractvalue(column_value, '/PERS_INFO/phoneno')      "Phone No"
  FROM TABLE(XMLSequence(
             XMLTYPE(
             '<?xml version="1.0" encoding="ISO-8859-1"?>
              <doc>
                <PERS_INFO>
                  <lastname>John</lastname>
                  <firstname>Doe</firstname>
                  <social_security_no>1800325171545</social_security_no>
                  <birthday>25/03/1980</birthday>
                  <address>Principal, 15</address>
                  <phoneno>0040722222222</phoneno>
                  <acc>
                    <transaction>200</transaction>
                    <transaction>150</transaction>
                    <transaction>-23</transaction>
                  </acc>
                  <acc>
                    <transaction>450</transaction>
                  </acc>
                  <acc>
                    <transaction>800</transaction>
                    <transaction>320</transaction>
                    <transaction>-125</transaction>
                  </acc>
                </PERS_INFO>
                <PERS_INFO>
                  <lastname>Smith</lastname>
                  <firstname>Pop</firstname>
                  <social_security_no>2851211173377</social_security_no>
                  <birthday>11/12/1985</birthday>
                  <address>FirstAvenue, 20</address>
                  <phoneno>0040744444444</phoneno>
                  <acc>
                    <transaction>444</transaction>
                    <transaction>550</transaction>
                  </acc>
                  <acc>
                    <transaction>113</transaction>
                    <transaction>-50</transaction>
                    <transaction>89</transaction>
                  </acc>
                  <acc>
                    <transaction>300</transaction>
                  </acc>
                </PERS_INFO>
              </doc>').extract('/doc/PERS_INFO'))) t;
My problem is that this query will only at the first level (the level of the customer). I don't know how to get to the second and third level (transactions/account).
Now, this query return:
Doe     John     1800325171545     25/03/1980     Principal, 15     0040722222222
Pop     Smith     2851211173377     11/12/1985     FirstAvenue, 20     0040744444444
and I want him back like this:
Doe     John     1800325171545     25/03/1980     Principal, 15     0040722222222  1   200
Doe     John     1800325171545     25/03/1980     Principal, 15     0040722222222  1   150
Doe     John     1800325171545     25/03/1980     Principal, 15     0040722222222  1  -23
Doe     John     1800325171545     25/03/1980     Principal, 15     0040722222222  2   450
Doe     John     1800325171545     25/03/1980     Principal, 15     0040722222222  3   800
Doe     John     1800325171545     25/03/1980     Principal, 15     0040722222222  3   320
Doe     John     1800325171545     25/03/1980     Principal, 15     0040722222222  3  -125 
Pop     Smith     2851211173377     11/12/1985     FirstAvenue, 20     0040744444444  1   444
Pop     Smith     2851211173377     11/12/1985     FirstAvenue, 20     0040744444444  1   550
Pop     Smith     2851211173377     11/12/1985     FirstAvenue, 20     0040744444444  2   113
Pop     Smith     2851211173377     11/12/1985     FirstAvenue, 20     0040744444444  2  -50
Pop     Smith     2851211173377     11/12/1985     FirstAvenue, 20     0040744444444  2   89
Pop     Smith     2851211173377     11/12/1985     FirstAvenue, 20     0040744444444  3   300
What I do for this SQL query to get the result at the transaction level (as in the second table)? This XML can be improved as well. If another structure service for my purpose, please let me know.

Thank you!

Like [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions061.htm#SQLRF06173] extractvalue is frowned upon in your version, you need to switch to another method, as shown in the documentation.

Go further with that, here's a starter SQL which gives you the desired result

WITH INS_STG1 AS
(SELECT XMLTYPE('
              
                
                  John
                  Doe
                  1800325171545
                  25/03/1980
                  
Principal, 15
0040722222222 200 150 -23 450 800 320 -125
Smith Pop 2851211173377 11/12/1985
FirstAvenue, 20
0040744444444 444 550 113 -50 89 300
') xml_column FROM DUAL ) -- The above simulates your table. Only the below matters. SELECT xt.First_Name, xt.birth_day, xt2.acc_rn, xt3.trans FROM INS_STG1, XMLTable('/doc/PERS_INFO' PASSING INS_STG1.xml_column COLUMNS First_Name VARCHAR2(20) PATH 'firstname', Birth_day VARCHAR2(10) PATH 'birthday', acc_xml XMLType PATH 'acc') xt, XMLTable('/acc' PASSING xt.acc_xml COLUMNS acc_rn FOR ORDINALITY, tran_xml XMLTYPE PATH 'transaction') xt2, XMLTable('/transaction' PASSING xt2.tran_xml COLUMNS trans NUMBER PATH '.') xt3;

product

FIRST_NAME           BIRTH_DAY      ACC_RN      TRANS
-------------------- ---------- ---------- ----------
Doe                  25/03/1980          1        200
Doe                  25/03/1980          1        150
Doe                  25/03/1980          1        -23
Doe                  25/03/1980          2        450
Doe                  25/03/1980          3        800
Doe                  25/03/1980          3        320
Doe                  25/03/1980          3       -125
Pop                  11/12/1985          1        444
Pop                  11/12/1985          1        550
Pop                  11/12/1985          2        113
Pop                  11/12/1985          2        -50
Pop                  11/12/1985          2         89
Pop                  11/12/1985          3        300

Now... There are probably a better way to XQuery to shoot that turned off, but I'll keep this better than me for someone of XQuery example.

I'll also include is it possible that all this work could be done in a single SQL statement, as indicated by
[url http://odieweblog.wordpress.com/2012/05/10/how-to-load-xml-data-into-multiple-tables/] How to: Load XML data in multiple tables

Tags: Database

Similar Questions

  • wanted to extract data from nested table pl/sql Ref Cursor getting an erro

    create or replace type 'DEPT12' as an object (dno number (2), dname varchar2 (30), varchar2 (50)) loc;

    create or replace type dept_tab in the table in "DEPT12".

    create or replace type 'LOC12' as an object (locno number, loc_name varchar2 (100))

    create or replace type loc_tab in the table of "LOC12.

    create or replace type dept_loc_rec1 as an object (dept_tab, eno number, loc_dt loc_tab dept_dt);

    Create type dept_loc_tb as table of the dept_loc_rec1

    create table dept_loc_tb_bk1 (dept_dt dept_tab, eno number, loc_dt loc_tab)
    NESTED TABLE dept_dt
    STORE AS dept_tab12,
    NESTED TABLE loc_dt
    STORE AS loc_tab12




    insert into dept_loc_tb_bk1 values (dept_tab (dept12(3,'ABD','LOC')
    dept12(4,'ABD','LOC')
    (, dept12(5,'ABD','LOC')), 3, loc_tab (loc12(21,'AAB'),
    loc12(22,'AAB'),
    loc12(23,'AAB')));

    When I try to extract data from Ref cursor to pl/sql table that I get an error ora-06504: pl/sql: return types of the result set of variables or request do not match.
    I created a table nested, as well as the pl/sql nested table object dept_loc_tb and I said the same dept_loc_tb lv_dept_loc_tb, but trying to get in this variable we get an error above.

    Please anyone can solve my problem.
    -----------------
    declare
    type cr is ref cursor;
    cr_obj cr;

    lv_dept_loc_tb dept_loc_tb;

    Start
    Open cr_obj to select dept_dt, eno, dept_loc_tb_bk1 loc_dt;
    collect the fetch cr_obj in bulk in lv_dept_loc_tb;
    close cr_obj;
    end;

    Your query selects 3 distinct columns requires so 3 collections of matching types. You want to treat these 3 columns as an object of type DEPT_LOC_REC1:

    SQL> declare
      2  type cr is ref cursor;
      3  cr_obj cr;
      4
      5  lv_dept_loc_tb dept_loc_tb;
      6
      7  begin
      8  open cr_obj for select dept_dt,eno,loc_dt from dept_loc_tb_bk1;
      9  fetch cr_obj bulk collect into lv_dept_loc_tb;
     10  close cr_obj;
     11  end;
     12  /
    declare
    *
    ERROR at line 1:
    ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
    ORA-06512: at line 9
    
    SQL> declare
      2  type cr is ref cursor;
      3  cr_obj cr;
      4
      5  lv_dept_loc_tb dept_loc_tb;
      6
      7  begin
      8  open cr_obj for select DEPT_LOC_REC1(dept_dt,eno,loc_dt) from dept_loc_tb_bk1;
      9  fetch cr_obj bulk collect into lv_dept_loc_tb;
     10  close cr_obj;
     11  end;
     12  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.
    P.S. discover sys_refcursor.

  • Extract data from complex XML of XMLType with nodes parents containing several internal nodes

    Hello

    I use Google geocoding XML Web Service to try to enrich some geo data in the database. I've kept all the Google result in an XMLType column, the result is something like this:

    <? XML version = "1.0" encoding = "UTF-8"? >

    < GeocodeResponse >

    < status > OK < / status >

    < result >

    Zip_code < type > < / type >

    < formatted_address > 76279, Saudi Arabia < / formatted_address >

    < address_component >

    < > 76279 long_name < / long_name >

    < > 76279 short_name < / short_name >

    Zip_code < type > < / type >

    < / address_component >

    < address_component >

    < long_name > Northern Frontier Province < / long_name >

    < short_name > Northern Frontier Province < / short_name >

    administrative_area_level_1 < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < address_component >

    < long_name > Saudi Arabia < / long_name >

    < short_name > SA < / short_name >

    country of < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < geometry >

    < location >

    < lat > 29.1214197 < / lat >

    < LNG > 44.3945656 < / LNG >

    < / location >

    < location_type > APPROX. < / location_type >

    < window >

    < Southwest >

    < lat > 29.1016132 < / lat >

    < LNG > 44.3654665 < / LNG >

    < / Southwest >

    < Northeast >

    < lat > 29.1400926 < / lat >

    < LNG > 44.4116001 < / LNG >

    < / Northeast >

    < / window >

    < limits >

    < Southwest >

    < lat > 29.1016132 < / lat >

    < LNG > 44.3654665 < / LNG >

    < / Southwest >

    < Northeast >

    < lat > 29.1400926 < / lat >

    < LNG > 44.4116001 < / LNG >

    < / Northeast >

    < / delimits >

    < / geometry >

    < place_id > ChIJcy767DIAYxURohAm-DLSunw < / place_id >

    < / result >

    < result >

    locality < type > < / type >

    < Type > policy < / type >

    Foucart, France < formatted_address > < / formatted_address >

    < address_component >

    < long_name > Foucart < / long_name >

    < short_name > Foucart < / short_name >

    locality < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < address_component >

    < long_name > Seine-Maritime < / long_name >

    < > 76 short_name < / short_name >

    administrative_area_level_2 < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < address_component >

    < long_name > upper Normandy < / long_name >

    < short_name > upper Normandy < / short_name >

    administrative_area_level_1 < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < address_component >

    < long_name > France < / long_name >

    < short_name > EN < / short_name >

    country of < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < geometry >

    < location >

    < lat > 49.6131170 < / lat >

    < LNG > 0.5951040 < / LNG >

    < / location >

    < location_type > APPROX. < / location_type >

    < window >

    < Southwest >

    < lat > 49.6019770 < / lat >

    < LNG > 0.5731880 < / LNG >

    < / Southwest >

    < Northeast >

    < lat > 49.6329760 < / lat >

    < LNG > 0.6081609 < / LNG >

    < / Northeast >

    < / window >

    < limits >

    < Southwest >

    < lat > 49.6019770 < / lat >

    < LNG > 0.5731880 < / LNG >

    < / Southwest >

    < Northeast >

    < lat > 49.6329760 < / lat >

    < LNG > 0.6081609 < / LNG >

    < / Northeast >

    < / delimits >

    < / geometry >

    < place_id > ChIJQdTiHHJc4EcRUIO2T0gUDAQ < / place_id >

    < / result >

    < / GeocodeResponse >


    Here are practically two entries from geo (the /result of xml nodes), and each entry has multiple secondary entries of type address_component and a secondary entrance to the geometry of type.


    I can get the entries in the result of this query:


    SELECT xt.*

    OF zip_tree_sort_xml x,.

    XMLTABLE ("' / GeocodeResponse/result")

    PASSAGE x.google_geodata_xml

    COLUMNS

    Path of 'FORMATTED_ADDRESS' VARCHAR2 (200) "formatted_address".

    ) xt;


    The subnodes XML type address_component and type geometry of teas and those below:


    SELECT xt.*

    OF zip_tree_sort_xml x,.

    XMLTABLE ('/ GeocodeResponse/result/address_component ')

    PASSAGE x.google_geodata_xml

    COLUMNS

    Path of "LONG_NAME' VARCHAR2 (200)"long_name. "

    'SHORT_NAME' VARCHAR2 (500) PATH 'short_name ',.

    Path ACCESS VARCHAR2 (200) from 'TYPE_1' 'type [1]. "

    Path ACCESS VARCHAR2 (200) to 'TYPE_2' 'type [2].

    ) xt;


    SELECT xt.*

    OF zip_tree_sort_xml x,.

    XMLTABLE ("/ GeocodeResponse/result/geometry/location")

    PASSAGE x.google_geodata_xml

    COLUMNS

    "latitude" NUMBER PATH 'lat ',.

    "longitude" NUMBER PATH 'LNG '.

    ) xt;


    But y at - it anyway to join the two subnodes XML below with the parent that above? So I can only get correct result attributes?

    Best regards

    Rodriguez

    But y at - it anyway to join the two subnodes XML below with the parent that above? So I can only get correct result attributes?

    You can do chaining XMLTABLE another that will handle the address_component expandable nodes.

    Data from the geometry node can be extracted at the same level as a result.

    SQL> select x1.formatted_address
      2       , x2.long_name
      3       , x2.short_name
      4       , x2.type_1
      5       , x2.type_2
      6       , x1.latitude
      7       , x1.longitude
      8  from zip_tree_sort_xml t
      9     , xmltable('/GeocodeResponse/result'
     10         passing t.google_geodata_xml
     11         columns
     12           formatted_address   varchar2(200) path 'formatted_address'
     13         , address_components  xmltype       path 'address_component'
     14         , latitude            number        path 'geometry/location/lat'
     15         , longitude           number        path 'geometry/location/lng'
     16       ) x1
     17     , xmltable('/address_component'
     18         passing x1.address_components
     19         columns
     20           long_name   varchar2(200) path 'long_name'
     21         , short_name  varchar2(500) path 'short_name'
     22         , type_1      varchar2(200) path 'type[1]'
     23         , type_2      varchar2(200) path 'type[2]'
     24       ) x2 ;
    
    FORMATTED_ADDRESS       LONG_NAME                   SHORT_NAME                   TYPE_1                         TYPE_2       LATITUDE  LONGITUDE
    ----------------------- --------------------------- ---------------------------- ------------------------------ ---------- ---------- ----------
    76279, Saudi Arabia     76279                       76279                        postal_code                               29,1214197 44,3945656
    76279, Saudi Arabia     Northern Borders Province   Northern Borders Province    administrative_area_level_1    political  29,1214197 44,3945656
    76279, Saudi Arabia     Saudi Arabia                SA                           country                        political  29,1214197 44,3945656
    Foucart, France         Foucart                     Foucart                      locality                       political   49,613117   0,595104
    Foucart, France         Seine-Maritime              76                           administrative_area_level_2    political   49,613117   0,595104
    Foucart, France         Upper Normandy              Upper Normandy               administrative_area_level_1    political   49,613117   0,595104
    Foucart, France         France                      FR                           country                        political   49,613117   0,595104
    
    7 rows selected.
    
  • How to extract data from SQL server in the FDM

    Hi Experts

    How to extract data from a SQL server HFM to another SQL Server using scripts for integration in FDQM?

    concerning

    Dev

    Could you clarify why you want to do this?

    If you try to synchronize two databases (apps) to have a backup or something running in a development environment, I suggest configuring replication between two databases. It would be much more effective to do it at the SQL Server level through the application of FDM, IMHO.

    Charles

  • Extract data from Oracle into excel file

    Hello

    I have a requirement where in I need to extract data from Oracle into excel file and the worksheet excel name should be 'given '.
    for example. Excel 'AR Data_DDMMYY' file name and the name of the "Data" sheet excel

    I used the UTL_FILE API to extract the data delimited by tabs that you can open in excel, but it's not exactly an excel file as the name of the worksheet is the same as the name of the file.

    I tried to use utl_file.fcopy and frename.

    Is it possible to do it using PLSQL?

    Select * from version of v$.
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    "CORE     10.2.0.5.0     Production"
    TNS for HPUX: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    Example Code:
    declare
    cursor c is
    select * from scott.emp;
    v varchar2(100);
    f utl_file.file_type;
    
    file_name varchar2(100) := 'AR Data.xls';
    dir varchar2(50) := 'CESDIR191710';
    
    --select * from dba_directories
    
    begin
    
    
    f := utl_file.fopen(dir, file_name, 'W');
    
    v := 'EMPNO'||chr(9)||'ENAME'||chr(9)||'JOB'||chr(9)||'SAL'||chr(9)||'HIREDATE'||chr(9)||'DEPTNO';
    utl_file.put_line(f, v);
    
    for i in c
    loop
    
    v := i.empno||chr(9)||i.ename||chr(9)||i.job||chr(9)||i.sal||chr(9)||i.hiredate||chr(9)||i.deptno;
    utl_file.put_line(f, v);
    
    end loop;
    utl_file.fclose(f);
    
    --utl_file.frename(dir, file_name, dir, replace(file_name, '.xls', '_')||to_char(sysdate, 'MMDDYY')||'.xls', false);
    utl_file.fcopy(dir, file_name, dir, replace(file_name, '.xls', '_')||to_char(sysdate, 'MMDDYY')||'.xls');
    
    end;
    Thank you
    Imran

    Hello

    I tried to change the .xlsx to .xls and it gives a note at the opening of the file "the file you are trying to open, abc.xls, is in a different format that it is specified by the file extension. Check that the file is not corrupted and precedes from a trusted source before you open the file. Do you want to open it now? »

    When you rename the file does not solve your problem.
    Anton Scheffer package generates a file in format xlsx Office 2010. When rename you it with the .xls extension, then Office 2010 will give you the warning that the file format does not match the extension.

    but the requirement has to generate excel 2003 file.

    The xml_spreadsheet package writes a format that was introduced with Office 2003, but you must use .xml as extension in other Office 2010 will give you the same caveat.
    To write the real xls version (binary), you can use Apache POI. You will need to import Java classes in your db and write a PL/SQL wrapper. Or you can use one of the options above, writing the output to a windows server and then use Excel to open and save in the required format.

    You must decide whether it is easier to write the binary xls format or to convince the customer to accept other formats that can be opened with Excel.

    Concerning
    Marcus

  • extract data from a table to a text file

    I need to extract data from a table to a text file, I twist my output is the following...

    bash-3. $00 vi tap3roamercosts_20110915144318.txt
    lines of 'tap3roamercosts_20110915144318.txt' 393948, 23464348 characters
    ^ LAFGTD | N | 2011090203000001 | 13242514000064 | 1. 0 | 20. 41220 | 02-SEVEN.-11. 01-SEPT.-11. 0 | 13244
    755. 64. 70. 0093794428588 | 0093796234547 | 0 | S2 | E | 412200306902634 | 8. 1. 61500 | 16081 |
    | HW | Call to the Roamer. 0 | I have | Roaming billing Inroamer Plan | 1_0_1 | LKA | N_I_Independent
    the time of day. Rate of Roamer SMST systems | AFGTD20110902030000010001013242514000064 |
    |||||||||||||||||||||

    AFGTD | N | 2011090203000001 | 13242612000044 | 1. 0 | 20. 41220 | 02-SEVEN.-11. 01-SEPT.-11. 0 | 13244
    853. 44. 70. 234. 0093793252818 | 0 | S2 | E | 412200303198150 | 8. 1. 61000 | 12403 | HW | -Ro
    bitter call | 0 | I have | Roaming billing Inroamer Plan | 1_0_1 | N_I_Independent time of Da
    There | Rate of Roamer SMST systems | AFGTD20110902030000010001013242612000044 |
    ||||||||

    AFGTD | N | 2011090203000001 | 13242612000047 | 1. 0 | 20. 41220 | 02-SEVEN.-11. 01-SEPT.-11. 0 | 13244
    853. 47. 70. 234. 0093793252818 | 0 | S2 | E | 412200303198150 | 8. 1. 61000 | 12403 | HW | -Ro
    bitter call | 0 | I have | Roaming billing Inroamer Plan | 1_0_1 | N_I_Independent time of Da
    There | Rate of Roamer SMST systems | AFGTD20110902030000010001013242612000047 |
    ||||||||
    .
    .
    .
    .
    .

    Please help me how to format my output each record in simple lines in oracle sqlplus. Here are the settings I used...

    TERMOUT OFF SET;
    SET ECHO OFF;
    SET LINESIZE 100000;
    THE VALUE OF NEWPAGE 0;
    SET SPACE 0;
    SET PAGESIZE 50000;
    SET FEEDBACK OFF;
    SET THE OFF POSITION;
    SET TRIMSPOOL
    SET THE TAB

    And what was wrong with the answers that you have on your previous thread?

    How to extract data in a text file

    Please do not ask the same question again. If there is a problem with the answers provided, then continue on the same thread that tell people what is the problem.

    Saying that, this is another possibility for you...

    As user sys:

    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    /
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /
    

    As myuser:

    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      --
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;
    

    This allows the header line and the data to write into files separate if necessary.

    for example

    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    
    PL/SQL procedure successfully completed.
    

    Output.txt file contains:

    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10
    

    The procedure allows for the header and the data to separate files if necessary. Just by specifying the file name "header" will put the header and the data in a single file.

    Adapt to the exit of styles and different types of data are needed.

  • Query to extract data from source DB driver using process mapping pre...

    Hi all
    I have a source for the query to retrieve the data from the source database. Looking for suggestion what could be the best approach to extract data from the source database.using owb 11 GR 1 material.
    I'm in printing, create the process of mapping driver prerequisite for aid to perform immediate with Create table T1 as a sql query. Petition to the sides of the Insert into T1 Select * from Source_Table in the different database.

    Certainly, need to create Db users in the Source database, to get privileges to read the data of source_database.
    Is - this good aproach to or of any other alternative to achieve this.

    Means, create the table in the transit area (desired area, where I am) and using driver mapping process before you run the select query to retrieve data from a data source.

    Would apreciate your previous answer.
    Thank you
    MAK

    You can mark Correct or useful if it solves your purpose.

  • Extract data from error HFM, float to Numeric?

    Hi all

    We extract data from HFM,.

    HFM-> SQL-> FILE staging

    Our mapping, flow, everything seems fine. When we run this out on the third market errors while extracting data with the following:

    com.hyperion.odi.common.ODIHAppException: arithmetic overflow error conversion float type numeric data.


    We researched and found to increase the logical length should solve this problem.

    Our Source has a length of 16...

    We have increased the logical length of target from 16 to 30, and he rest-error. We even tried 50, 100 for the logical length.

    We are at Version 10.1.3.6.0.

    Any suggestions on how to fix this?

    Thank you!

    Published by: user10678366 on May 22, 2013 13:28

    Have you tried changing the scale of all the columns float, right?

    It can be a ridiculously large number coming from HFM. So, go to store for your data source in ODI and manually change the data type of column type VARCHAR of size like 100 or more. That would force the ODI to create the staging table with columns of characters for the field. Data will be retrieved anyway. Given that you write it in file, type of character should not matter. In addition, if writing to the file fails for any reason, you can do a max on the staging table and find the value problem in the table (while in HFM, you may not be able to do).

  • Script Insert statement to extract data from Table in Oracle 7i

    Hi all, I have an old Oracle legacy system that works for more than 15 years. Every now and then, we need to extract data from this table @ ORacle 7i to import to Oracle 10 G.

    My thoughts are to create a script to Insert statements in oracle 7 and that, to be deployed to Oracle 10 G.

    I found cela scripts in Google and don't know exactly how it works. No explanation on these scripts, would be greatly appreciated. I find that this format can help to produce a set of insert statements in this table to the last table to 10G.

    < pre >
    -Step 1: create this procedure:
    create or replace function ExtractData (v_table_name varchar2) return varchar2 as
    Boolean b_found: = false;
    v_tempa varchar2 (8000);
    v_tempb varchar2 (8000);
    v_tempc VARCHAR2 (255);
    Start
    for tab_rec in (select table_name from user_tables where table_name = upper (v_table_name))
    loop
    b_found: = true;
    v_tempa: =' select ' insert into ' | tab_rec.table_name |' (';
    for col_rec in (select * from user_tab_columns)
    where
    table_name = tab_rec.table_name
    order by
    column_id)
    loop
    If col_rec.column_id = 1 then
    v_tempa: = v_tempa | " ' || Chr (10) | " ' ;
    on the other
    v_tempa: = v_tempa |', ". Chr (10) | " ' ;
    v_tempb: = v_tempb |', ". Chr (10) | " ' ;
    end if;
    v_tempa: = v_tempa | col_rec.column_name;
    If instr(col_rec.data_type,'CHAR') > 0 then
    v_tempc: = "' |' | col_rec.column_name |'| " ' ;
    elsif instr (col_rec.data_type, 'DATE') > 0 then
    v_tempc: = "' to_date ("'| to_char('|| col_rec.column_name||',''mm/DD/YYYY HH24 '') | ") (', "' dd/mm/yyyy hh24"') "';
    on the other
    v_tempc: = col_rec.column_name;
    end if;
    v_tempb: = v_tempb | " ' || Decode('|| col_rec.column_name||',''Null'','||v_tempc||') | " ' ;
    end loop;
    v_tempa: = v_tempa |') values ('| v_tempb |'); "from ' |" tab_rec.table_name | « ; » ;
    end loop;
    If not b_found then
    v_tempa: ='-Table ' | v_table_name | 'not found ';
    on the other
    v_tempa: = v_tempa | Chr (10) | "select"-commit; "double;';
    end if;
    Return v_tempa;
    end;
    /
    display errors

    -STEP 2: run the following code to extract the data.
    Go head
    set pages 0
    game of stripes on
    fixed lines 2000
    the feeding off value
    trigger the echo
    var retline varchar2 (4000)
    coil c:\t1.sql
    Select 'set echo off' from dual;
    Select 'spool c:\recreatedata.sql' from dual;
    Select ' select "-these data was extracted on" | TO_CHAR (sysdate, "mm/dd/yyyy hh24" ") double;' double.

    -The following two lines as repeat as many times as the tables that you want to extract
    exec: retline: = ExtractData ('dept');
    print: retline;

    exec: retline: = ExtractData ('emp');
    print: retline;

    Select 'off spool' from dual;
    spool off
    @c:\t1

    -Step 3: run the updated c:\recreatedata.sql waiting for output to recreate the data.

    Source: http://www.idevelopment.info/data/Oracle/DBA_tips/PL_SQL/PLSQL_5.shtml




    < / pre >

    Hello

    Well what this script do.
    You will pass a table name as input to the function that will return varchar2 (string - insert statement). It will generate 2 t1.sql of sql script that contains the output sequence.

    Will use the first passed the user_tables scipt to check if the input table name exists and if there is the will reterive user_table_columns column names and generate the following sql script.
    Now, this t1.sql will run to generate a final sript formally orders insert that will run you on the target schema (make sure that the table exists).

    * #t1.sql*

    set echo off
    spool recreatedata.sql
    select '-- This data was extracted on '||to_char(sysdate,'mm/dd/yyyy hh24:mi') from dual;
    select 'insert into MY_OBJECT1 ('||chr(10)||'OWNER,'||chr(10)||'TOTAL) values ('||decode(OWNER,Null,'Null',''''||OWNER||'''')||','||chr(10)||''||decode(TOTAL,Null,'Null',TOTAL)||');' from MY_OBJECT1;
    select '-- commit;' from dual;
    spool off
    

    Then @t1.sql runs, and the general insert for the infeed table table.

    -- This data was extracted on 03/09/2009 23:39
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('MDSYS', 92800);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('TSMSYS', 256);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('DMSYS', 15104);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('TESTME', 128);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('PUBLIC', 2571392);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('OUTLN', 768);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('CTXSYS', 21888);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('OLAPSYS', 78336);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('KLONDIKE', 2432);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('SYSTEM', 51328);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('EXFSYS', 21504);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('DBSNMP', 4096);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('ORDSYS', 216192);
    
    INSERT INTO MY_OBJECT1 (OWNER, TOTAL)
      VALUES   ('SYSMAN', 111744);
    
    -- commit;
    

    Hope this helps
    Concerning

  • 1074118649 error occurred at niUSRP extract data from Rx (2D CBD) .vi

    Hello

    When I was trying the example of the USRP OR which is "niUSRP EX Rx synchronized to multiple entries (MIMO Expansion)", a mistake is released which is

    1074118649 error occurred at niUSRP extract data from Rx (2D CBD) .vi

    A workflow command has been issued in the past.

    can anyboay help me solve the problem?

    Thank you very much

    Andy

    Hi andy,.

    what you need to do is reversing the Oder river where the screw niUSRP the value Time.vi and niUSRP Trigger.vi configure a1.1ppear. Time of first setting then set up trigger. The example works correctly with version 1.1, since you are using version 1.2, that changes must be made.

    In the example, you can set the clock to standard time (start time = 0) even if you had already triggered the reception. Thus, samples received will be acquired with time stamp later where the error.

    Best regards

  • Extract data from graph XY

    Hello

    Here, I want to extract data from the XY graph. I joined vi which I use for table 1 d. How can I use this for 2D table VI.

    Thank you

    Hi Alex,

    You can use the same approach.

    The only thing that changes is the function ArraySubset in its adaptation to the 2D matrix. You can select rows or clumns of your data (depending on how you have generated them)...

  • How to ETL extract data from database Oracle 11.1 using Cognos Data Manager 10.1

    Hello

    I need to run the IBM Cognos Data Manager 10.1 version ETL tool for extracting data from the Oracle11.1 database.

    My understanding is that, from the point of view of database, the best way would to have a stored procedure that will provide a reference cursor in the ETL client tool.

    However, a database procedure the ETL tool running seems not to be possible in this version of the data manager.

    If someone has done this before? What is the best way for this snippet to do?

    Thank you

    Emilija

    Annabelle says:

    My reading of original question: "What is the best way for this snippet to do?"

    Sorry - is NOT helping.

    The BEST way to extract data from a table is to use a SELECT statement.

    You said you want to do.

    So just repeat your original question instead of those that ask you to answer will not move forward us.

  • Is there any task under the WSF to extract data from configuration of an instance as working Structures?

    Hello

    Is there any task in the Installation Manager to extract data from configuration of an instance as working Structures, research etc.

    I'm looking for the same kind that I could move all these configurations of one example to the other.

    Thank you

    Maury

    The name of the task is to manage Configuration packages in the installation and maintenance program. You can see this document http://docs.oracle.com/cd/E48434_01/fusionapps.1118/e49542/F1166430AN11D30.htm

  • How to extract data from a signed pdf that was sent to me.

    I can extract data from a PDF file that is not signed, but how to extract data from a signed PDF? Exporting data option does not work once it is signed. Specifically, I want to combine the data into a csv file, but a PDF signed does not to me.

    Hi evanb92625060,

    It is not possible to extract (using Acrobat |) Collection and management of the PDF to form data) data from a signed PDF form is that it locks all fields in the form.

    Kind regards
    Nicos

  • Extract data from form DPS 2015?

    I have a registration form with some fields such as name, email etc. identification and a "submit" button.

    Here are a few questions about this:

    1. can I create a form with fields (name, e-mail id) in 2015 DPS.

    2. If so, how can retrieve us the data from the form after submission. Is there an API to extract data from form of DPS 2015?

    3. where we store the data? Can it be stored in the AEM or DPS?

    Appreciate your suggestions and help.

    Hi Kalyan,

    It's nothing built in DPS to do this, however you can use the HTML articles for this feature. You will need to write JavaScript code to handle the #2 and #3 elements. It is up to you to decide where you want to store the information collected. Usually you get shipped back through a Web service to a site or a database, you manage.

    Neil

Maybe you are looking for