之前一直涉及数据批量处理,PHP在oracle的数据处理上,效率一直不高。
由于没有多线程等,特别受限。
其他语言又不太会写,尝试了很多方法。
终于在今天发现一个方法,可以高效的执行insert语句。
在这之前使用insert all的语法,有一些提升,但是不高。
本次采用的是 pl/sql的存储过程方式。思路来源:
plsql - Executing an oracle .sql file with php - Stack Overflow
原本是想通过load data的方式,后来说到:
Read the file, parse it for semi-colons, and pass each resulting string (minus the semi-colon) to oci_parse/oci_execute, or
Change your file so it's a valid PL/SQL block, with BEGIN at the beginning and END; at the end, with each of the DDL statements you want to execute in an EXECUTE IMMEDIATE as shown below:
效率大概是,执行一万条insert 语句在十多二十秒左右,完全可以接受。
这里面要注意的就是:insert语句中有单引号,因为不是动态SQL,所以单引号需要转义,使用两个连续的单引号即可。
否则会报错:ORA-06550错误