in SQL Server I can create a procedure to receive a datatable as input instead of of primitive type, this way I can pass a list of values, like the example below.
--Create Type
CREATE TYPE dbo.NamesList
AS TABLE
(
fullName VARCHAR(50)
);
--Create Procedure
CREATE PROCEDURE dbo.DoSomethingWithNames
#List AS dbo.NamesList READONLY
AS
BEGIN
SET NOCOUNT ON;
SELECT fullName FROM #List;
END
--Example of SQL Call
--Set variable values
DECLARE #NL NamesList;
INSERT #NL VALUES ('Bill'),('Michael'),('Paul'),('William'),('Kate')
--Call procedure
Exec DoSomethingWithNames #NL
On IBM IIB I can call stored procedures with a code like this:
CREATE PROCEDURE GetFiles (IN idFile INTEGER)
LANGUAGE DATABASE
DYNAMIC RESULT SETS 1
EXTERNAL NAME "dbo.SP_S_FILE";
But I have no idea if it's possible to pass a datatable instead of primitive value and how to it. Any ideas?
Thanks
Have you looked at the PASTHRU statement? I haven't tried doing what you're asking before, but the documentation sounds promising (assuming the limitations don't prevent you from using it).
PASSTHRU can still be used to call stored procedures if:
Only input parameters can be used.
Only single result sets are supported.
If you don't meet these criteria, use the CALL statement because PASSTHRU
imposes limitations (you cannot use output parameters, for example).
Related
I try to use variable in the alias.
Is it possible not to change to dynamic SQL???
For example
get_this_year --> this is the function call this year, so 2018.
CREATE OR REPLACE PROCEDURE do_activity
v_cur_year VARCHAR2(11);
BEGIN
v_cur_year := get_this_year;
select t.1 AS v_cur_year -- I wanna use in here
FROM table1
END do_activity
how can I use Variable as alias.
Thanks
What you are asking for is not possible.
The column list, names, structure, etc. has to be known, when the query is parsed. Queries within PL/SQL are parsed, when PL/SQL code is parsed/compiled, so in your case, on procedure creation. (This obviously excludes dynamic queries, which are constructed in run-time, hence can't be parsed on PL/SQL compilation.)
You would have to use the dynamic SQL, to get the column name defined by the function result, but you already stated, that you do not want dynamic SQL.
There's a second issue with your code, although it may be a result of you simplifying the code. You are not capturing the query result in your procedure, which is obligatory in Oracle PL/SQL. You can't just run a query, and expect its result to be returned by running the procedure - it's not Transact-SQL. To return a data set from PL/SQL, you would have to write a tabular function (still, this would require stable data set structure, so no dynamic column naming) or you would have to use an OUT parameter of ref-cursor type.
I inherited an awesome 600 line Stored Procedure in which I need to debug. I'm trying to debug by right clicking on the name of the stored procedure, clicking execute using sql debugger. This brings up a table in which I can manually enter my parameters. Great. Except one of the parameters is a OracleArray vArray INPUT parameter, and I'm not sure how to actually enter something like this as a parameter? I'm not familiar with Oracle.
Your question doesn't have a lot of details, so I'll have to give a vague answer. Here's how you can call a procedure (named other_procedure) which takes a VARRAY argument or other complicated setup. Once you've declared a test procedure, you can execute it with the debugger and then step into the procedure you actually care about.
CREATE OR REPLACE PROCEDURE test_procedure IS
-- (size and type of the varray should match the one in other_procedure)
TYPE my_array_t IS VARRAY(4) OF VARCHAR2(20);
-- define and initialize your array
test_array my_array_t := my_array_t('one','two','three');
BEGIN
-- call the procedure
other_procedure(test_array);
END;
/
If you're still having trouble, edit your question to provide more details (like the procedure definition and varray definition) and we can give a more specific answer.
I am wondering whether it is possible to pass arbitrary number of VARCHAR parameters into PLSQL procedure/function. So far I have this
DECLARE
--TYPE thisType IS TABLE OF VARCHAR2(50);
var TypePack.thisType;
BEGIN
var:=TypePack.thisType('a','b','c');
L10B(TypePack.thisType('a','b'));
/****** OR ******/
L10B(var);
END;
L10B is SP which works with given parameter. What do I want to achieve is something like
L10B('string1','string2','string3',...,'stringX');
where X is not known in advance. Enter as many arguments as I want then take entered text (e.g. 'string2','string3') and before it is "given" to procedure convert it to that type.
The PLSQL compiler does not support arbitrary numbers of parameters. You can pass a VARRAY or associative array (index-by-table) into a function, giving you the option to pass lists of VARCHAR2.
I have a problem with calling a stored procedure from ABAP.
I use standard ABAP class cl_sql_statement and it's methods execute_procedure and set_param. Called procedure, for example, has a single Boolean input parameter.
CREATE OR REPLACE PROCEDURE print_boolean (
p_in_flag BOOLEAN
) IS
ABAP snippet
DATA: ld_e_bool type char5,
ld_o_stat type ref to cl_sql_statement,
ld_r_data type ref to data.
***************************
ld_e_bool = 'FALSE'.
get references of ld_e_bool into ld_r_data.
ld_o_stat->set_param(DATA_REF = ld_r_data).
ld_o_stat->execute_procedure( 'print_boolean' ).
********************************************
After the call I catch an exception which says something like: 'wrong number or types of arguments'. Maybe I need another type than char5... Any help would be appreciated.
Some observation:
The JDBC drivers do not support the passing of BOOLEAN parameters to PL/SQL stored procedures( suggest wrapping the PL/SQL procedure with a second PL/SQL procedure). But i dont want to use the above option becuase there are already lot of packages/SP's are available.
The Oracle documentation is unclear on how PL/SQL boolean values are actually represented. There is also a question that discusses the use of boolean types in Oracle database fields (not really relevant here, but provides some background).
From the PL/SQL documentation:
The BOOLEAN datatype takes no parameters. Only the values TRUE, FALSE, and NULL can be assigned to a BOOLEAN variable.
You cannot insert the values TRUE and FALSE into a database column. You cannot select or fetch column values into a BOOLEAN variable. Functions called from a SQL query cannot take any BOOLEAN parameters. Neither can built-in SQL functions such as TO_CHAR; to represent BOOLEAN values in output, you must use IF-THEN or CASE constructs to translate BOOLEAN values into some other type, such as 0 or 1, 'Y' or 'N', 'true' or 'false', and so on.
In light of that, and I know you don't want to, you may need to change the type of parameter you pass into the stored procedure (e.g., use a single character or integer) and then use logic to treat that as a boolean.
In SAP doc say:
Almost all SQL statements that are valid for the addressed database system can be included between EXEC and ENDEXEC
Maybe if i try put in this section native pl/sql code i get result...
Edit: I put this code snip and it's ok.
EXEC SQL.
BEGIN
print_boolean(TRUE);
END;
ENDEXEC.
But there is one problem. This sql statement have static form only.
I am using IBM message broker, v8.0.0.2. I am trying to call a stored procedure with 45 parameters, in and out. I use the Oracle jdbc driver (oracle.jdbc.OracleDriver). Turns out that I get an 'Invalid column index' SqlException, whenever I try to set the 45th IN or OUT parameter, which is weird. Is there such a limit?
Give Us the Code you've created and the Exception from the Exception list, by the way ,test the stored procedure using SQL Developer or any editor you are using then.. create procedure using ESQL and Call Database Stored Procedure.
CREATE PROCEDURE YourProcedureName(IN PARAM1 TYPE, IN PARAM2 TYPE,...,
OUT PARAM44 TYPE, INOUT PARAM45 TYPE)
LANGUAGE DATABASE DYNAMIC RESULT SETS 1 EXTERNAL NAME "ProcedureNameInDB";
In Main Function
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
--CopyMessageHeaders();
--CopyEntireMessage();
-- DECLARE HERE PARAMETERS FOR THE PROCEUDRE
-- In This Block Declare the 45 parameters for passing them in ESQL Procedure.
-- Then ESQL will pass them to Oracle Stored Procedure.
-- END DECLARE PARAMETERS FOR THE PROCEUDRE
-- Environment.DBRowSetResult: Storing Stored Procedure Output in Environment variable.
CALL YourProcedureName(param1, param2, .... param44,param45, Environment.DBRowSetResult);
END;