note 110576 added to function.oci-new-cursor
| From: | mgumiel at mgait dot com | Date: | Thu, 08 Nov 2012 21:15:20 +0000 |
| Subject: | note 110576 added to function.oci-new-cursor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191814@lists.php.net to get a copy of this message | ||
Some packages in oracle are functions, and that functions returns a cursor.
For example:
CREATE FUNCTION F_Function( p1 char(2), p2 int)
RETURN SYS_REFCURSOR
AS
my_cursor SYS_REFCURSOR;
BEGIN
OPEN my_cursor FOR SELECT * FROM allitems
WHERE (cod=p1)
AND (Number=p2);
RETURN my_cursor;
END F_Function;
Here is the code that allows to obtain data from a function that returns a cursor.
<pre>
<?php
$conn=oci_connect("server", "user", "pass");
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message']), E_USER_ERROR);
}
//You must asign before.
$p1 = '03';
$p2 = 2012016191;
$stid = oci_parse($conn, 'begin :cursor := server.PKG_package.F_Function(:p1,:p2);
end;');
$p_cursor = oci_new_cursor($conn);
//Send parameters variable value lenght
oci_bind_by_name($stid, ':p1', $p1,2);
oci_bind_by_name($stid, ':p2', $p2,10);
//Bind Cursor put -1
oci_bind_by_name($stid, ':cursor', $p_cursor, -1, OCI_B_CURSOR);
// Execute Statement
oci_execute($stid);
oci_execute($p_cursor, OCI_DEFAULT);
oci_fetch_all($p_cursor, $cursor, null, null, OCI_FETCHSTATEMENT_BY_ROW);
echo '<br>';
print_r($cursor);
?>
----
Server IP: 69.147.83.199
Probable Submitter: 200.87.231.37
----
Manual Page -- http://www.php.net/manual/en/function.oci-new-cursor.php
Edit -- https://master.php.net/note/edit/110576
Del: integrated -- https://master.php.net/note/delete/110576/integrated
Del: useless -- https://master.php.net/note/delete/110576/useless
Del: bad code -- https://master.php.net/note/delete/110576/bad+code
Del: spam -- https://master.php.net/note/delete/110576/spam
Del: non-english -- https://master.php.net/note/delete/110576/non-english
Del: in docs -- https://master.php.net/note/delete/110576/in+docs
Del: other reasons-- https://master.php.net/note/delete/110576
Reject -- https://master.php.net/note/reject/110576
Search -- https://master.php.net/manage/user-notes.php