Oracle stored procedure in PHP fetching XML values
Hi,
I have the below table created in oracle
CREATE TABLE TEST_XML(
ID NUMBER(5),
DATA VARCHAR2(4000)
INSERT INTO TEST_XML VALUES(100,'<student><name>Ruck</name><id>1</id></student>');
I have created a procedure:
CREATE OR REPLACE PROCEDURE SP_TEST_XML
( ID IN NUMBER,
DATA OUT VARCHAR2
IS
-- local variables
v_ID NUMBER(5);
v_DATA VARCHAR2(4000);
BEGIN
v_ID := ID;
SELECT DATA
INTO v_DATA
FROM TEST_XML
WHERE ID = v_ID;
DATA := v_DATA;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
When i run the below block in sqlplus:
DECLARE
a VARCHAR2(4000);
BEGIN
SP_TEST_XML(100,a);
DBMS_OUTPUT.PUT_LINE('The value is: ' || a);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
I get the below output:
'The value is: <student><name>Ruck</name><id>1</id></student>
But i tried to call the same procedure and fetch the data value using below php code:
<?php
$conn = OCILogon("username", "password", "dbhost");
$sql = 'BEGIN SP_TEST_XML(:ID, :DATA); END;';
$stmt = OCIParse($conn,$sql);
//Bind the input parameters
$p = OCIBindByName($stmt,':ID',$ID,5);
// Bind the output parameter
$q = OCIBindByName($stmt,':DATA',$DATA,4000);
// Assign values to input parameters
$ID = 100;
OCIExecute($stmt);
echo " Data = $DATA <br>";
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
I get the following result : Ruck1
Why is the complete string not outputed?why are tags eliminated from output?
only the values are concatenated and returned?
Pls help me.
Thanks.
srinath.
Hi, I have the below table created in oracle
CREATE TABLE TEST_XML(
ID NUMBER(5),
DATA VARCHAR2(4000) );
INSERT INTO TEST_XML VALUES(100,'<student><name>Ruck</name><id>1</id></student>');
I have created a procedure:
CREATE OR REPLACE PROCEDURE SP_TEST_XML
( ID IN NUMBER, DATA OUT VARCHAR2 )
IS -- local variables v_ID NUMBER(5); v_DATA VARCHAR2(4000);
BEGIN
v_ID := ID;
SELECT DATA INTO v_DATA FROM TEST_XML WHERE ID = v_ID;
DATA := v_DATA;
EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(SQLERRM); END; /
When i run the below block in sqlplus:
DECLARE a VARCHAR2(4000);
BEGIN SP_TEST_XML(100,a);
DBMS_OUTPUT.PUT_LINE('The value is: ' || a);
EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(SQLERRM); END; /
I get the below output: 'The value is: <student><name>Ruck</name><id>1</id></student>
But i tried to call the same procedure and fetch the data value using below php code:
<?php $conn = OCILogon("username", "password", "dbhost");
$sql = 'BEGIN SP_TEST_XML(:ID, :DATA); END;';
$stmt = OCIParse($conn,$sql);
//Bind the input parameters $p = OCIBindByName($stmt,':ID',$ID,5);
// Bind the output parameter $q = OCIBindByName($stmt,':DATA',$DATA,4000);
// Assign values to input parameters $ID = 100;
OCIExecute($stmt); echo " Data = $DATA
"; OCIFreeStatement($stmt); OCILogoff($conn); ?>
I get the following result : Ruck1
Why is the complete string not outputed?why are tags eliminated from output? only the values are concatenated and returned? Pls help me. Thanks. srinath.
Similar Messages
-
How to execute oracle stored procedure through php as externally?
hi...
i am searching for the way that how to execute oracle stored procedure through web service, i am using php and mysql, i have some stored procedures in oracale database, i want to execute them, from php, means the database will be remain mysql, and the stored procedures of oracle will be executed externally...
Kind regards,
Wilayat.Ok, so first of all this is a kind of strange question. Since Oracle and MYSQL can happily live side by side.
Make sure you have the oracle client (instant or regular ) installed and OCI_8 is set up and working correctly in PHP. If it is, when you run the phpinfo() routine you will see oci_8 on there. IF PHP connects just fine from the command line yet apache wont connect check permissions and things like the LD_Library Path.
Then in php, right along with your MySQL statements run Oracle Statements eg:
<?php
$OraDB = oci_connect(name,pass,tnsname);
$MySQLdb = mysql_connect([parms]);
$oraQueryText = "begin sp_some_proc([some parms]); end;" ;
$mysqlQuery = " Some mysql Query";
$oraQuery = oci_parse($OraDB,$oraQueryText );
oci_execute($oraQuery);
mysql_execute([parms]);
?>
Use the standard fetch code to get data from either of them.
If you cannot and I mean absolutely cannot get an admin to link in OCI_8 then you still have recourse although it will be tedious as hell. PHP allows you to exec calls to the OS. You still MUST make sure the Oracle Client is installed and that sqlplus runs from the command line. You will more then likely have to have a shell script written to do this as well, but maybe not as I have never tried it with the exception of capturing the return value of sqlplus and you will have to dig into sqlplus to get it to send its results to a file you can then parse with php.
Good Luck! -
Oracle Stored Procedure Not Accepting Comma delimited values in database
I have a stored procedure which does the following, declares variables and assigns values retrieved from a parameter temp_table database to each variable, then it reads column headings from a master table. Using the variables assigned to each parameter from the temp_table as a filter, the rows from the MASTER TABLE are finally output by the procedure. The stored procedure works fine when dealing with single value string values passed from the parameter temp_table.
The problem comes in when multiple values are selected and stored in the database parameter field as a comma separated string, eg. A045, A012
So, the strored procedure has been modified to use a function to split the string into separate values: 'A045' and 'A012'. So that: A045, A012 from the database will be returned to the stored procedure variable as *('A045', 'A012')* . When testing the stored procedure using the static values *('A045', 'A012')* , data is returned.
eg. EMPLOYEE_MASTER.CODE IN ('*A045*', '*A012*') will return results
However, when *('A045', 'A012')* is dynamically concatenated from the function and assigned to variable:
paramCode := split_str(paramCode) with paramCode eventually being passed: *('A045', 'A012')*
to become:
EMPLOYEE_MASTER.CODE IN (paramCode)
then NO DATA is returned.
I am stuck and don't know what the problem is. If anyone has any ideas, please feel free to help. I have included the Actual Stored Procedure below for a better understanding.
--------------------------------------------- STORED PROCEDURE-------------------------------------------------------
create or replace
PROCEDURE GETEMPLOYEEDATA
( sesId IN VARCHAR2,
l_cursor in out sys_refcursor
) is
compCode varchar(200);
businessUnit varchar(200);
locCode varchar(200);
hrDeptID varchar(200);
glDept varchar(200); plat varchar(200);
deptFunc varchar(200); empType varchar(200);
unionCode varchar(200); jobCode varchar(200);
careerLvl varchar(200);
empStatus varchar(200);
zid varchar(200);
superID varchar(200);
counter varchar(200) ;
token_index number;
--v_errm VARCHAR2(256);
BEGIN
dbms_output.put_line('Start of BEGIN');
/* Counter to get number of Unique Employee ID based on valid Session ID */
select count(*) into counter from XXCCHRWEB.hr_web_sessionid_tmp where parameter_20=sesId;
open l_cursor for SELECT counter EMPLOYEE_ID, '' LAST_NAME,
'' FIRST_NAME from dual;
dbms_output.put_line('OPENING FIRST CURSOR');
/* If no valid session ID returned then error gently */
if counter=0 then
open l_cursor for SELECT '' EMPLOYEE_ID, '' LAST_NAME,
'' FIRST_NAME,'' MIDDLE_NAME,'' NAME,
'' EMPLOYEE_TYPE, '' COMPANY, '' COMPANY_DESCRIPTION,
'' BUSINESS_UNIT, '' BUSINESS_UNIT_DESCRIPTION, '' LOCATION,
'' LOCATION_NAME, '' HR_DEPARTMENT_ID,'' DEPARTMENT_NAME,
'' DEPARTMENT_FUNCTION, '' PLATFORM, '' JOB_CODE,
'' JOB_TITLE, '' BUSINESS_TITLE, '' MANAGER_LEVEL,
'' JOB_FUNCTION, '' GL_DEPARTMENT_ID, '' GL_OP_UNIT,
'' GL_RESPONSIBILITY_CENTER, '' HR_CHANNEL,'' FULL_OR_PART_TIME,
'' REGULAR_OR_TEMP, '' GRADE,'' UNION_CODE,
'' BARGAINING_UNIT, '' ANNUAL_RATE,'' HOURLY_RATE,
'' HIRE_DATE, '' BIRTH_DATE, '' REHIRE_DATE,
'' SERVICE_DATE, '' POSITION_NUMBER, '' REPORTS_TO,
'' REPORTS_TO_TITLE, '' SUPERVISOR_ID, '' SUPERVISOR_NAME,
'' LAN_ID from dual;
dbms_output.put_line('End of counter=0');
-- return;
end if;
/* read from hr_web_sessionid_tmp */
select
parameter_1,parameter_2, parameter_3, parameter_4,
parameter_5,parameter_6, parameter_7, parameter_8,
parameter_9,parameter_10, parameter_11, parameter_12,
parameter_13, parameter_14
into
compCode, businessUnit, locCode, hrDeptID,
glDept, plat, deptFunc, empType,
unionCode, jobCode, careerLvl, empStatus,
zid, superID
from
XXCCHRWEB.hr_web_sessionid_tmp
where
parameter_20= sesId;
/*Assigning All Value to NULL superID*/
IF superid is null then
superID:= 'All';
END IF;
jobCode:='('''|| get_token(jobCode, 1)||''')'||','||'('''|| get_token(jobCode, 2)||''')';
dbms_output.put_line('SELECTING PARAMETERS FROM TEMP TABLE WITH ROW COUNT : '||l_cursor%ROWCOUNT);
/* read from Employee Master */
open l_cursor for SELECT DISTINCT * FROM ( SELECT HR_EMPLOYEE_MASTER.EMPLOYEE_ID, HR_EMPLOYEE_MASTER.LAST_NAME,
HR_EMPLOYEE_MASTER.FIRST_NAME, HR_EMPLOYEE_MASTER.MIDDLE_NAME, HR_EMPLOYEE_MASTER.NAME,
HR_EMPLOYEE_MASTER.EMPLOYEE_TYPE, HR_EMPLOYEE_MASTER.COMPANY, HR_EMPLOYEE_MASTER.COMPANY_DESCRIPTION,
HR_EMPLOYEE_MASTER.BUSINESS_UNIT, HR_EMPLOYEE_MASTER.BUSINESS_UNIT_DESCRIPTION, HR_EMPLOYEE_MASTER.LOCATION,
HR_EMPLOYEE_MASTER.LOCATION_NAME, HR_EMPLOYEE_MASTER.HR_DEPARTMENT_ID, HR_EMPLOYEE_MASTER.DEPARTMENT_NAME,
HR_EMPLOYEE_MASTER.DEPARTMENT_FUNCTION, HR_EMPLOYEE_MASTER.PLATFORM, HR_EMPLOYEE_MASTER.JOB_CODE,
HR_EMPLOYEE_MASTER.JOB_TITLE, HR_EMPLOYEE_MASTER.BUSINESS_TITLE, HR_EMPLOYEE_MASTER.MANAGER_LEVEL,
HR_EMPLOYEE_MASTER.JOB_FUNCTION, HR_EMPLOYEE_MASTER.GL_DEPARTMENT_ID, HR_EMPLOYEE_MASTER.GL_OP_UNIT,
HR_EMPLOYEE_MASTER.GL_RESPONSIBILITY_CENTER, HR_EMPLOYEE_MASTER.HR_CHANNEL, HR_EMPLOYEE_MASTER.FULL_OR_PART_TIME,
HR_EMPLOYEE_MASTER.REGULAR_OR_TEMP, HR_EMPLOYEE_MASTER.GRADE, HR_EMPLOYEE_MASTER.UNION_CODE,
HR_EMPLOYEE_MASTER.BARGAINING_UNIT, HR_EMPLOYEE_MASTER.ANNUAL_RATE, HR_EMPLOYEE_MASTER.HOURLY_RATE,
HR_EMPLOYEE_MASTER.HIRE_DATE, HR_EMPLOYEE_MASTER .BIRTH_DATE, HR_EMPLOYEE_MASTER.REHIRE_DATE,
HR_EMPLOYEE_MASTER.SERVICE_DATE, HR_EMPLOYEE_MASTER.POSITION_NUMBER, HR_EMPLOYEE_MASTER.REPORTS_TO,
HR_EMPLOYEE_MASTER.REPORTS_TO_TITLE, HR_EMPLOYEE_MASTER.SUPERVISOR_ID, HR_EMPLOYEE_MASTER.SUPERVISOR_NAME, HR_EMPLOYEE_MASTER.GENDER,
HR_EMPLOYEE_MASTER_1.LAN_ID
FROM
(XXCCHR.HR_EMPLOYEE_MASTER HR_EMPLOYEE_MASTER_1
LEFT OUTER JOIN
XXCCHR.HR_DEPARTMENT_SECURITY HR_DEPARTMENT_SECURITY
ON
HR_EMPLOYEE_MASTER_1.EMPLOYEE_ID=HR_DEPARTMENT_SECURITY.EMPLOYEE_ID)
LEFT OUTER JOIN
XXCCHR.HR_EMPLOYEE_MASTER HR_EMPLOYEE_MASTER
ON
-- HR_DEPARTMENT_SECURITY.DEPARTMENT_SECURITY=HR_EMPLOYEE_MASTER.HR_DEPARTMENT_ID
(HR_DEPARTMENT_SECURITY.DEPARTMENT_SECURITY=HR_EMPLOYEE_MASTER.HR_DEPARTMENT_ID
or
HR_DEPARTMENT_SECURITY.DEPARTMENT_SECURITY in ('DPALL','DPCAG009'))
WHERE
HR_EMPLOYEE_MASTER_1.LAN_ID=upper(zid) and
(compCode = 'All' or HR_EMPLOYEE_MASTER.COMPANY IN compCode)
(jobCode = 'All' or HR_EMPLOYEE_MASTER.JOB_CODE IN (jobCode) ) ) ;
dbms_output.put_line('END OF SELECT for counter number : ' || counter ||' Cursor row count : '|| l_cursor%ROWCOUNT || ' with Job Code : ' || (jobCode));
dbms_output.put_line('Company Code is:' || compCode);
COMMIT;
dbms_output.put_line('Data has been Output with session id:' || sesId);
--delete from XXCCHRWEB.hr_web_sessionid_tmp where parameter_20= sesId;
dbms_output.put_line('Data should have been DELETED, please check the session temp table');
commit;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('AN EXCEPTION HAS BEEN CAUGHT for counter number : ' || counter ||' Cursor row count : '|| l_cursor%ROWCOUNT || ' from session id : ' || sesId);
dbms_output.put_line('The error code is ' || SQLERRM);
END GETEMPLOYEEDATA;
Edited by: user10384134 on Nov 4, 2009 8:37 AMThis seems to work for me:
define param="'ABC','XYZ'"; --- Set up a test in clause
--- Test data
with test as
(select 'ABC' fld from dual union all
select 'DEF' from dual union all
select 'PQR' from dual union all
select 'XYZ' from dual)
--- Query starts here.
select fld
from test,
table (sys.ODCIVarchar2List (¶m)) p
where fld = p.column_valueOr Using an actual "IN" clause:
define param="'ABC','XYZ'";
with test as
(select 'ABC' fld from dual union all
select 'DEF' from dual union all
select 'PQR' from dual union all
select 'XYZ' from dual
p as
(select column_value from table (sys.ODCIVarchar2List (¶m))
select fld
from test
where fld in (select column_value from p)Edited by: AlanWms on Nov 4, 2009 9:08 AM -
Help : How can i call oracle stored procedure in PHP
i have following stored procedure and i want to call it in PHP.
pls give me syntax how can i call it.
Create or Replace Procedure Insert_profilebasicdetail
p_isubprofileid IN NUMBER,
p_Copyisubprofileid IN NUMBER,
p_itranno IN NUMBER,
As
v_IncKeyID NUMBER;
v_tempkeyId NUMBER;
CURSOR TempInsert IS
SELECT ikeyid,iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,iyear,isubprofileid
FROM profilebasicdetail
WHERE isubprofileid=p_Copyisubprofileid and itranno=p_itranno;
BEGIN
SELECT MAX(NVL(iKeyID,0))
INTO v_IncKeyID
FROM profilebasicdetail;
FOR r in TempInsert LOOP
v_IncKeyID := v_IncKeyID + 1;
Insert into profilebasicdetail
(ikeyid,iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,itranno,iyear,isubprofileid)
select v_IncKeyID,r.iprofileid,r.iquestionid,r.vquestionans,
r.cstatusindi,r.dmodifyon,r.imodifyby,1,
r.iyear,p_isubprofileid
from profilebasicdetail
where ikeyId=r.ikeyId;
END LOOP;
EXCEPTION
WHEN others THEN
raise;
End;
Thanks
allHi, your SP have an error in the sentence "p_itranno IN NUMBER,)"... the comma is the error.
In order to use the SP from PHP you have write...
<?php
$sth = oci_parse($dbh, "begin Insert_profilebasicdetail (:isubprofileid , :copyisubprofileid, :itranno); end;"
oci_bind_by_name($sth, ": isubprofileid ", $youparameter1);
oci_bind_by_name($sth, ": copyisubprofileid", $youparameter2);
oci_bind_by_name($sth, ": itranno", $youparameter2);
oci_execute($sth);
?> -
Not able to get Oracle stored procedure return value passed to Powerbuilder
I have an Oracle Stored Procedure that receives a string value and returns a string value.. When I call it from Powerbuilder, it executes but does not send the return value of a string back. I am trying to encrypt a string in Powerbuilder, pass it to a .net web page and then decrypt so I can check the security tables for permissions to view the web page. I have tried creating a simple stored procedure that takes a string and returns a string to Powerbuilder; but even that is not working. Any suggesstions?
Oracle Procedure:
CREATE OR REPLACE
PROCEDURE TESTINOUT_VARCHAR
( P_STRING IN VARCHAR2, P_OUT OUT VARCHAR2)
IS
BEGIN
P_OUT := P_STRING || 'TESTING';
END TESTINOUT_VARCHAR;
Powerbuilder Call:
string p_string =' '
Declare TestingString procedure for TESTINOUT_VARCHAR(:ls_group, :p_out) using SQLCA
Execute TestingString;
IF SQLCA.CODE = 0 THEN
FETCH TestingString into:p_out;
End If
p_string = p_out;Hello John,
I'm not sure if you already found a solution using an ODBC connection.
Below the solution with an RPC call:
Create a user object (uo_trans) of type transaction with the following local external function:
subroutine TESTINOUT_VARCHAR(string P_STRING,ref string P_OUT) RPCFUNC
Execute this script
uo_trans l_transaction
string ls_outparam
l_transaction = CREATE uo_trans
// Profile ODBC_ORA
l_transaction.DBMS = "ODBC"
l_transaction.AutoCommit = False
l_transaction.DBParm = "ConnectString='DSN=ODBC_ORA;UID=system;PWD=<xxxxxx>'"
connect using l_transaction;
ls_outparam = space (30)
l_transaction.testinout_varchar( sle_1.text, ls_outparam)
messagebox("OUT parameter", ls_outparam)
disconnect using l_transaction;
DESTROY l_transaction -
Sending '?' in XML tag to Oracle Stored Procedure
I have a situation that I cannot find the answer to why it is happening.
I am sending an XML data type to an oracle stored procedure. In one of the fields, I need to allow the '?' character to be sent.
<ADDITIONALINFO>This is where I want ? to be</ADDITIONALINFO>
When I send the info to the stored procedure I get the following error: ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing
LPX-00216: invalid character 191 (0xBF)Error at line 19
What I do not understand is that the character (0xBF) is the inverted question mark �
I have been able to get around the issue by changing the question mark to ? which is the decimal format for the question mark and the query works.
ie: <ADDITIONALINFO>This is where I want ? to be</ADDITIONALINFO>
Is there another delimiter that is needed for '?' like what is needed to print the & in & fashion?
Any insight to this issue would be helpful.There are some characters that you cannot use in an XML document, but I was not aware that the questionmark was one of them. As far as I know, you need to transform the characters '&', '<' and '>', and any character with a code higher than 127. The fact that the question mark is turned into an upside down questionmark seems to be some weird functionality.
-
How in ColdFusion with in variables get a Oracle stored procedure to return values?
How in ColdFusion with in variables get a Oracle stored procedure to return values?
We have tried several things, we can get a stored procedure to return a result set if we are not passing in variables but we cannot get them when we are passing in variables.
We know how to do it calling MS SQL.
Thanks for any help,
Nathan Sr
P.S. we have heard this may not be possible with the current Oracle Driver is there a different Oracle driver?I can only barely understand what you're asking here (not from a technical perspective, but from understanding your written English), but I suspect you're wanting to know how to pass back values other than recordsets from Oracle?
You should be able to pass them back via a type=out proc param, shouldn't you?
If you could reword your post so it's a bit more coherent, and possibly post some code, that might help.
Adam -
Calling stored procedure from php script.
I have the following stored procedure in Oracle 8:
CREATE OR REPLACE procedure kunde_create
(iname1 in varchar2,
iname2 in varchar2,
iname3 in varchar2,
ianrede in number,
istrasse in varchar2,
iland varchar2,
iplz in varchar2,
iort in varchar2,
iortsteil in varchar2,
itelefon in varchar2,
iemail in varchar2,
itelefax in varchar2,
imobil in varchar2,
ianrufer in varchar2,
izusinfo in varchar2,
izusatz2 in varchar2,
okdnr out varchar2)
is
vkndnr number;
vadrnr number;
vkdnr varchar2(15);
ikugru constant number:=4;
minkdnr constant varchar2(15):='44000000';
maxkdnr constant varchar2(15):='50000000';
begin
..... SOME CODE ....
okdnr:='something_to_output';
commit;
end kunde_create;
I am trying to call this SP from a php script, in this way:
$connection = ora_logon("username@db", "password");
$cursor = ora_open($connection);
ora_commitoff($connection);
$cu=ora_parse($cursor, "begin KW.kunde_create ( :Sta_nameD, :Sta_name2D, :Sta_kugruD, :ianredeD, :Sta_straD, :Sta_landD, :Sta_plzD, :Sta_ortD, :Sta_ortsteilD, :Sta_telD, :Sta_mailD, :Sta_faxD, :Sta_tel2D, :Sta_anruD, :Sta_zusD, :Sta_zus2D ,:okdnr); end;");
ora_bind($cursor, ":Sta_nameD", $Sta_nameD, 32, 1);
ora_bind($cursor, ":Sta_name2D", $Sta_name2D, 32, 1);
ora_bind($cursor, ":ianredeD", $ianredeD, 32, 1);
ora_bind($cursor, ":Sta_straD", $Sta_straD, 32, 1);
ora_bind($cursor, ":Sta_landD", $Sta_landD, 32, 1);
ora_bind($cursor, ":Sta_plzD", $Sta_plzD, 32, 1);
ora_bind($cursor, ":Sta_ortD", $Sta_ortD, 32, 1);
ora_bind($cursor, ":Sta_ortsteilD", $Sta_ortsteilD, 32, 1);
ora_bind($cursor, ":Sta_telD", $Sta_telD, 32, 1);
ora_bind($cursor, ":Sta_mailD", $Sta_mailD, 32, 1);
ora_bind($cursor, ":Sta_faxD", $Sta_faxD, 32, 1);
ora_bind($cursor, ":Sta_tel2D", $Sta_tel2D, 32, 1);
ora_bind($cursor, ":Sta_anruD", $Sta_anruD, 32, 1);
ora_bind($cursor, ":Sta_zusD", $Sta_zusD, 32, 1);
ora_bind($cursor, ":Sta_zus2D", $Sta_zus2D, 32, 1);
ora_bind($cursor, ":okdnr", $okdnr, 32, 2);
ora_exec($cursor); //Line 93
This code brings me back this error:
Warning: Can't find variable for parameter in /www/vaillant/htdocs/www_tisweb/html/php/testdb/connect.php on line 93
I tried nearlly everything, but it doesnt work :(
Can anybody help me please.
Thanx in advance,
Ahmed AdailehI had to make a few modifications to get your example to work. The
biggest change was to the ora_bind syntax. I also found I had to
define a variable to hold the OUT value before doing the ora_exec.
Otherwise I got the error you saw. I'm not sure why defining it first
is necessary. I didn't dig deeply into PHP's oracle.c code.
My final script is below. It displays "okdnr is something_to_output".
I tested using PHP 4.3.3 against Oracle 9.2.
The best general suggestion I can make is to use PHP's oci8 driver
unless you need to be compatible with existing PHP code. There is an
example of using OUT binds in oci8 to call a stored procedure at
PHP and serveroutput
-- CJ
<?php
// Changed connection details to suit my environment
$connection = ora_logon("scott@MYDB", "tiger");
$cursor = ora_open($connection);
ora_commitoff($connection);
// Changed schema to SCOTT to match who I'd created the procedure as
$cu=ora_parse($cursor, "begin SCOTT.kunde_create ( :Sta_nameD, :Sta_name2D, :Sta_kugruD, :ianredeD, :Sta_straD, :Sta_landD, :Sta_plzD, :Sta_ortD, :Sta_ortsteilD, :Sta_telD, :Sta_mailD, :Sta_faxD, :Sta_tel2D, :Sta_anruD, :Sta_zusD, :Sta_zus2D ,:okdnr); end;");
// Allocated the IN parameter variables
$Sta_nameD = 'a';
$Sta_name2D = 'a';
$ianredeD = 1;
$Sta_straD = 'a';
$Sta_landD = 'a';
$Sta_plzD = 'a';
$Sta_ortD = 'a';
$Sta_ortsteilD = 'a';
$Sta_telD = 'a';
$Sta_mailD = 'a';
$Sta_faxD = 'a';
$Sta_tel2D = 'a';
$Sta_anruD = 'a';
$Sta_zusD = 'a';
$Sta_zus2D = 'a';
$Sta_kugruD = 'a';
// Changed ora_bind syntax to match
// http://www.php.net/manual/en/function.ora-bind.php
ora_bind($cursor, "Sta_nameD", ":Sta_nameD", 32, 1);
ora_bind($cursor, "Sta_name2D", ":Sta_name2D", 32, 1);
// Change ianredeD type to 2 to match procedure definition
ora_bind($cursor, "ianredeD", ":ianredeD", 32, 2);
ora_bind($cursor, "Sta_straD", ":Sta_straD", 32, 1);
ora_bind($cursor, "Sta_landD", ":Sta_landD", 32, 1);
ora_bind($cursor, "Sta_plzD", ":Sta_plzD", 32, 1);
ora_bind($cursor, "Sta_ortD", ":Sta_ortD", 32, 1);
ora_bind($cursor, "Sta_ortsteilD", ":Sta_ortsteilD", 32, 1);
ora_bind($cursor, "Sta_telD", ":Sta_telD", 32, 1);
ora_bind($cursor, "Sta_mailD", ":Sta_mailD", 32, 1);
ora_bind($cursor, "Sta_faxD", ":Sta_faxD", 32, 1);
ora_bind($cursor, "Sta_tel2D", ":Sta_tel2D", 32, 1);
ora_bind($cursor, "Sta_anruD", ":Sta_anruD", 32, 1);
ora_bind($cursor, "Sta_zusD", ":Sta_zusD", 32, 1);
ora_bind($cursor, "Sta_zus2D", ":Sta_zus2D", 32, 1);
// Changed okdnr type to 1 to match procedure definition
ora_bind($cursor, "okdnr", ":okdnr", 32, 1);
// Bound missing parameter
ora_bind($cursor, "Sta_kugruD", ":Sta_kugruD", 32, 1);
// Preallocated the output variable - I'm not sure why this is
// necessary nor what size is needed.
// When this line is commented out I get:
// Warning: Can't find variable for parameter in test01.php on line XX
$okdnr = "a";
ora_exec($cursor);
print "okdnr is $okdnr";
?> -
BO v5.1 - creating a report from an oracle stored procedure
Post Author: newrochelle
CA Forum: Publishing
hi to all,
im using BO 5.1 and i need to create a document from an oracle stored procedure that have only one IN parameter and ten OUT parameters.
Creating the new report I selected the database connection then I choose the stored procedure name from the list, I inserted the value for the IN parameter and finally I click on Run button.
I got the following error message:
ORA-06550: line 1, column 38: :PLS-00103: Encountered the symbol
"," when expecting one of the following: : : ( - + case mod
new not null others <an identifier> : <a double-quoted
delimited-identifier> <a bind variable> avg : count current
exists max min prior sql stddev sum variance : execute forall
merge time timestamp interval date : <a string literal with
character set specification> : <a number> <a single-quoted SQL
string> pipe : <an alternatively-quoted string literal with
character set specification> : <an alternatively-q :-6550
it seems to be caused by the OUT parameters!
i leaved them without any value.
it's the first time that I used a stored procedure to create a BO report, but I think the OUT parameters are needed to do that, otherwise what data will be presented in the report???
can you help me?
please answear me ASAP.
Thank's in advance
Regards
AndreaPost Author: synapsevampire
CA Forum: Publishing
Try posting in a BO forum, this is Crystal Reports.
-k -
Not able to retrive the recordset from oracle stored procedure in VC++
Hi,
I am trying to retrieve the records from the reference cursor which is an out parameter for an oracle 9i store procedure in VC++ application. But it is giving the record count as -1 always. Meanwhile i am able to get the required output in VB application from the same oracle 9i store procedure .
Find the code below which i used.
Thanks,
Shenba
//// Oracle Stored Procedure
<PRE lang=sql>CREATE OR REPLACE
PROCEDURE GetEmpRS1 (p_recordset1 OUT SYS_REFCURSOR,
p_recordset2 OUT SYS_REFCURSOR,
PARAM IN STRING) AS
BEGIN
OPEN p_recordset1 FOR
SELECT RET1
FROM MYTABLE
WHERE LOOKUPVALUE > PARAM;
OPEN p_recordset2 FOR
SELECT RET2
FROM MYTABLE
WHERE LOOKUPVALUE >= PARAM;
END GetEmpRS1;</PRE>
///// VC++ code
<PRE lang=c++ id=pre1 style="MARGIN-TOP: 0px">ConnectionPtr mpConn;
_RecordsetPtr pRecordset;
_CommandPtr pCommand;
_ParameterPtr pParam1;
//We will use pParam1 for the sole input parameter.
//NOTE: We must not append (hence need not create)
//the REF CURSOR parameters. If your stored proc has
//normal OUT parameters that are not REF CURSORS, you need
//to create and append them too. But not the REF CURSOR ones!
//Hardcoding the value of i/p paramter in this example...
variantt vt;
vt.SetString("2");
m_pConn.CreateInstance (__uuidof (Connection));
pCommand.CreateInstance (__uuidof (Command));
//NOTE the "PLSQLRSet=1" part in
//the connection string. You can either
//do that or can set the property separately using
//pCommand->Properties->GetItem("PLSQLRSet")->Value = true;
//But beware if you are not working with ORACLE, trying to GetItem()
//a property that does not exist
//will throw the adErrItemNotFound exception.
m_pConn->Open (
bstrt ("Provider=OraOLEDB.Oracle;PLSQLRSet=1;Data Source=XXX"),
bstrt ("CP"), bstrt ("CP"), adModeUnknown);
pCommand->ActiveConnection = m_pConn;
pParam1 = pCommand->CreateParameter( bstrt ("pParam1"),
adSmallInt,adParamInput, sizeof(int),( VARIANT ) vt);
pCommand->Parameters->Append(pParam1);
pRecordset.CreateInstance (__uuidof (Recordset));
//NOTE: We need to specify the stored procedure name as COMMANDTEXT
//with proper ODBC escape sequence.
//If we assign COMMANDTYPE to adCmdStoredProc and COMMANDTEXT
//to stored procedure name, it will not work in this case.
//NOTE that in the escape sequence, the number '?'-s correspond to the
//number of parameters that are NOT REF CURSORS.
pCommand->CommandText = "{CALL GetEmpRS1(?)}";
//NOTE the options set for Execute. It did not work with most other
//combinations. Note that we are using a _RecordsetPtr object
//to trap the return value of Execute call. That single _RecordsetPtr
//object will contain ALL the REF CURSOR outputs as adjacent recordsets.
pRecordset = pCommand->Execute(NULL, NULL,
adCmdStoredProc | adCmdUnspecified );
//After this, traverse the pRecordset object to retrieve all
//the adjacent recordsets. They will be in the order of the
//REF CURSOR parameters of the stored procedure. In this example,
//there will be 2 recordsets, as there were 2 REF CURSOR OUT params.
while( pRecordset !=NULL ) )
while( !pRecordset->GetadoEOF() )
//traverse through all the records of current recordset...
long lngRec = 0;
pRecordset = pRecordset->NextRecordset((VARIANT *)lngRec);
//Error handling and cleanup code (like closing recordset/ connection)
//etc are not shown here.</PRE>It can be linked to internal conversion. In some case, the value of internal or extranal value is not the same.
When you run SE16 (or transaction N), you have in option mode the possibility to use the exit conversion or not.
Christophe -
Calling a Oracle stored procedure in orchestrator
I am trying to execute a stored procedure using the query database IP in orchestrator. I can select data from the oracle db so i know the prereqs are setup correctly but it fails on executing the stored procedure.
The syntaxe is execute SPNAME('PARAM!','PARAM2')
The error is
Failed, Oracle failure Database error has occurred. ORA-00900: invalid SQL statement
Oracle query failure, please verify your query syntax is correct. Verify correct table names and column names etc...
The SP works fine in sql developer so im pretty sure the syntax is correct unless the Query Database IP needs a different syntax to work.simple as that. i actually tried something similar since that is how SCOM executes SP but left the execute command in there so it failed and i moved on. thanks for the reply.
Just for reference i went the powershell route and that worked as well but much more complicated then your solution. for anyone that wants to know the script is
$asm = [System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient")
$connectionString = "Data Source=TNSNAME;uid=USERID;pwd=PASSWORD";
$inputString1 = "PARAMETER INPUT 1";
$inputString2 = "PARAMETER INPUT 2"
$oracleConnection = new-object System.Data.OracleClient.OracleConnection($connectionString);
$cmd = new-object System.Data.OracleClient.OracleCommand;
$cmd.Connection = $oracleConnection;
$cmd.CommandText = "SP NAME";
$cmd.CommandType = [System.Data.CommandType]::StoredProcedure;
$cmd.Parameters.Add("NAME OF EXPECTED PARAMETER 1", [System.Data.OracleClient.OracleType]::NUMBER) | out-null;
$cmd.Parameters["NAME OF EXPECTED PARAMETER 1"].Direction = [System.Data.ParameterDirection]::Input;
$cmd.Parameters["NAME OF EXPECTED PARAMETER 1"].Value = $inputString1;
$cmd.Parameters.Add("NAME OF EXPECTED PARAMETER 2", [System.Data.OracleClient.OracleType]::VARCHAR2) | out-null;
$cmd.Parameters["NAME OF EXPECTED PARAMETER 2"].Direction = [System.Data.ParameterDirection]::Input;
$cmd.Parameters["NAME OF EXPECTED PARAMETER 2"].Value = $inputString2;
$oracleConnection.Open();
$cmd.ExecuteNonQuery() | out-null;
$oracleConnection.Close();
got help from http://dovetailsoftware.com/clarify/gsherman/2012/05/15/calling-oracle-stored-procedures-using-powershell/ -
Oracle Stored Procedure with out parameter
Good morning,
Is it possible to use an Oracle stored procedure with out parameters in MII ?
If yes, what is the manipulation to see the values of parameters Out?
Thank youMichael,
This is the MII query template :
DECLARE
STRCOMPTERENDU NVARCHAR2(200);
BEGIN
STRCOMPTERENDU := NULL;
XMII.SP_VALIDATEPROCESSORDERSLIST2 ( STRCOMPTERENDU => [Param.1] );
COMMIT;
END;
and the stocked procedure code
CREATE OR REPLACE PROCEDURE XMII.SP_ValidateProcessOrdersList2(strCompteRendu OUT nVarchar2) IS
tmpVar NUMBER;
debugmode INT;
strClauseSql varchar(2048);
strListPOactif varchar(1024);
dtmTimeStamp DATE;
NAME: SP_ValidateProcessOrdersList
PURPOSE:
REVISIONS:
Ver Date Author Description
1.0 18/06/2008 1. Created this procedure.
NOTES:
Automatically available Auto Replace Keywords:
Object Name: SP_ValidateProcessOrdersList
Sysdate: 18/06/2008
Date and Time: 18/06/2008, 18:45:32, and 18/06/2008 18:45:32
Username: (set in TOAD Options, Procedure Editor)
Table Name: (set in the "New PL/SQL Object" dialog)
BEGIN
tmpVar := 0;
debugmode := 0;
-- lecture date systeme pour time stamp
select sysdate into dtmTimeStamp from dual;
if debugmode = 1 then
DBMS_OUTPUT.put_line('SP_ValidateProcessOrdersList');
end if;
-- insertion du bloc dans le log
insert into LOG_ORDER
(DATE_ORDER,BLOCK_ORDER,ID_LOG_ORDER)
values
(dtmTimeStamp,'SP_ValidateProcessOrdersList',ID_LOG_ORDER.nextval);
Commit;
if debugmode = 1 then
DBMS_OUTPUT.put_line('insertion LOG OK');
end if;
strCompteRendu := '0123456-896;0123456-897';
commit;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
ROLLBACK;
-- insertion du bloc dans le log
insert into LOG_ORDER
(DATE_ORDER,BLOCK_ORDER,ID_LOG_ORDER)
values
(dtmTimeStamp,' ',ID_LOG_ORDER.nextval);
COMMIT;
-- Consider logging the error and then re-raise
RAISE;
END SP_ValidateProcessOrdersList2;
Thanks for your help
Alexandre -
Calling Oracle Stored procedure with OUT parameter from ODI
Hi,
I called an oracle stored procedure with following anonymous block in the ODI procedure.
Declare
Status varchar2(10);
Begin
OTM.DeleteTarget('E_KPI_TARGET_VALUE', Status);
End;
I want to capture the OUT parameter STATUS value in a project level variable.
And based on its va;lue I would like to choose between 2 interfaces in my package.
Please help me in doing this.Hi,
For that kind of situation I commoly use:
1) one step with:
create or replace package <%=odiRef.getSchemaName("W")%>.pck_var
Status varchar2(10);
end;
* transaction 9, for instance
2) step
Begin
OTM.DeleteTarget('E_KPI_TARGET_VALUE', <%=odiRef.getSchemaName("W")%>.pck_var.Status);
End;
* transaction 9
3) then, at an ODI variable, use a refresh like:
select <%=odiRef.getSchemaName("W")%>.pck_var.Status from dual
at same logical shema where the package was created.
Does it make sense to you? -
Call to Oracle stored procedure that returns ref cursor doesn't work
I'm trying to use an OData service operation with Entity Framework to call an Oracle stored procedure that takes an number as an input parameter and returns a ref cursor. The client is javascript so I'm using the rest console to test my endpoints. I have been able to successful call a regular Oracle stored procedure that takes a number parameter but doesn't return anything so I think I have the different component interactions correct. When I try calling the proc that has an ref cursor for the output I get the following an error "Invalid number or type of parameters". Here are my specifics:
App.config
<oracle.dataaccess.client>
<settings>
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursor.P_RESULTS" value="implicitRefCursor bindinfo='mode=Output'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.0" value="implicitRefCursor metadata='ColumnName=WINDFARM_ID;BaseColumnName=WINDFARM_ID;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Number;ProviderType=Int32'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.1" value="implicitRefCursor metadata='ColumnName=STARTTIME;BaseColumnName=STARTTIME;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.2" value="implicitRefCursor metadata='ColumnName=ENDTIME;BaseColumnName=ENDTIME;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.3" value="implicitRefCursor metadata='ColumnName=TURBINE_NUMBER;BaseColumnName=TURBINE_NUMBER;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.4" value="implicitRefCursor metadata='ColumnName=NOTES;BaseColumnName=NOTES;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.5" value="implicitRefCursor metadata='ColumnName=TECHNICIAN_NAME;BaseColumnName=TECHNICIAN_NAME;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYID.RefCursor.P_RESULTS" value="implicitRefCursor bindinfo='mode=Output'" />
</settings>
OData Service Operation:
public class OracleODataService : DataService<OracleEntities>
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("GetWorkOrdersByWindfarmId", ServiceOperationRights.All);
config.SetServiceOperationAccessRule("CreateWorkOrder", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
[WebGet]
public IQueryable<GetWorkOrdersByWindfarmId_Result> GetWorkOrdersByWindfarmId(int WindfarmId)
return this.CurrentDataSource.GetWorkOrdersByWindfarmId(WindfarmId).AsQueryable();
[WebGet]
public void CreateWorkOrder(int WindfarmId)
this.CurrentDataSource.CreateWorkOrder(WindfarmId);
Here is the stored procedure:
procedure GetWorkOrdersByWindFarmId(WINDFARMID IN NUMBER,
P_RESULTS OUT REF_CUR) is
begin
OPEN P_RESULTS FOR
select WINDFARM_ID,
STARTTIME,
ENDTIME,
TURBINE_NUMBER,
NOTES,
TECHNICIAN_NAME
from WORKORDERS
where WINDFARM_ID = WINDFARMID;
end GetWorkOrdersByWindFarmId;
I defined a function import for the stored procedure using the directions I found online by creating a new complex type. I don't know if I should be defining the input parameter, WindfarmId, in my app.config? If I should what would that format look like? I also don't know if I'm invoking the stored procedure correctly in my service operation? I'm testing everything through the rest console because the client consuming this information is written in javascript and expecting a json format. Any help is appreciated!
Edited by: 1001323 on Apr 20, 2013 8:04 AM
Edited by: jennyh on Apr 22, 2013 9:00 AMMaking the change you suggested still resulted in the same Oracle.DataAccess.Client.OracleException {"ORA-06550: line 1, column 8:\nPLS-00306: wrong number or types of arguments in call to 'GETWORKORDERSBYWINDFARMID'\nORA-06550: line 1, column 8:\nPL/SQL: Statement ignored"} System.Exception {Oracle.DataAccess.Client.OracleException}
I keep thinking it has to do with my oracle.dataaccess.client settings in App.Config because I don't actually put the WindfarmId and an input parameter. I tried a few different ways to do this but can't find the correct format. -
JDBC Sender - Oracle Stored procedures
hi all
i am working on JDBC sender - File receiver
I am fetching data from Oracle database
if i write select query directly in sender adapter the scenario is working properly but when try to write stored procedure in oracle and use execute statement in JDBC, adapter is throwing error.
As in oracle to fetch multiple rows i have to use cursors .
i read lot of articles in forum but still not clear on following issues :can any one solve them?
1 . To get multiple rows can i write SP without cursors?
2 . If SP is using cursor do my XI accept it or it only accepts resultset? in that case how to write sp.
thanks & regards
sheetalSheetal,
Adding to Jai Shankar's reply, Like pointed out, Oracle Stored Procedures return Cursors and XI sender JDBC adapter expects resultsets and so it is not possible to call Oracle SP's from Sender JDBC adapters.
But, I have also come across a few recent threads where there have been discussions that this is possible from SP 16 onwards. I have not been able to check and confirm on this, but, maybe you can check your SP level and see if you are below SP 16 . If yes, definetly not possible. If SP 16, or above, a Quick OSS to SAP should surely give the answer if it is possible or not!
Do let us know your findings.
Regards
Bhavesh
Maybe you are looking for
-
Installing photoshop cs2 onto macbook pro
I had the old version of photoshop cs2. I want to put it on my new macbook pro. I was given the link http://www.adobe.com/downloads/cs2_downloads/index.html". I have downloaded it but when I try to install the message says 'Installation failed. The i
-
Aperture won't switch to old library
I go to switch to my Aperture 1.5.6 library and it says that it needs to relaunch. But when it does so, I get a box asking if I want to create a new library which only gives me the option to create a new library or quit the program. I've tried creati
-
How can I get rich black onto only black plate
I do layout for an advertising magazine. Much of the content is received from others (the advertisers) and much of that is amatuer (created in Word, etc.). I place the ads into an ID (using CC) and export to PDF. My printer has me using a PDF/X-1a:20
-
How to create table with javascript and jquery in abap
Hello masters, i want to create table using javascript and jquery. i know how to use these languages but i dont how to implement them to abap. regards.
-
Installing fonts with In Design
Hi , I have installed new fonts on my computer. Then started to use them in In Design, all seemed good. Next time I went in the fonts were not there and not recognized. I went in and placed them into my computer fonts folder again. They were always i