How to retrieve multiple rows from a stored function with oracle

前端 未结 3 842
一个人的身影
一个人的身影 2021-01-06 07:43

I\'m trying to create a stored function in oracle that returns multiple rows.

My question is very similar to this one except that I want to fetch a select *

3条回答
  •  日久生厌
    2021-01-06 08:24

    If you are using PHP and you want to access a oracle stored function. You can make use of something like this

    //Your connection details
    $conn = oci_connect($username, $password, '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))' );
    
    /* Your query string; you can use oci_bind_by_name to bind parameters or just pass the variable in it*/
    
    $query = "begin :cur := functionName('".$param1."','".$param2."','".$param3."'); end;";
    $stid = oci_parse($conn, $query); 
    $OUTPUT_CUR = oci_new_cursor($conn);
    oci_bind_by_name($stid, ':cur', $OUTPUT_CUR, -1, OCI_B_CURSOR);
    oci_execute($stid); 
    oci_execute($OUTPUT_CUR);
    oci_fetch_all($OUTPUT_CUR, $res);
    
    // To get your result  
    var_dump($res);
    
    

    I hope this helps.

提交回复
热议问题