<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 = 'INSERT ALL';
$select = $html->find('select[id=auto-car-mm-0]', 0);
foreach($select->find('option') as $opt)
{
if($opt->value == '') continue;
$i .= ' INTO kolesa_brands (id, name) VALUES('.$opt->value.', \''.$opt->plaintext.'\')';
$brands[$opt->value] = $opt->plaintext;
}
$insert = oci_parse($conn, $i.' SELECT * FROM dual;');
oci_execute($insert);</blockquote>
BEGIN
UPDATE kolesa_brands SET name = 'name' WHERE id = <id>;
IF SQL%NOTFOUND THEN
INSERT INTO kolesa_brands (id, name) VALUES (<id>, '<name>');
END IF;
END;
<id>, <name>
нужно подставить значения $opt->value и $opt->plaintext). Так как для merge нужно две таблицы можно попробовать использовать виртуальную таблицу dualmerge 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)
<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>
MERGE
INTO users_dest dest
USING( SELECT 1 user_id, 10 points FROM dual) src
ON( dest.user_id = src.user_id )
WHEN MATCHED THEN
UPDATE SET points = src.points
WHEN NOT MATCHED THEN
INSERT( user_id, points )
VALUES( src.user_id, src.points );
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;
for ($i = 0; $i < count($router); $i++) {
$query = "MERGE INTO CORE_INTERFACES USING dual ON "
// The next row is the match criteria, like If "HOSTNAME" AND "IFINDEX" exist, Then Update else INSERT NEW HOSTNAMES!
. "( HOSTNAME = '" . $hostname . "' AND IFINDEX = '" . t trim($router_interface[0]) . "')"
. "WHEN MATCHED THEN UPDATE SET "
. "IFNAME = '" . trim($router_interface[1]) . "',IFTYPE = '" . trim(clean_iftype($router_interface[2])) . "',IFADMINSTATUS = '" . trim(clean_output($router_interface[3])) . "',"
. "LAST_UPDATE = CURRENT_TIMESTAMP "
. "WHEN NOT MATCHED THEN INSERT ("
. "IF_ID,HOSTNAME,IFINDEX,IFNAME,IFTYPE,IFADMINSTATUS,"
. "FIRST_SEEN "
. ") VALUES ("
. " core_interfaces_seq.nextval, "
. "'" . $hostname . "'," //$HOSTNAME
. "'" . trim($router_interface[0]) . "'," //ifIndex
. "'" . trim($router_interface[1]) . "'," //ifName
. "'" . trim(clean_iftype($router_interface[2])) . "'," //ifType
. "'" . trim(clean_output($router_interface[3])) . "'," //ifAdminState
. " CURRENT_TIMESTAMP )";
$stid = oci_parse($gnedb, $sql);
}
<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>
Warning: oci_execute(): ORA-06550: line 1, column 6: PLS-00103: Encountered the symbol "\" when expecting one of the following: ( begin case declare exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock inser...
begin\r\nmerge into kolesa_brands tusing (select 4 id, ARO name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 1 id, Acura name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 2 id, Alfa Romeo name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 3 id, Alpina name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 6 id, Aston Martin name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 7 id, Audi name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 150 id, BAW name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 11 id, BMW name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 15 id, BYD name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 9 id, Bentley name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 140 id, Brilliance name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 14 id, Buick name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 16 id, Cadillac name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 17 id, Chana name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 122 id, Changan name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 18 id, Chery name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 19 id, Chevrolet name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)\r\nmerge into kolesa_brands tusing (select 20 id, Chrysler name from dual) n on ( t.id = n.id)when matched thenupdate set t.name = n.namewhen not matched theninsert (t.id, t.name) values (n.id, n.name)