我使用Oracle 10g快捷在Windows XP中,並在MacBook OS X 10.5.8上運行PHP 5.3.1與PDO和Oracle即時客戶端10.2.0.4.0_4,我運行下面的腳本:如何從PHP獲取Oracle SQL查詢的EXPLAIN PLAN?
<?php
$pdo = new PDO("oci:dbname=winders:1521/xe", "system", "XXXXXX");
...
$sql = "WITH NumberedBugs AS (
SELECT b.*, ROW_NUMBER() OVER (ORDER BY bug_id) AS RN
FROM Bugs b
) SELECT * FROM NumberedBugs WHERE RN = :offset";
$stmt = $pdo->prepare($sql);
$stmt->execute($offset);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
沒問題。但我也希望能夠編寫一個PHP腳本來獲取此查詢的EXPLAIN PLAN
報告。當我嘗試,我得到一個錯誤:
$sql = "EXPLAIN PLAN FOR WITH NumberedBugs AS (
SELECT b.*, ROW_NUMBER() OVER (ORDER BY bug_id) AS RN
FROM Bugs b
) SELECT * FROM NumberedBugs WHERE RN = 1234";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
(我改變了查詢參數的硬編碼整數文字此測試。)
當我嘗試打電話fetch()
我得到這個錯誤:
ORA-24374: define not done before fetch or execute and fetch
什麼的這個解釋,我怎麼能得到一個PHP腳本EXPLAIN PLAN
報告?我已經做了一些網絡搜索這個錯誤,但我找不到足夠清楚的解釋。
謝謝比爾,剛剛給你發了一封電子郵件。 – 2011-11-27 03:35:55