How to run this stored procedure - oracle

I have to check this procedure
im giving following values as parameters
34220, 2815,'7/20/2011', 32760, 100, 'PMNT_CHECK', 1, null, "", false, null, null
DECLARE
P_APP_ID NUMBER;
P_USER_ID NUMBER;
P_DATE DATE;
P_INV_IDS WB_PROD.WB_PCK_TYPES.T_IDS;
P_AMNTS WB_PROD.WB_PCK_TYPES.T_NUMBERS;
P_PMNT_METHOD VARCHAR2(15);
P_BANK_AC_FROM NUMBER;
P_CHECK_NUMBERS WB_PROD.WB_PCK_TYPES.T_NUMBERS;
P_MEMO VARCHAR2(1000);
P_PAY_MULTIPLE NUMBER;
P_CRD_IDS WB_PROD.WB_PCK_TYPES.T_IDS;
P_CRD_AMOUNTS WB_PROD.WB_PCK_TYPES.T_PRICES;
O_PY_ID NUMBER;
BEGIN
P_APP_ID := 34220;
P_USER_ID := 2815;
P_DATE := '7/20/2011';
-- Modify the code to initialize the variable
P_INV_IDS := 32760;
-- Modify the code to initialize the variable
P_AMNTS := 100;
P_PMNT_METHOD := 'PMNT_CHECK';
P_BANK_AC_FROM := 1;
-- Modify the code to initialize the variable
--P_CHECK_NUMBERS := NULL;
P_MEMO := '';
P_PAY_MULTIPLE := false;
-- Modify the code to initialize the variable
-- P_CRD_IDS := NULL;
-- Modify the code to initialize the variable
-- P_CRD_AMOUNTS := NULL;
WB_PCK_BILL_PAYMENTS.PAY_BILLS(
P_APP_ID => P_APP_ID,
P_USER_ID => P_USER_ID,
P_DATE => P_DATE,
P_INV_IDS => P_INV_IDS,
P_AMNTS => P_AMNTS,
P_PMNT_METHOD => P_PMNT_METHOD,
P_BANK_AC_FROM => P_BANK_AC_FROM,
P_CHECK_NUMBERS => P_CHECK_NUMBERS,
P_MEMO => P_MEMO,
P_PAY_MULTIPLE => P_PAY_MULTIPLE,
P_CRD_IDS => P_CRD_IDS,
P_CRD_AMOUNTS => P_CRD_AMOUNTS,
O_PY_ID => O_PY_ID
);
DBMS_OUTPUT.PUT_LINE('O_PY_ID = ' || O_PY_ID);
END;
Im getting error at this line
P_INV_IDS := 32760;
i checked type of
P_INV_IDS WB_PROD.WB_PCK_TYPES.T_IDS;
which is in Declare statement, which is like this
type t_ids is table of t_id
index by binary_integer;
I donot understand how to give parameter to this type. Please let me know how to give this parameter.
Thank you

P_INV_IDS is an associative array as per your type declaration.
you can not assign this way
P_INV_IDS := 32760;
you need to specify the index in P_INV_IDS to which you are assigning value
something like
P_INV_IDS(0) := 32760;
P_INV_IDS(1) := 32761;
http://www.java2s.com/Tutorial/Oracle/0520__Collections/AssignvaluetoPLSQLtable.htm

How is the TYPE t_id defined? That will dictate how you initialize this array. If it were a number, then you will want to initialize your value this way:
P_INV_IDS(1) := 32760;
If, however, t_id is defined as, say a RECORD:
TYPE t_id IS RECORD (
ID INTEGER;
DESCRIPTION VARCHAR2(32);
);
Then you might want to initialize thusly:
P_INV_IDS(1).id := 32760;
P_INV_IDS(1).description := 'Description for 32760';

Related

Comparing data of any type without overloading

let's start with an example:
type Collection_t is table of varchar2(3);
Collection_v Collection_t := Collection_t('qwe', 'asd', 'yxc', 'rtz', 'fgh', 'vbn');
single_var varchar2(3) := 'yxc';
procedure get_position(Single_Value varchar2, Value_Set Collection_t) is
i integer := 1;
begin
while (i is not null) loop
if Single_Value = Value_Set(i)
then
dbms_output.put_line(i);
end if;
i := Value_Set.Next(i);
end loop;
end;
begin
get_position(single_var, Collection_v);
end;
now, question is: can I declare this procedure with 'anydata', and check if table (2ed argument) consists of the same type as first argument.
I'd assume declaration of a procedure would look like that:
procedure get_position(Single_Value anydata, Value_Set anydata) is ...
later I'd compare types, and honestly I couldn't figure it out, how to solve this problem.
From my limited understanding, you still have to encode/decode anydata into basic (or user-defined) PL/SQL types to do anything meaningful like comparing values, so you might not gain the benefits of dynamic languages like Python.
Here is an example, passing anydata as a parameter. You'll need to update anydata_to_varchar to handle data types you need.
Personally, overloading seems like a more straightforward approach, unless there is a better way to work with anydata values.
declare
type tab_anydata is table of anydata;
-- test as varchar2
/*
lookup_array tab_anydata := tab_anydata(
anydata.convertVarchar2('blah'),
anydata.convertVarchar2('meh'),
anydata.convertVarchar2('foo'),
anydata.convertVarchar2('bar')
);
lookup_value anydata := anydata.convertVarchar2('foo');
*/
-- test as date
lookup_array tab_anydata := tab_anydata(
anydata.convertDate(trunc(sysdate - 2)),
anydata.convertDate(trunc(sysdate - 0)),
anydata.convertDate(trunc(sysdate + 1)),
anydata.convertDate(trunc(sysdate + 2))
);
lookup_value anydata := anydata.convertDate(trunc(sysdate));
function anydata_to_varchar(p_what anydata)
return varchar2
is
value_type varchar2(30) := anydata.GetTypeName(p_what);
result varchar2(32767);
begin
select
case value_type
when 'SYS.VARCHAR2' then anydata.AccessVarchar2(p_what)
when 'SYS.DATE' then to_char(anydata.AccessDate(p_what), 'YYYY-MM-DD')
when 'SYS.NUMBER' then to_char(anydata.AccessNumber(p_what))
else null
end into result
from dual;
return result;
end;
function get_position(p_what anydata, p_where tab_anydata)
return number
is
pos number := -1;
what_value varchar2(30) := anydata_to_varchar(p_what);
curr_value varchar2(30);
begin
for i in 1..p_where.count
loop
curr_value := anydata_to_varchar(p_where(i));
if what_value = curr_value then
pos := i;
exit;
end if;
end loop;
return pos;
end;
begin
dbms_output.put_line('lookup type : '||anydata.GetTypeName(lookup_value));
dbms_output.put_line('lookup value : '||anydata_to_varchar(lookup_value));
dbms_output.put_line('found position: '||get_position(lookup_value, lookup_array));
end;
/
dbms_output:
lookup type : SYS.DATE
lookup value : 2022-07-20
found position: 2
db<>fiddle here

Item Query From Table and Send It To Procedure

Note
I want to query page item name and send the corresponding items value into a procedure. I can get the item name but couldn't get the value of it. At first I use the following code:
begin
for j in (select item_name from UTLITMINF where service_id ='abc' ) loop
val := val || ':' || j.item_name; --items name
END LOOP;
/* exe := ' begin
dynamic_api_call(p_service => :ser,
p_par => :v_val, --items value to need to send
o_result_json => :v_l_response_text);
end; ';
execute immediate exe
using IN ser,
in val,
out l_response_text;*/
begin
dynamic_api_call(p_service => 'abc',
p_par => val, --items name from page queried from table and send its value to procedure
o_result_json => l_response_text);
end;
raise_application_error(-20001,l_response_text);
end;
In val parameter it contains P11_CUSTOMER. But the value of it did not pass through the procedure. How can I get the value of it? Suggest me if i need to improve my code.
You can use the V (short for value) and NV (short for numeric value) function for dynamic item names. Try something like this (you'll need to adjust on your end).
declare
l_response_text varchar2(255);
l_ser varchar2(255) := 'abc';
l_item_name varchar2(255);
begin
select item_name
into l_item_name
from UTLITMINF
where service_id = l_ser;
dynamic_api_call(
p_service => l_ser,
p_par => v(l_item_name),
o_result_json => l_response_text
);
end;
Try the dynamic sql like the below
begin
for j in (select item_name from UTLITMINF where service_id ='abc' ) loop
val := val || ':' || j.item_name; --items name
END LOOP;
exe := ' begin
dynamic_api_call(p_service => :ser,
p_par => :v_val, --items value to need to send
o_result_json => :v_l_response_text);
end ;';
execute immediate exe
using ser,
val,
OUT l_response_text;
raise_application_error(-20001,l_response_text);

Wrong number of arguments in call of a SP PL-SQL [duplicate]

Just calling this directly from the editor (Toad). No idea why getting the above error having checked the function definition and variable types repeatedly. All of the information available online seems to be for stored procedures - which I don't believe are used here
DECLARE
TYPE attrs_type is VARRAY(10) of STRING(10);
l_ldap_host VARCHAR(255) := 'SERVERNAME';
l_ldap_port INT := 389;
l_ldap_user VARCHAR(255) := 'USERNAME';
l_ldap_passwd VARCHAR(255) := 'PASSWORD';
l_ldap_base VARCHAR(255) := 'l=something,dc=something';
l_session DBMS_LDAP.session;
l_retval NUMBER;
l_entry VARCHAR(255);
l_attrs attrs_type;
l_message VARCHAR(255) := null;
l_filter VARCHAR(255) := 'objectclass=*';
BEGIN
l_session := DBMS_LDAP.init(hostname => l_ldap_host,
portnum => l_ldap_port);
l_retval := DBMS_LDAP.simple_bind_s(ld => l_session,
dn => l_ldap_user,
passwd => l_ldap_passwd);
l_attrs(1) := '*'; -- retrieve all attributes
l_retval := DBMS_LDAP.search_s(
ld => l_session,
base => l_ldap_base,
scope => DBMS_LDAP.SCOPE_SUBTREE,
filter => l_filter,
attrs => l_attrs,
attronly => 0,
res => l_message);
DBMS_OUTPUT.put_line(l_message);
-- code to do stuff
EXCEPTION
WHEN OTHERS THEN DBMS_OUTPUT.put_line (SQLERRM);
END
You have to define l_attrs as dbms_ldap.string_collection, not your own type. Even if your type is defined in the same way, it will not be interchangeable with another apparently-similar type. To Oracle, your attrs_type is not the same as string_collection. Hence the error you're getting - you are indeed using the wrong type for that argument.
From the documentation:
A collection type defined in a package specification is incompatible with an identically defined local or standalone collection type.

How to determine payload type for DBMS_AQ.DEQUEUE_ARRAY

I am attempting to use the function DBMS_AQ.DEQUEUE_ARRAY in Oracle 10.2.0.4.0. to browse the contents of a queue. Is there a way to determine the type to use for the message array? Is there some "generic" type I could be using? What I'm attempting is as follows:
CREATE or REPLACE TYPE I_NEED_THIS_TYPE AS ????
/
CREATE or REPLACE myFunction
return pls_integer
IS
dequeue_options DBMS_AQ.dequeue_options_t;
message_properties DBMS_AQ.message_properties_t;
msgPropArray DBMS_AQ.message_properties_array_t;
msgIdArray DBMS_AQ.msgid_array_t;
msgArray I_NEED_THIS_TYPE;
cMsgs pls_integer;
BEGIN
msgPropArray := DBMS_AQ.message_properties_array_t();
msgIdArray := dbms_aq.msgid_array_t();
msgArray := I_NEED_THIS_TYPE();
--where SOME_NAME and SOME_QUEUE_TABLE I get from
--select owner,name from user_queues;
dequeue_options.CONSUMER_NAME := 'SOME_NAME.SOME_QUEUE_TABLE';
dequeue_options.DEQUEUE_MODE := DBMS_AQ.BROWSE;
dequeue_options.NAVIGATION := DBMS_AQ.FIRST_MESSAGE;
dequeue_options.VISIBILITY := DBMS_AQ.IMMEDIATE;
dequeue_options.WAIT := DBMS_AQ.NO_WAIT;
dequeue_options.MSGID := null;
cMsgs := DBMS_AQ.DEQUEUE_ARRAY(
queue_name => 'MY_QUEUE_NAME',
dequeue_options => dequeue_options,
array_size => 30,
message_properties => msgPropArray,
payload_array => msgArray,
msgid_array => msgIdArray);
return cMsgs;
END;
/
I have tried numerous combinations of
CREATE or REPLACE TYPE I_NEED_THIS_TYPE AS VARRAY(100) of CLOB;
CREATE or REPLACE TYPE I_NEED_THIS_TYPE AS VARRAY(100) of SYS.xmltype;
CREATE or REPLACE TYPE I_NEED_THIS_TYPE AS VARRAY(100) of xmltype;
CREATE or REPLACE TYPE I_NEED_THIS_TYPE AS OBJECT(
id NUMBER,
xmlData CLOB
)
DECLARE
TYPE assoc_array is TABLE OF CLOB index by pls_integer;
myData assoc_array;
I AM able to use the DBMS_AQ.DEQUEUE function as expected, the message parameter for that is SYS.xmltype.
I am unable to use the administrator account, but do have privilieges to create types and functions. If there is no way to determine this information, what type of query should I ask the administrator to run so that I can determine this information?
Thanks!
It's probable your queue was created with a payload type when CREATE_QUEUE_TABLE was run. You can therefore find out the type for the queue by performing this query:
select OBJECT_TYPE
from DBA_QUEUE_TABLES
where OWNER = 'SOME_NAME' and QUEUE_TABLE = 'SOME_QUEUE_TABLE';
Then your function can use this:
type I_NEED_THIS_TYPE is varray(100) of <OBJECT_TYPE>;

How can I debug the value of a PL/SQL collection in Oracle?

I'm debugging a procedure which ... returns certain values. The procedure seems to use DBMS_SQL.DESCRIBE_COLUMNS2 which was, till now unknown to me.
One of the out variables of the DBMS_SQL.DESCRIBE_COLUMNS2 procedure is a collection, and I want to examine that value is being returned into that - how can I observe/watch/examine this value ?
I use Allround Automations' PL/SQL Developer, but also have Oracle's SQL Developer as the tools with which I can use.
Tried iterating through the collection like so;
For Val In 1..M_Rec_Tab.Count Loop
Dbms_Output.Put_Line( M_Rec_Tab(Val) );
end loop;
But that throws a PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'.
M_Rec_Tab is declared as Dbms_Sql.Desc_Tab2 type.
Dbms_Sql.Desc_Tab2 declared as desc_tab2 is table of desc_rec2 index by binary_integer
I'm on Oracle 10g R2 ( 10.2.0.1.0 )
You were almost there... Just one more step. The definition of desc_tab2 is:
TYPE desc_rec2 IS RECORD (
col_type binary_integer := 0,
col_max_len binary_integer := 0,
col_name varchar2(32767) := '',
col_name_len binary_integer := 0,
col_schema_name varchar2(32) := '',
col_schema_name_len binary_integer := 0,
col_precision binary_integer := 0,
col_scale binary_integer := 0,
col_charsetid binary_integer := 0,
col_charsetform binary_integer := 0,
col_null_ok boolean := TRUE);
So you can loop over the collection and output the values of each field in the record:
For Val In 1..M_Rec_Tab.Count Loop
Dbms_Output.Put_Line( '----- Record #'||Val||' -----' );
Dbms_Output.Put_Line( 'Column Type: '||M_Rec_Tab(Val).col_type );
Dbms_Output.Put_Line( 'Max Length: '||M_Rec_Tab(Val).col_max_len );
...
Dbms_Output.Put_Line( 'Charset Form: '||M_Rec_Tab(Val).col_charsetform );
Dbms_Output.Put_Line( 'Nulls Allowed: '|| case when M_Rec_Tab(Val).col_null_ok then 'Y' else 'N' end );
end loop;

Resources