I have a bunch of sql queries stored in a column of an oracle database table. I have to retrieve one query at a time, execute it and display the results of this query on the front end. Here is the first query in the QUERY column.
select a.division_id, a.completion_id, a.num_of_stages, b.num_of_stages as numb, abs(a.num_of_stages - b.num_of_stages) as diff from odm_dba.odm_comp_summary a, (select division_id, completion_id, count(*) num_of_stages from odm_dba.odm_comp_stage group by division_id, completion_id) b where a.division_id = b.division_id and a.completion_id = b.completion_id and a.num_of_stages <> b.num_of_stages;
I executed this code in toad. It was working fine. No I am using the below code to retrieve the QUERY column and then execute it.
<?php
session_start();
ob_start();
require_once 'dbconnect.php';
$qry = "SELECT query FROM vdc_dba.queries";
$result = oci_parse($conn, $qry);
oci_execute($result);
$row = oci_fetch_array($result);
echo $row['QUERY'];
$new_result=oci_parse($conn,$row['QUERY']);
oci_execute($new_result);
$row1 = oci_fetch_array($new_result);
echo $row1['DIVISION_ID'];
?>
This is the output of the above query
" The actual query and then Warning: oci_execute(): ORA-00911: invalid character in C:\xampp\htdocs\query.php on line 13
Warning: oci_fetch_array(): ORA-24374: define not done before fetch or execute and fetch in C:\xampp\htdocs\query.php on line 14"
I am not sure how to use the result of a query as a query again. I am new to PHP, any help would be appreciated. Thanks