How to use cursor in php?

for example:
CURSOR CUR_ORDER IS
select distinct a.sales_branch segment2,a.order_number,
a.delivery_id,
a.sold_to_customer_id customer_id,
a.bill_to_customer_id,
a.ship_to_customer_id,
a.purchase_order,to_char(a.ordered_date,'yyyy-mm-dd') order_date
from vv_ar_temp_tl a;
how to use it in php program?

Hi,
I do not know what exactly is Your question about. I'll try to give an overview:
1. "CURSOR CUR_ORDER IS" is PL/SQL syntax, not PHP
2. result of oci_parse call is in fact a CURSOR, so I think You already know how to use it.
3. if Your question is on how to pass cursor between PL/SQL and PHP, I use:
a) PL/SQL procedure:
CREATE OR REPLACE
PROCEDURE TEST_P (PO_REF_CURSOR OUT SYS_REFCURSOR) AS
BEGIN
OPEN PO_REF_CURSOR FOR -- Opens ref cursor for query
SELECT OBJECT_NAME, OBJECT_TYPE FROM USER_OBJECTS WHERE ROWNUM <= 5;
END;
b) in PHP:
$conn = ocinlogon($database_user, $database_passwd, $database); // connect database
$outrefc = ocinewcursor($conn); //Declare cursor variable
$mycursor = ociparse ($conn, 'begin test_p(:curs); end;'); // prepare procedure call
ocibindbyname($mycursor, ':curs', $outrefc, -1, OCI_B_CURSOR); // bind procedure parameters
$ret = ociexecute($mycursor); // Execute function
$ret = ociexecute($outrefc); // Execute cursor
$nrows = ocifetchstatement($outrefc, $data); // fetch data from cursor
ocifreestatement($mycursor); // close procedure call
ocifreestatement($outrefc); // close cursor
ocilogoff($conn); // close database connection
var_dump($data); // show content fo $data variable
Now $data contains arrays of columns with arrays of rows from query.
Hope it helps You,
Regards,
Pawel

Similar Messages

  • How to use cursors in abap

    Hi,
        How to use cursor(sql Cursor) in abap program  could any one help me..
    Advance Thanks
    Regards
    Guhapriyan

    Hi Guhapriyan,
    Have a look at demo programs DEMO_SELECT_CURSOR_1, DEMO_SELECT_CURSOR_2 and DEMO_SELECT_CURSOR_3.
    Thanks
    Lakshman

  • How to use cursor function for nested xml

    Hi,
    i have a query for XMLQuery like
    select * from bills where bill_id=????
    it results in something like
    <bills>
    <bill>
    <city>london</city>
    <amount>44</amount>
    </bill>
    <bill>
    <city>london</city>
    <amount>988</amount>
    </bill>
    <bill>
    <city>new york</city> <amount>59</amount> </bill>
    </bills>
    but i want xml output to be sorted for city names adding one more level location like
    <bills>
    <location city="london">
    <bill>
    <amount>44</amount>
    </bill>
    <bill>
    <amount>988</amount> </bill>
    </location>
    <location city="new york">
    <bill>
    <amount>59</amount> </bill>
    </location>
    </bills>
    it should be possible to iterate through the same table to gather informaton with the help of cursor function, but never used CURSOR before.
    any idea?

    sreese wrote:
    p_desig works as a comma delimited string without the NVL function, that's not the issue.
    It IS the issue .. you need to provide  a SAMPLE so we can see what you're doing ..
    How are you "passing it in" ?
    option A:
    procedure ( in_var  in  VARCHAR2 )
    AS
    and nvl(sn.c_attribute1,'x@#$%') in nvl(in_var,'x@#$%')
    option B:
    and nvl(sn.c_attribute1,'x@#$%') in nvl(&1,'x@#$%')
    .. or some other method?

  • How to use Cursor Paramter

    Hi all,
    My query will written values by passing 5 parameter values.
    Now i want to use this query in plsql cursor, For that i need to use cursor parameter concepts and its very new to me. so pls any one help me how to use this cursor parameter to pass the values when i run my procedure.
    Regards
    Ajantha

    If you mean writing cursor with parameters you could try this way.
    CURSOR c1 (name VARCHAR2, salary NUMBER) IS SELECT ...
    --- open the cursor:
    OPEN c1(emp_name, 3000);
    Link for more info
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/06_ora.htm#36656
    Thanks

  • How to use cursors on Smith Chart?

    Hi everybody,
        Last 7 days , i was trying to point some markers on Smith chart.
    Please suggest any method to implement this. i want to mark some points on smith chart and get data.
    thank you,
    dg7318
    Solved!
    Go to Solution.

    thankyou nyc,
    I am seeing the demos.llb but nothing is mentioned about using cursors or markers. 
    I am plotiing impedance on smith chart. I want to put some markers on the chart. I also want to control the placement of those markers. I wish to get data (impedance and frequency) wherever the marker is positioned. 
    Again thanks for ur help.
    dg,
    the things that seems to be impossible first, after completion gives u real happiness..

  • How to use cursor data in more than one location in form?

    hi all.
    is it possible to make cursor as global or public in the form so i can use its data in more than location for testing like in buttons triggers.
    for example:
    if i declare the following cursor in "WHEN-NEW-FORM-INSTANCE" trigger
    CURSOR cur
    IS
    SELECT ID, NAME
    FROM PERSON;how can i use this cursor in other triggers in other buttons in the form?
    thanks

    kareem wrote:
    now i have the old data- from cursor and the new- from tableNo, you have not. When you open the cursor you get the state of the database at the current SCN.
    If you
    - open your cursor, fetch the data and close the cursor
    - update some data
    - open your cursor, fetch the data and close the cursor
    you will get the updated data from your cursor the second time (unless your update isn't a uncommited autonomous transaction but I wouldn't go down that route).
    You will have to save your data somewhere or you might take a look at flashback: http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/consist.htm#i20759
    cheers

  • How to use cursor data in more than one location in the form?

    hi all.
    is it possible to make cursor as global or public in the form so i can use its data in more than location for testing like in buttons triggers.
    for example:
    if i declare the following cursor in "WHEN-NEW-FORM-INSTANCE" trigger
    CURSOR cur
    IS
    SELECT ID, NAME
    FROM PERSON;how can i use this cursor in other triggers in other buttons in the form?
    thanks

    kareem wrote:
    now i have the old data- from cursor and the new- from tableNo, you have not. When you open the cursor you get the state of the database at the current SCN.
    If you
    - open your cursor, fetch the data and close the cursor
    - update some data
    - open your cursor, fetch the data and close the cursor
    you will get the updated data from your cursor the second time (unless your update isn't a uncommited autonomous transaction but I wouldn't go down that route).
    You will have to save your data somewhere or you might take a look at flashback: http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/consist.htm#i20759
    cheers

  • How to use Cursor's Fetch to return multiple column Data

    Hi ,
    This is my Table :
    SQL> select * from Login;
    USERNAME PASSWORD CONFIRMPASSWORD
    RAvi SAI SAI
    Kiran Keyboard Keyboard
    VARNU JAINA JAINA
    This is my stored Procedure , for that Table , this is working fine , where he Cursor's Fetch is returning only a Single column of Data .
    CREATE OR REPLACE PROCEDURE getEmpName(EMP_ID IN VARCHAR2)
    IS
    EMPNAME VARCHAR2(50);
    CURSOR MYCUR
    IS
    SELECT USERNAME from login where USERNAME=EMP_ID;
    BEGIN
    OPEN MYCUR ;
    LOOP
    FETCH MYCUR  INTO EMPNAME;
    DBMS_OUTPUT.PUT_LINE(EMPNAME);
    EXIT WHEN MYCUR%NOTFOUND;
    END LOOP;
    close MYCUR ;
    END;
    Now , I have a requirement as , i need to get the Password also along with Username ,
    Please tell me how can i use FETCH of Cursor to populate Details into the Declared Variables
    FETCH MYCUR  INTO EMPNAME;
    CREATE OR REPLACE PROCEDURE getEmpName(EMP_ID IN VARCHAR2)
    IS
    EMPNAME VARCHAR2(50);
    PASSWORD VARCHAR2(50);
    CURSOR MYCUR
    IS
    SELECT USERNAME , PASSWORD from login where USERNAME=EMP_ID;
    BEGIN
    OPEN MYCUR ;
    LOOP
    FETCH MYCUR  INTO EMPNAME; // Help needed here**
    DBMS_OUTPUT.PUT_LINE(EMPNAME);
    EXIT WHEN MYCUR%NOTFOUND;
    END LOOP;
    close MYCUR ;
    END;
    Edited by: user10503747 on Oct 14, 2010 11:51 AM
    Edited by: user10503747 on Oct 14, 2010 11:52 AM

    1) I'm hoping that this is a homework assignment. You would never, in the real world, store a password in clear text. And you would never, from a database design, have separate Password and ConfirmPassword columns.
    2) The INTO clause can accept a list of variables. So
    FETCH your_cursor_name INTO local_variable1, local_variable2;would be valid.
    3) You would generally want to avoid having local variables that share the name of a column-- that leads to some pretty serious confusion related to scoping. One common convention is to prefix local variables with a "l_".
    4) You would generally want local variables to inherit the type of the column rather than explicitly declaring the length of a string in your procedure. That way, if you change the table in the future, your code will continue to work.
    5) And finally, a procedure that just calls DBMS_OUTPUT would cause all sorts of red flags in reality. It would make far more sense for this to be a function that returns a value than a procedure that tries to write to a buffer that the client application may or may not have created.
    Justin

  • How to use saprfc_allow_start_program in PHP

    I'm trying to download documents from sap DMS using saprfc v1.4.1 in PHP.
    I call the bapi function BAPI_DOCUMENT_CHECKOUTVIEWX in order to download the document. However, after the script executes I'm getting the message "I::001 RFC partner does not allow to start the required p".
    I'm runnig the script on linux redhat and apache.
    PHP v5.1.6
    saprfc v1.4.1
    Here's a section of the code:
    //Discover interface for function module BAPI_DOCUMENT_CHECKOUTVIEWX
    $fce = saprfc_function_discover($rfc,"BAPI_DOCUMENT_CHECKOUTVIEWX");
    if (! $fce )
      echo "Discovering interface of function module failed";
      exit;
    //Set import parameters. You can use function saprfc_optional() to mark parameter as optional.
    saprfc_import ($fce,"GETCOMPONENTS","X");
    saprfc_import ($fce,"HOSTNAME","");
    saprfc_import ($fce,"ORIGINALPATH","/home/nawad");
    saprfc_import ($fce,"PF_FTP_DEST","");
    saprfc_import ($fce,"PF_HTTP_DEST","");
    //Fill internal tables
    saprfc_table_init ($fce,"COMPONENTS");
    saprfc_table_init ($fce,"DOCUMENTFILES_IN");
    saprfc_table_init ($fce,"DOCUMENTFILES_OUT");
    saprfc_table_init ($fce,"DOCUMENTS");
    saprfc_table_append ($fce,"DOCUMENTS", array ("DOCUMENTTYPE"=>"DRW","DOCUMENTNUMBER"=>"314304","DOCUMENTVERSION"=>"00","DOCUMENTPART"=>"000","DESCRIPTION"=>"","USERNAME"=>"","STATUSEXTERN"=>"","STATUSINTERN"=>"","STATUSLOG"=>"","LABORATORY"=>"","ECNUMBER"=>"","VALIDFROMDATE"=>"","REVLEVEL"=>"","DELETEINDICATOR"=>"","CADINDICATOR"=>"","STRUCTUREINDICATOR"=>"","PREDOCUMENTNUMBER"=>"","PREDOCUMENTVERSION"=>"","PREDOCUMENTPART"=>"","PREDOCUMENTTYPE"=>"","AUTHORITYGROUP"=>"","DOCFILE1"=>"","DATACARRIER1"=>"","WSAPPLICATION1"=>"","DOCFILE2"=>"","DATACARRIER2"=>"","WSAPPLICATION2"=>"","VRLDAT"=>"","USERDEFINED1"=>"","USERDEFINED2"=>"","USERDEFINED3"=>"","USERDEFINED4"=>"","SAVEDOCFILE1"=>"","SAVEDATACARRIER1"=>"","SAVEDOCFILE2"=>"","SAVEDATACARRIER2"=>"","CREATEDATE"=>"","REFDOCUMENTNUMBER"=>"","REFDOCUMENTPART"=>"","REFDOCUMENTVERSION"=>"","FILESIZE1"=>"","FILESIZE2"=>"","CMFIXED"=>"","CMRELEVANCE"=>""));
    saprfc_table_init ($fce,"WSAPPLICATION");
    //Do RFC call of function BAPI_DOCUMENT_CHECKOUTVIEWX, for handling exceptions use saprfc_exception()
      $rc = saprfc_allow_start_program ("/opt/SAPClients/SAPGUI7.10rev4/bin/sapftp");
    $rfc_rc = saprfc_call_and_receive ($fce);
    if ($rfc_rc != SAPRFC_OK) {
      if ($rfc == SAPRFC_EXCEPTION ) echo ("Exception raised: ".saprfc_exception($fce));
      else echo (saprfc_error($fce));
      exit;
    //Retrieve export parameters
    $RETURN = saprfc_export ($fce,"RETURN");
    print_r($RETURN);
    When I print $RETURN I see the message
    "I::001 RFC partner does not allow to start the required p"
    Anybody was successful downloading documents from sap DMS using PHP.
    Thanks

    Dear,
    If you want to use the code.
    first you can write your code in a subroutine in module pool program 1
    and then you can use it from module pool  program 2 by
    perform subroutine_name(program_name)
    using P_1
    changing C_1
    if you wan to use one module pool data into other module pool.
    so that is another requirement.

  • Using Cursor in Select statements? How to do this?

    I am getting an error whilt passing a cursor to a select clause:
    SELECT dbms_xmlquery.getXML('select deptno, dname, '||
    'cursor(select empno, ename, sal from emp e where e.deptno = d.deptno) employees '||
    'from dept d where d.deptno in (10, 20)')
    FROM dual;
    DBMS_XMLQUERY.GETXML('SELECTDEPTNO'||'CURSORIS(SELECTEMPNOFROMEMPEWHEREE.DEPT=D.
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00923
    : FROM keyword not found where expected
    </ERROR
    THIS IS DUE TO THE CURSOR AND ITS FROM STATEMENT?
    CAN ANY ONE PLEASE GUIDE AS TO HOW TO USE CURSORS IN A SELECT STATEMENT PLEASE?

    Another duplicate thread. See my response Select CLAUSE error using CURSORS & XSU.Please SEE..
    Cheers, APC

  • How to use PHP with SQL?

    how to use sql in php and output a new ERP table contains every order_number, every order_quantity and so on then ouput sum of company and then sum of area
    and so on.
    now i only know a little how to use sql in php and you can give some examples of this?

    This sounds like a nice little homework exercise.
    Check the PHP FAQs for Oracle/PHP help
    http://www.oracle.com/technology/tech/php/htdocs/php_faq.html
    http://www.oracle.com/technology/tech/php/htdocs/php_troubleshooting_faq.html
    For SQL help, check http://asktom.oracle.com/
    -- cj

  • How to create store procedure using cursor, and looping condition with exce

    Hi,
    I am new in pl/sql development , please help me for follwoing
    1. I have select query by joining few tables which returns lets say 100 records.
    2. I want to insert records into another table(lets say table name is tbl_sale).
    3. If first record is inserted into tbl_sale,and for next record if value is same as first then update into tbl_sale else
    insert new row
    4. I want to achieve this using store procedure.
    Please help me how to do looping,how to use cursor and all other necessary thing to achieve this.

    DECLARE
       b   NUMBER;
    BEGIN
       UPDATE tbl_sale
          SET a = b
        WHERE a = 1;
       IF SQL%ROWCOUNT = 0
       THEN
          INSERT INTO tbl_sale
                      (a
               VALUES (b
       END IF;
    END;note : handle exceptions where ever needed
    Regards,
    friend
    Edited by: most wanted!!!! on Mar 18, 2013 12:06 AM

  • How to use a session, created in a jsp page, in a php page

    Hello, forgive me for the newbie question.
    Here is my problem:
    I want to have a jsp page create a session, set some session variables and then redirect to a php page which will access those same session variables.
    I have the redirection worked out, but I can't seem to find out how to use the jsp session in my php script.
    Is this possible at all, and if so, how does it work?

    Note that javascript runs on the client side, and JSP runs on the server. JSP and the session objects are NOT available to javascript in reaction to the user.
    If this function is called only when the page is first created, not when the user interacts with the page, or if you want that value to be constant with respect to the javascript, then you can do this:
    <%
      String someValue = (String)session.getAttribute("theAttributeName");
    %>
    <script type="text/javascript">
         Calendar.setup({inputField:"f_date_dfFirstPmtDate",
                                              button:"f_trigger_dfFirstPmtDate",
                                             singleClick:true,
                                              ifFormat:<%=someVale%>});
    </script>

  • How to use a variable in a cursor?

    Hi,
    Is it possible to use a variable as condition for fetching data using cursors? The code works fine ( as shown) without using the clause 'where empno < 7600'. How can I use the variable 'stmt' in defining/fetching data by using cursor cur_1? My target is to get info for employee whose empno<7600. Any inputs would be appreciated.
    DECLARE
         STMT VARCHAR2(50) := 'EMPNO < 7600';
         CURSOR CUR_1 IS SELECT EMPNO, ENAME, JOB, MGR FROM EMP;
    BEGIN
         OPEN CUR_1;
         LOOP
              FETCH CUR_1 INTO :EMP.EMPNO, :EMP.ENAME, :EMP.JOB, :EMP.MGR;
              EXIT WHEN CUR_1%NOTFOUND;
              NEXT_RECORD;
         END LOOP;
         CLOSE CUR_1;
    END;

    Hi:
    You could use a CURSOR Parameter:
    DECLARE
    CURSOR CUR_1 (empno_in IN VARCHAR2) IS SELECT EMPNO, ENAME, JOB, MGR FROM EMP WHERE empno < empno_in;
    BEGIN
    OPEN CUR_1 (7600);
    LOOP
    FETCH CUR_1 INTO :EMP.EMPNO, :EMP.ENAME, :EMP.JOB, :EMP.MGR;
    EXIT WHEN CUR_1%NOTFOUND;
    END LOOP;
    CLOSE CUR_1;
    END;
    or a REF Cursor, like so:
    DECLARE
    TYPE CUR_1_TYPE IS REF CURSOR;
    CUR_1 CUR_1_TYPE;
    BEGIN
    OPEN CUR_1 FOR SELECT EMPNO, ENAME, JOB, MGR FROM EMP WHERE empno < 7600;
    LOOP
    FETCH CUR_1 INTO :EMP.EMPNO, :EMP.ENAME, :EMP.JOB, :EMP.MGR;
    EXIT WHEN CUR_1%NOTFOUND;
    END LOOP;
    CLOSE CUR_1;
    END;
    Note - these will run in SQL*Plus ... I believe you are using Oracle Forms as you had the NEXT_RECORD command in your example, and I had to remove it.

  • Please reply:how to avoid extra trailing spaces while using cursor sharing

    i am using cursor sharing with FORCE or SIMILAR.
    what is the solution to avoid extra trailing spaces without any java code change.
    do we have any option in oracle to avoid extra trailing spaces during the query processing ?
    I am using Oracle 10g
    CURSOR SHARING is a feature in which multiple sql statements
    which are same will have a shared cursor (in the library cache) for an oracle session,
    i.e, the first three steps of the sql processing (hard parse, soft parse, optimization)
    will be done only the first time that kind of statement is executed.
    There are two ways in which similar SQL statements with different condition values can be made to "SHARE" cursor during execution:
    1. Writing SQLs with Bind Variables: SQLs having no hard coded literals in them
    For e.g., the query below
    SELECT node.emp_name AS configid
    FROM emp node
    WHERE emp_no = :1
    AND dept_no =
    DECODE (SUBSTR (:2, 1, 3),
    :3, :4,
    (SELECT MAX (dept_no)
    FROM emp
    WHERE emp_no = :5 AND dept_no <= :6)
    AND node.dept_type = :7
    ORDER BY node.emp_name
    Here all the variables are dynamically bound during the execution. The ":X" represents BIND Variable and the actual values are bound to the SQL only at the 4th step of the execution of the SQL.
    In applications: The queries written with "?" as bind variables will be converted into ":X" and are sqls with Bind Variables.
    2. The CURSOR_SHARING parameter: Only Useful for SQL statements containing literals:
    For eg., the query below:
    SELECT node.emp_name AS configid
    FROM emp node
    WHERE emp_no = 'H200'
    AND dept_no =
    DECODE (SUBSTR (:1, 1, 3),
    'PLN', :2,
    (SELECT MAX (dept_no)
    FROM emp
    WHERE emp_no = :3 AND dept_no <= :4)
    AND node.dept_type = :5
    ORDER BY node.emp_name
    In the query above, there are two hard coded literals H200 , PLN. In this case when the same SQL executed with different values like (H2003 , PLN), oracle will create a new cursor for this statement and all the first three steps ( hard & soft parse and optimization plan) needs to be done again.
    This can be avoided by changing the CURSOR_SHARING parameter which can be set to any of three values:
    1. EXACT: Causes the mechanism not be used, i.e. no cursor sharing for statements with different literals. This is the default value.
    2. FORCE: Causes unconditional sharing of SQL statements that only differ in literals.
    3. SIMILAR: Causes cursor sharing to take place when this is known not to have any impact on optimization.
    So, FORCE and SIMILAR values of the parameter will be helping in cursor sharing and improve the performance of the SQLs having literals.
    But here the problem arises if we use the FORCE and SIMILAR other than EXACT.
    alter session set cursor_sharing ='EXACT'
    select 1 from dual;
    '1'
    1
    alter session set curson_sharing='FORCE'
    select 2 from dual;
    '2'
    2
    alter session set curson_sharing='SIMILAR'
    select 3 from dual;
    '3'
    3
    So, this will give extra trailing spaces in when we retrieve from java method and any
    further java processing based on the hardcoded literal values will fail. this needs lot of
    effort in remodifying the existing millions of lines of code.
    My question is i have to use cursor sharing with FORCE or SIMILAR and can't we do the trimming
    from the oracle query processing level ?
    please help me on this ?
    Message was edited by:
    Leeladhar
    Message was edited by:
    Leeladhar

    Please reply to this thread
    How to avoid extr trailing spaces using Cursor sharing opton FORCE, SIMILAR

Maybe you are looking for