Calling oracle procedures through zend framework - zend-db

I am calling a stored procedure that has 2 input parameters (id,name) and 2 output parameters (year, value) from a zend framework.
If the output parameters are of type NUMBER then I am able to bind and run the procedure.
But in my case the output parameters are of "TYPE" table. I have created the type like this:
CREATE OR REPLACE TYPE year IS TABLE OF NUMBER(4);
CREATE OR REPLACE TYPE value IS TABLE OF NUMBER(10,3);
I am calling the procedure in php like this:
$callProc = "CALL proc_name($idValue,$nameValue,:o_years,:o_value)";
$stmt = $this->_DB->prepare($callProc);
I am having problem in trying to bind the output variable o_years and o_value using bindParam() since it is a type and not string.

oci_new_cursor should help

Related

Manipulate with data returned by stored procedure

I have stored procedure in SAP HANA (let's call it testProcedure) which returns data (for example col1 | col2 | col3). Unfortunately I can't modify this stored procedure.
How can I manipulate (filter it etc.) with these data after procedure execution (currently I execute it with call testProcedure()?
I'm looking for something like select * from testProcedure() where col1 = 'hello'
What you’re describing works with a user defined table function, but not with a procedure.
If your procedure uses the default result set, then there’s no way to filter or otherwise process the result set. It will just be returned to HANA studio as is.
If the result set is returned via a output parameter you could assign it to a table variable and apply filters when selecting from that table variable.

SQL - stored procedure, pass field and table name parameters on execute

I created a SQL procedure that replaces all values in a field with Xs the same length as the original values.
Update Table
Set Name = Replicate('x', Len(Name))
I am trying to alter this procedure so that I can just pass a table and field name as a parameter on execute instead of editing the stored procedure every time I want to pass a new field. Is there a way to do this?
This is what I think the execute statements should look like when I want to x out the values in another field:
Exec MyProcedure ‘Users’, ‘Email’
You can use EXEC to execute sql statements like this: EXEC (#sqlCommand). SqlCommand would be the string composed by you based on the received parameters.
Also, another option would be to run the statement using sp_executesql.

Creating a table type param in SQL Server Stored Procedure

Is it possible to declare/create the table type param(TVP) in Stored Procedure itself instead of creating the table value type separately in the schema and then using it in Stored procedure. i.e.,
create procedure proc1(
#table1 table(id int) readonly
)
as
begin
select top 1 * from sysobjects
end
From MSDN:
Table-valued parameters are based on strongly-typed table structures
that are defined by using Transact-SQL CREATE TYPE statements. You
have to create a table type and define the structure in SQL Server
before you can use table-valued parameters in your client
applications.
So it is clearly said that you can't declare TVP in stored procedure like you want - only by creating as user-defined type.

Use Stored procedure like a function

I need to deal with the table name as a variable.Then I must using dynamic sql and therefore I must using Stored procedure.
But the problem that how can I use the stored procedure like a custom sql function.
e.g: select col1,(Exec sp1 param1,'tbName') from table1
Finally,I changed my design and and use dynamic SQL in one upper level.
This will be posible in sql server denali that introduces the new keywords "WITH RESULTSET".
The alternative on current sql versions is passing a temp-table to the stored procedure
Stored procedures can return scalar values through output parameters. Here's an example (from here).
Create the stored procedure like this:
CREATE PROCEDURE _4P_test
#intInput INT,
#intOutput INT OUTPUT
AS
SET #intOutput = #intInput + 1
Call it like this:
DECLARE #intResult INT
EXEC _4P_test 3, #intResult OUT
SELECT #intResult
However you should try to design your system so that you don't have to use dynamic SQL in the way you described.

Nested Create Type in Stored Procedure Declaration T-SQL

I am writing a SQL Stored Proc which takes in a single table valued parameter. Is it possible for me to create the table type in the parameter definition, for example:
CREATE PROCEDURE example (
#param (CREATE TYPE tableparameter ( column1 int, colunn2 varchar.... )) READONLY
)
No.
Databases will want the type to already exist before it can be specified as a parameter type, otherwise the database has no way to know if the data it is receiving is valid or not.