How to pass record type value to function argument - oracle

May I know how to pass a record type value to a function argument?
Below is my attempt. I'm getting "wrong number or types of arguments in call..." error
I've searched but couldn't seem to find definite answer that will help me.
Hope someone can answer.
DECLARE
TYPE attribute_type_record IS RECORD
(
name VARCHAR2(100)
,value VARCHAR2(400)
,ind integer
);
type attribute_type is table of attribute_type_record index by binary_integer;
sid_att attribute_type;
ret varchar2(3000);
BEGIN
sid_att(1).name := 'SID_ATTRIBUTES.REFERENCE1';
sid_att(1).value := 'SID_ATTRIBUTES.REFERENCE1';
sid_att(1).ind := '1';
--v_row := sid_attributes_table('SID_ATTRIBUTES.REFERENCE1');
ret := SC$DATA_ENTRY.ins_sid_attributes(sid_att(1).name,
sid_att(1).value,
sid_att(1).ind,
'594191176',
'TEST');
END;
FUNCTION ins_sid_attributes (
p_sid_attributes_table sc$data_entry_utilities.attribute_table,
p_sid_id sid_attributes.sid_id%TYPE,
p_user IN VARCHAR2
)
RETURN VARCHAR2
IS
error_message VARCHAR2 (2000);
v_row sc$data_entry_utilities.attribute_type;
empty_row sc$data_entry_utilities.attribute_type;
v_order INTEGER := 0;
v_name VARCHAR2 (2000);
cat_table pkg_utilities.number_table;
-- I did not post the rest of the code of this function since i believe it is irrelevant to the error and to keep it short.
Thanks in advance!
noth

Assuming that the INS_SID_ATTRIBUTES procedure shown above is the one you're actually trying to call, the message seems reasonable to me. INS_SID_ATTRIBUTES, as shown above, wants three parameters:
A SC$DATA_ENTRY_UTILITIES.ATTRIBUTE_TABLE
A SID_ATTRIBUTES.SID_ID%TYPE
A VARCHAR2
But in the call you're passing it:
A VARCHAR2
A VARCHAR2
An INTEGER
A VARCHAR2
A VARCHAR2
So you're passing five arguments to a procedure that only accepts three, and the values you're passing are of the wrong types.
Share and enjoy.

Related

Create email notification request link function

I created a function to create link but am encountering errors when creating a variable, tried declaring but declare would have an error
create or replace FUNCTION CREATE_REQUEST_LINK(request_id IN VARCHAR2, task_id IN VARCHAR2)
RETURN VARCHAR2 AS
request_link varchar2(100);
BEGIN
first_half varchar2 := apex_mail.get_instance_url;
second_half varchar2 := 'f?p=&APP_ID.:&APP_PAGE.:&APP_SESSION.::::';
request_link := first_half + second_half;
RETURN request_link;
END WF_CREATE_REQUEST_LINK;
It was returning on Line 8 and 9
Error: PLS-00103: Encountered the symbol "VARCHAR2" when expecting one of the following: := . ( # % ; The symbol "." was substituted for "VARCHAR2" to continue.
Is there a way to fix. I'm kinda new to Oracle Apex
Additional question, am I right in creating the 2nd half, the plan is that the $APP_SESSION. after clicking the link will be changed into the session id after logging in.
You seem to want to declare two local variables first_half and second_half. Variable declarations need to happen in the declaration section of a block.
When you declare a varchar2 variable, you need to provide a length. I'll guess that you want both local variables to have a maximum length of 100.
The string concatenation operator is || not +
So you probably want something like
create or replace FUNCTION CREATE_REQUEST_LINK(
request_id IN VARCHAR2,
task_id IN VARCHAR2)
RETURN VARCHAR2
AS
request_link varchar2(100);
first_half varchar2(100) := apex_mail.get_instance_url;
second_half varchar2(100) := 'f?p=&APP_ID.:&APP_PAGE.:&APP_SESSION.::::';
BEGIN
request_link := first_half || second_half;
RETURN request_link;
END WF_CREATE_REQUEST_LINK;

Error executing DBMS_OUTPUT.PUT_LINE in Oracle

I am running DBMS_OUTPUT.PUT_LINE to send a message from a procedure and I am trying to display the debug information of what a type variable contains BFILE
create or replace PROCEDURE P_FILEUPLOAD_XML IS
v_dir gzvcatg.gzvcatg_desc11%TYPE;
l_dir VARCHAR2(35);
l_fil VARCHAR2(30) := 'ES0000251446027471.xml';
l_loc BFILE;
BEGIN
l_loc := BFILENAME(v_dir,l_fil);
DBMS_OUTPUT.PUT_LINE(l_loc);
END;
At the moment of executing my procedure and waiting for a response from the log:
Anyone know why the error is due and how to correct it.
UPDATE:
Following the recommendation in the MT0 response making use of DBMS_LOB.READ, try the following:
create or replace PROCEDURE P_FILEUPLOAD_XML IS
v_dir gzvcatg.gzvcatg_desc11%TYPE;
l_dir VARCHAR2(35);
l_fil VARCHAR2(30) := 'ES0000251446027471.xml';
l_loc BFILE;
BEGIN
l_loc := BFILENAME(v_dir,l_fil);
DBMS_LOB.READ(l_loc IN BFILE);
END;
But executing it generates the following error:
Anyone know why the error is due
l_loc is a BFILE.
DBMS_OUTPUT.PUT_LINE( item IN VARCHAR2 ) takes a VARCHAR2 data type as its argument.
You cannot implicitly cast a BFILE to a VARCHAR2 so the procedure call raise an exception as it is the wrong type of argument to call the function with.
and how to correct it.
Read the file using DBMS_LOB.READ and use UTL_RAW.CAST_TO_VARCHAR2 to convert the RAW value you get from the LOB to a string so you can print it.

How to convert pls_number to varchar2 in oracle?

I tried to convert pls_integer to varchar2 using to_char but it is not working.
I also tried pls_integer to number and number to varchar2 using to_number and to_char methods, but that also not working. I am getting an error :
Pls00306 - wrong number or types of arguments in call 'to_number'.
Can you please help.
There's no need to do anything special just assign. Oracle allows implicit data type conversion between pls_integer and varchar2. See table 3-10 at the bottom of this page
declare
l_number pls_integer;
l_varchar varchar2(1);
begin
l_number := 8;
l_varchar := l_number;
end;

Can we use a table type parameter as a default null parameter in PLSQL?

I have a record type as follows,
TYPE x_Rec IS RECORD(
master_company x_tab.master_company%TYPE,
report_trans_type x_tab.report_trans_type%TYPE,
balance_version_id x_tab.balance_version_id%TYPE,
reporting_entity x_tab.reporting_entity%TYPE,
year_period_from x_tab.year_period%TYPE,
year_period_to x_tab.year_period%TYPE,
journal_id x_tab.journal_id%TYPE,
row_id x_tab.row_id%TYPE);
and I have created a table type using this record:
TYPE x_rec_tab IS TABLE OF x_Rec INDEX BY PLS_INTEGER;
I want to use this table type in a procedure as a default null parameter.
PROCEDURE x_Balance___(x_param IN NUMBER,
x_rec_ IN x_rec_tab default null)
IS
BEGIN
...My code
END;
It gives the following error message
PLS-00382: expression is of the wrong type
I resolved this by using CAST(null as /*your_type*/) in the Procedure's signature.
For instance, in your case, it will be something like this:
PROCEDURE x_Balance (x_param IN NUMBER,
x_rec_ IN x_rec_tab default cast(null as x_rec_tab))
Then, within the procedure, you just need to check if x_rec_ has elements by using the count method.
This way works for me.
You can't do that with an associative array, as that can never be null. You would get the same error if you tried to assign null to a variable of type x_rec_tab. They also don't have constructors, so you can't use an empty collection instead.
You can do this will a varray or more usefully for your situation a nested table:
create or replace package p42 as
TYPE x_Rec IS RECORD(
master_company x_tab.master_company%TYPE,
report_trans_type x_tab.report_trans_type%TYPE,
balance_version_id x_tab.balance_version_id%TYPE,
reporting_entity x_tab.reporting_entity%TYPE,
year_period_from x_tab.year_period%TYPE,
year_period_to x_tab.year_period%TYPE,
journal_id x_tab.journal_id%TYPE,
row_id x_tab.row_id%TYPE);
-- no index-by clause, so nested table not associative array
TYPE x_rec_tab IS TABLE OF x_Rec;
end p42;
/
Package P42 compiled
show errors
No errors.
create or replace package body p42 as
PROCEDURE x_Balance___(x_param IN NUMBER,
x_rec_ IN x_rec_tab default null)
IS
BEGIN
--...My code
null;
END;
PROCEDURE dummy IS
l_rec_tab x_rec_tab;
BEGIN
l_rec_tab := null;
END;
end p42;
/
Package Body P42 compiled
show errors;
No errors.
You could also default to an empty collection instead:
PROCEDURE x_Balance___(x_param IN NUMBER,
x_rec_ IN x_rec_tab default x_rec_tab())
IS
...
That doesn't really help you much if you have other code that relies on the type being an associative array of course.
Old question but still might be helpful.
You can create a function:
function empty_tab
return x_rec_tab
as
l_tab x_rec_tab;
begin
return l_tab;
end empty_tab;
This way you can (notice that empty_tab is used as default parameter):
PROCEDURE x_Balance___(x_param IN NUMBER,
x_rec_ IN x_rec_tab default empty_tab)
IS
BEGIN
...My code
END;
This is a repeat of #ManuelPerez answer, but I just feel that it could have been explained better.
Create this procedure, casting your optional variable to your datatype like this:
CREATE OR REPLACE PROCEDURE Test_Procedure (
txt_ IN VARCHAR2,
col_formats_ IN dbms_sql.varchar2a DEFAULT cast(null as dbms_sql.varchar2a) )
IS BEGIN
Dbms_Output.Put_Line (txt_);
FOR i_ IN 1 .. 10 LOOP
IF col_formats_.EXISTS(i_) THEN
Dbms_Output.Put_Line (i_ || ' Exists');
ELSE
Dbms_Output.Put_Line (i_ || ' DOES NOT Exist');
END IF;
END LOOP;
END Test_Procedure;
The reason this beats the accepted answer is that it doesn't require you to change the datatype of the incoming variable. Depending on your circumstance, you may not have the flexibility to do that.
Now call your procedure like this if you have a variable to feed the procedure:
DECLARE
txt_ VARCHAR2(100) := 'dummy';
arr_ dbms_sql.varchar2a;
BEGIN
arr_(4) := 'another dummy';
Test_Procedure (txt_, arr_);
END;
Or like this if you don't:
DECLARE
txt_ VARCHAR2(100) := 'dummy';
BEGIN
Test_Procedure (txt_);
END;
Your output will look something like this:
dummy
1 DOES NOT Exist
2 DOES NOT Exist
3 DOES NOT Exist
4 Exists
5 DOES NOT Exist
6 DOES NOT Exist
7 DOES NOT Exist
8 DOES NOT Exist
9 DOES NOT Exist
10 DOES NOT Exist

Oracle PL/SQL: How to print a table type

I am trying to print an table type for debugging purposes, but don't know how. I tried the following two methods, neither of which work:
dbms_output.put_line (V_TEMP_TABTYPE(1));
dbms_output.put_line (V_TEMP_TABTYPE);
The error generated is: PLS-00306: wrong number or types of arguments in call to.
So, how can I print the contents of a table type? Or is there a different way to display the contents?
The table_type and the type it references are::
create or replace TYPE MY_TYPE IS OBJECT( MyString Varchar(20)
, counter Number(9) );
create or replace TYPE MY_TABTYPE AS TABLE OF MY_TYPE;
Oracle has objects but it's ... different. Not exactly sure with your question if you want to see the values of the properties or if you want to actually see the type.
CREATE OR REPLACE TYPE MY_TYPE IS OBJECT (
MyString Varchar(20)
, counter Number(9)
);
Now run some code for it.
DECLARE
myType MY_TYPE;
BEGIN
myType := MY_TYPE('ABC123',0);
-- To see the values reference the properties
DBMS_OUTPUT.PUT_LINE(myType.mystring);
-- To see they TYPE of the OBJECT
DBMS_OUTPUT.PUT_LINE(SYS.ANYDATA.CONVERTOBJECT(myType).getTypeName());
END;
Of course you can create methods on the object to return information for you a bit easier.
CREATE OR REPLACE TYPE MY_TYPE IS OBJECT (
MyString Varchar(20)
, counter Number(9)
, MEMBER FUNCTION getType RETURN VARCHAR2
, MEMBER FUNCTION toString RETURN VARCHAR2
)
/
CREATE OR REPLACE TYPE BODY MY_TYPE
AS
MEMBER FUNCTION getTYPE RETURN VARCHAR2 IS
BEGIN
RETURN SYS.ANYDATA.CONVERTOBJECT(SELF).getTypeName();
END;
MEMBER FUNCTION toString RETURN VARCHAR2 IS
BEGIN
RETURN 'MY_TYPE('||self.mystring||','||self.counter||')';
END;
END;
/
You can call the functions on the object now makes it easier to read imo.
DECLARE
mytype MY_TYPE;
BEGIN
mytype := MY_TYPE('AGAIN','0');
DBMS_OUTPUT.PUT_LINE(mytype.toString);
DBMS_OUTPUT.PUT_LINE(mytype.getType);
END;
dbms_output.put_line(v_temp_tabtype(i).myString);

Resources