<blockquote>require_once "simple_html_dom.php";
error_reporting(E_ALL);
ini_set('display_errors', '1');
$conn = oci_connect('ddd', 'ddd', '127.0.0.1/orcl', 'AL32UTF8');
$brands = array();
$html = str_get_html(file_get_contents('https://kolesa.kz/cars/'));
$i = 'begin ';
$i .= '\r\n';
$select = $html->find('select[id=auto-car-mm-0]', 0);
foreach($select->find('option') as $opt)
{
if($opt->value == '') continue;
$i .= 'merge into kolesa_brands t ';
$i .= 'using (select '.$opt->value.' id, \''.$opt->plaintext.'\' name from dual) n on (t.id = n.id) ';
$i .= 'when matched then ';
$i .= 'update set t.name = n.name ';
$i .= 'when not matched then ';
$i .= 'insert (t.id, t.name) values (n.id, n.name);';
$i .= '\r\n';
$brands[$opt->value] = $opt->plaintext;
}
$i .= '\r\n';
$i .= 'end;';
$insert = oci_parse($conn, $i);
oci_execute($insert);</blockquote>
begin
--Первый запрос
merge into kolesa_brands t
using ( select <id> id, '<name>' name from dual ) n on ( t.id = n.id)
when matched then
update set t.name = n.name
when not matched then
insert (t.id, t.name) values (n.id, n.name);
--Второй запрос
merge into kolesa_brands t
using ( select <id> id, '<name>' name from dual ) n on ( t.id = n.id)
when matched then
update set t.name = n.name
when not matched then
insert (t.id, t.name) values (n.id, n.name);
--и т.д.
end;
$i .= 'insert (t.id, t.name) values (n.id, n.name);';