Oracle: загрузка большого XML-файла?

У меня есть надуманный пример: давайте подумаем о линейной регрессии на 2D-плоскости. В этом случае функция потерь будет среднеквадратичной ошибкой, подобранная линия минимизирует эту ошибку.

Однако, по какой-то причине нас очень очень интересует площадь под кривой от 0 до 1 нашей подогнанной линии, и, таким образом, это может быть одной из метрик. И мы отслеживаем этот показатель, в то время как модель минимизирует среднеквадратичную функцию потери ошибок.

5
задан Mark Harrison 15 July 2009 в 10:18
поделиться

3 ответа

Вы можете получить доступ к файлам XML на сервере через SQL. С вашими данными в /tmp/tmp.xml вы сначала должны объявить каталог:

SQL> create directory d as '/tmp';

Directory created

Затем вы можете напрямую запросить свой XML-файл:

SQL> SELECT XMLTYPE(bfilename('D', 'tmp.xml'), nls_charset_id('UTF8')) xml_data
  2    FROM dual;

XML_DATA
--------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<badges>
  [...]

Чтобы получить доступ к полям в вашем файле, вы можете использовать метод, описанный в другой SO , например:

SQL> SELECT UserId, Name, to_timestamp(dt, 'YYYY-MM-DD"T"HH24:MI:SS.FF3') dt
  2    FROM (SELECT XMLTYPE(bfilename('D', 'tmp.xml'), 
                            nls_charset_id('UTF8')) xml_data
  3            FROM dual),
  4         XMLTable('for $i in /badges/row
  5                              return $i'
  6                  passing xml_data
  7                  columns UserId NUMBER path '@UserId',
  8                          Name VARCHAR2(50) path '@Name',
  9                          dt VARCHAR2(25) path '@Date');

    USERID NAME       DT                         
---------- ---------- ---------------------------
      3718 Teacher    2008-09-15 08:55:03.923    
       994 Teacher    2008-09-15 08:55:03.957    
12
ответ дан 18 December 2019 в 12:01
поделиться

Seems like you're talking about 2 issues -- first, getting the XML document to where Oracle can see it. And then maybe making it so that standard relational tools can be applied to the data.

For the first, you or your DBA can create a table with a BLOB, CLOB, or BFILE column and load the data. If you have access to the server on which the database lives, you can define a DIRECTORY object in the database that points to an operating system directory. Then put your file there. And then either set it up as a BFILE or read it in. (CLOB and BLOB store in the database; BFILE stores a pointed to a file on the operating system side).

Alternatively , use some tool that will let you directly write CLOBs to the database. Anyway, that gets you to the point where you can see the XML instance document in the database.

So now you have the instance document visible. Step 1 is done.

Depending on the version, Oracle has some pretty good tools for shredding the XML into relational tables.

It can be pretty declarative. While this gets beyond what I've actually done (I have a project where I'll be trying it this fall), you can theoretically load your XML Schema into the database and annotate it with the crosswalk between the relational tables and the XML. Then take your CLOB or BFILE and convert it to an XMLTYPE column with the defined schema and you're done -- the shredding happens automatically, the data is all there, it's all relational, it's all available to standard SQL without the XQUERY or XML extensions.

Of course, if you'd rather use XQUERY, then just take the CLOB or BFILE, convert it to an XMLTYPE, and go for it.

3
ответ дан 18 December 2019 в 12:01
поделиться

Я бы сделал простое:

grep '<row' file.xml |\
gawk -F '"' '{printf("insert into badges(userid,name,date) values (\"%s\",\"%s\",\"%s\");\n",$2,$4,$6); } > request.sql

или вы можете создать программу Java, используя синтаксический анализатор SAX. Каждый раз, когда ваш обработчик находит новый элемент «строка», вы получаете атрибуты и вставляете новую запись в свою базу данных.

0
ответ дан 18 December 2019 в 12:01
поделиться
Другие вопросы по тегам:

Похожие вопросы: