Ich glaube, ich habe das herausgefunden. Anscheinend musste aus diesem PL/SQL-Skript eine Prozedur erstellt werden:
CREATE OR REPLACE PROCEDURE getExamStatus(RC OUT SYS_REFCURSOR) AS
exam_ids VARCHAR2(255);
BEGIN
SELECT
LISTAGG(''''
|| exam_id
|| ''' AS \"'
|| exam_name
|| '\"',',') WITHIN GROUP(
ORDER BY
exam_id ASC
)
INTO exam_ids
FROM
exam;
OPEN rc FOR 'SELECT
*
FROM
(
SELECT
u.user_id,
u.user_name,
e.exam_id,
eu.exam_date
FROM
users u
LEFT JOIN exam_user eu ON u.user_id = eu.user_id
LEFT JOIN exam e ON e.exam_id = eu.exam_id
ORDER BY
u.user_id
)
PIVOT ( MAX ( exam_date )
FOR exam_id
IN ( ' || EXAM_IDS || ' )
)
ORDER BY
1';
END;
/
Führen Sie dann diese Prozedur in der Datenbank aus. Danach musste ich in der PHP-Datei die SQL-Anweisung umgestalten:
$sql = "BEGIN getExamStatus(:rc); END;";
Und die Funktion:
function getSQLResult($sql, $conn) {
$stmt = oci_parse($conn, $sql);
if( $stmt === false ) {
errorShutdown(__('...'), __('...'));
die();
} else {
$rc = oci_new_cursor($conn);
oci_bind_by_name($stmt, ':rc', $rc, -1, OCI_B_CURSOR);
if(!oci_execute($stmt)) {
return false;
//return oci_error($stmt);
}
if(!oci_execute($rc)) {
return false;
//return oci_error($stmt);
}
$results = array();
while (($row = oci_fetch_array($rc, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
$results[] = $row;
}
oci_free_statement($stmt);
oci_free_statement($rc);
return $results;
}
}