gpt4 book ai didi

php - 从 PHP 运行长的 Oracle 存储过程

转载 作者:可可西里 更新时间:2023-11-01 13:29:34 25 4
gpt4 key购买 nike

我有一个从 PHP 运行的存储过程:

//Request does not change
$sql = 'BEGIN SP_GET_MY_DATA(:POP, :SEG, :DUR, :VIEW, :PAGE, :OUTPUT_CUR); END;';

//Statement does not change
$stmt = oci_parse($conn,$sql);
oci_bind_by_name($stmt,':POP',$pop);
oci_bind_by_name($stmt,':SEG',$seg);
oci_bind_by_name($stmt,':DUR',$dur);
oci_bind_by_name($stmt,':VIEW',$view);
oci_bind_by_name($stmt,':PAGE',$page);

//But BEFORE statement, Create your cursor
$cursor = oci_new_cursor($conn)

// On your code add the latest parameter to bind the cursor resource to the Oracle argument
oci_bind_by_name($stmt,":OUTPUT_CUR", $cursor,-1,OCI_B_CURSOR);

// Execute the statement as in your first try
oci_execute($stmt);

// and now, execute the cursor
oci_execute($cursor);

// Use OCIFetchinto in the same way as you would with SELECT
while ($data = oci_fetch_assoc($cursor, OCI_RETURN_LOBS )) {
print_r($data}
}

问题是我在存储过程中有数百万行和复杂的逻辑。当我通过 SQL Developer 执行 SP_GET_MY_DATA 时,大约需要 2 个小时才能完成。

当我执行此操作时,PHP 超时。我也无法增加 PHP 中的 max_execution_time。

如何在 Oracle 或使用 PHP 上运行它而不会超时?请帮忙。

最佳答案

我在 DBA stack exchange 上的这个回答中非常全面地回答了如何使用 Oracle Scheduler 异步运行长时间运行的过程。参见 https://dba.stackexchange.com/a/67913/38772

TL;DR 是

-- submit this as a background job
BEGIN
dbms_scheduler.create_job (
job_name => 'MY_BACKGROUND_JOB'
, job_type => 'STORED_PROCEDURE'
, job_action => 'SP_GET_MY_DATA'
, enabled => TRUE
, auto_drop => TRUE
);
END;

如果要将参数传递给过程,则需要做更多的工作。您可能会发现此答案很有帮助 https://dba.stackexchange.com/q/42119/38772/

有关所有详细信息的其他引用,Oracle 文档中的相关章节位于 https://docs.oracle.com/database/121/ADMIN/scheduse.htm

关于php - 从 PHP 运行长的 Oracle 存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47223908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com