How to define a function with table type parameter
Hello All,
Here is the requirement ..
cursor c is select first_name, last_name , ssn from employee ;
TYPE employee_type IS TABLE OF c%rowtype;
tbl_employee_type employee_type;
I want to pass the parameter to a function the ssn -: tbl_employee_type(1).ssn
how the formal parameter should be declared
===========================
function chk_notnull_blank ( ? ) return boolean is
BEGIN
if ( colname is NOT NULL and colname in ( -8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9 )) then
RETURN TRUE ;
else
RETURN FALSE ;
end if;
END chk_notnull_blank;
======================
pls advice
thanks/kumar
You cannot define a generic argument in a function,
but you can overload several funtions with the same name and different types of arguments in a package,
in this way (not tested):
create table employees as
select employee_id ssn, first_name, last_name from hr.employees;
create or replace
PACKAGE chk
IS
cursor c is select first_name, last_name , ssn from employees ;
TYPE employee_type IS TABLE OF c%rowtype;
TYPE employee_ssn_type IS TABLE OF employees.ssn%TYPE;
TYPE employee_num_type IS TABLE OF number;
FUNCTION chk_notnull_blank ( colname employees.ssn%TYPE) RETURN boolean;
FUNCTION chk_notnull_blank ( colnames employee_type) RETURN boolean;
FUNCTION chk_notnull_blank ( colnames employee_ssn_type) RETURN boolean;
FUNCTION chk_notnull_blank ( colnames employee_num_type) RETURN boolean;
END chk;
create or replace
PACKAGE BODY chk
IS
FUNCTION chk_notnull_blank ( colname employees.ssn%TYPE) RETURN boolean IS
BEGIN
if ( colname is NOT NULL and colname in ( -8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9 )) then
RETURN TRUE ;
else
RETURN FALSE ;
END IF;
END chk_notnull_blank;
FUNCTION chk_notnull_blank ( colnames employee_type) RETURN boolean IS
BEGIN
FOR i IN colnames.FIRST .. colnames.LAST LOOP
IF NOT chk_notnull_blank( colnames( i ).ssn )
THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN true;
END chk_notnull_blank;
FUNCTION chk_notnull_blank ( colnames employee_ssn_type) RETURN boolean
IS
BEGIN
FOR i IN colnames.FIRST .. colnames.LAST LOOP
IF NOT chk_notnull_blank( colnames( i ) )
THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN TRUE;
END chk_notnull_blank;
FUNCTION chk_notnull_blank ( colnames employee_num_type) RETURN boolean
IS
BEGIN
FOR i IN colnames.FIRST .. colnames.LAST LOOP
IF NOT chk_notnull_blank( colnames( i ) )
THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN TRUE;
END chk_notnull_blank;
END chk;I assumed in this example that if the argument of the function chk_notnull_blank is of the table (collection) type,
then the function returns true if all table elements pass the check, otherwise it returns false.
Similar Messages
-
How to create a function with ref_cursor as parameter in OWB 10.1
Hi,
Can any one help me how to create a function with ref_cursor as parameter in OWB 10.1.?
Its urgent. Please help me.
Thanks,
SivHi David,
Thanks for your reply.
Before going for this function, I need to create a package in transformation node in owb module.
My package is as follows,
Create or replace package 123
type xxx is RECORD ( parameters);
type yyy is RECORD (parameters);
type aaa is table of yyy;
type bbb is REF CURSOR return xxx;
type ccc is record (parameters);
type ddd is ref cursor return eee;
END;
How can I create the above kind of package manually in OWB 10.1 (Should not to import the package)
Please help me its urgent.
Thanks,
Siv -
How can I Create function with an out Parameter
how all
how can I Create function with an out Parameter
I try to create it it sucess but how can I CALL it , it give me error
please I want A simple example
thanks3rd post on same question by same user :
Re: how can I Create function with an out Parameter
how can I Create function with an out Parameter -
How to change stored procedure with Table Valued Parameter
I am not sure how to change the normal stored procedure with Table Value Parameter.Do I have to create a separate Table or do I have to create a datatype. Can you please help me with this
ALTER PROCEDURE [dbo].[uspInsertorUpdateINF]
@dp_id char(32),
@dv_id char(32),
@em_number char(12),
@email varchar(50),
@emergency_relation char(32),
@option1 char(16),
@status char(20),
@em_id char(35),
@em_title varchar(64),
@date_hired datetime
AS
BEGIN
SET NOCOUNT ON;
MERGE [dbo].[em] AS [Targ]
USING (VALUES (@dp_id, @dv_id , @em_number, @email, @emergency_relation, @option1, @status, @em_id, @em_title, @date_hired))
AS [Sourc] (dp_id, dv_id, em_number, email, emergency_relation, option1, status, em_id, em_title, date_hired)
ON [Targ].em_id = [Sourc].em_id
WHEN MATCHED THEN
UPDATE
SET dp_id = [Sourc].dp_id,
dv_id = [Sourc].dv_id,
em_number = [Sourc].em_number,
email = [Sourc].email,
emergency_relation = [Sourc].emergency_relation,
option1 = [Sourc].option1,
status = [Sourc].status,
em_title = [Sourc].em_title,
date_hired = [Sourc].date_hired
WHEN NOT MATCHED BY TARGET THEN
INSERT (dp_id, dv_id, em_number, email, emergency_relation, option1, status, em_id, em_title,date_hired)
VALUES ([Sourc].dp_id, [Sourc].dv_id, [Sourc].em_number, [Sourc].email, [Sourc].emergency_relation, [Sourc].option1, [Sourc].status, [Sourc].em_id, [Sourc].em_title, [Sourc].date_hired);
END;It's not clear how you would change the procedure. But assuming that you want to replace the existing scalar parameters with tabular input, this is how you would do it. You first create a table type:
CREATE TYPE Insertor_type AS TABLE
(dp_id char(32),
dv_id char(32),
em_number char(12),
email varchar(50),
emergency_relation char(32),
option1 char(16),
status char(20),
em_id char(35),
em_title varchar(64),
date_hired datetime)
Then you change the procedure header:
ALTER PROCEDURE [dbo].[uspInsertorUpdateINF] @tvp Insertor_type READONLY AS
And finally you change the USING clause:
USING (SELECT dp_id, dv_id , em_number, email, emergency_relation, option1, status, em_id, em_title, date_hired
FROM @tvp) AS [Sourc] ON [Targ].em_id = [Sourc].em_id
The rest is fine as it is.
Erland Sommarskog, SQL Server MVP, [email protected] -
Complicated PL/SQL questions that involves function with in type parameter
Hello,
I have a question about functions with in-parameters. In the HR schema, I need to get the minimum salary of the job_id that is mentioned as an in-parameter.
this is what I am thinking but I dont know if it's correct or not or what should I do next!
create or replace function get_min_salary (i_job_id in varchar2)
return number
as
min_sal jobs.min_salary%type;
begin
SELECT min_salary INTO min_sal
FROM jobs
where job_id = i_job_id;
RETURN min_sal;
end get_min_salary;if the i_job_id which is the in type parameter does not have a minimum salary then use the following function to register an error:
create or replace procedure insert_error (i_error_code in number,
i_error_message in varchar2)
as
begin
insert into error_table (error_user, error_date, error_code, error_message)
values (user,sysdate,i_error_code,i_error_message);
end insert_error;This function is basically to say that an error has occured and to register that error, at the same time I need to print out the error using the dbms_out.put_line.
Any ideas of how to do that?
Thanks in advance>
minimum salary of the job_id
>
may be
SELECT min(min_salary) INTO min_sal
FROM jobs
where job_id = i_job_id;
if the i_job_id which is the in type parameter does not have a minimum salary then use the following function to register an error:why error?
This function is basically to say that an error has occured and to register that error, at the same time I need to print out the error using the dbms_out.put_line.
create or replace procedure insert_error (i_error_code in number,
i_error_message in varchar2)
as
begin
insert into error_table (error_user, error_date, error_code, error_message)
values (user,sysdate,i_error_code,i_error_message);
-- this
dbms_out.put_line('this');
end insert_error; -
How to write a function with table name as parameter
I created a function like this:
create or replace function "GETNAME"
(did in NUMBER, dtable in VARCHAR2)
return VARCHAR2
is
dname varchar2(200);
begin
select lastname || ' ' || firstname
into dname from dtable
where id = did;
return dname;
end;
i got an error: table or view does not exist.
Could somebody tell me how to fix it?
Thanks,
Jenor by using a reference cursor: create or replace function dynamic_cursor (pTab varchar2)
return sys_refcursor as
c sys_refcursor;
begin
open c for 'select * from '|| pTab;
return c;
end;
SQL> exec :c := dnamic_cursor('emp');
SQL> exec :c := dynamic_cursor('emp');
PL/SQL procedure successfully completed.
SQL> print c;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7566 JONES MANAGER 7839 02-APR-81 2975 1000 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7934 MILLER CLERK 7782 23-JAN-82 1300 10
7945 CINDY SALESMAN 7698 16-JAN-83 1800 30
7950 TINA SALESMAN 7698 18-JAN-83 1850 30
16 rows selected.
SQL> -
V-41 tcode error :Table 304 is not defined for use with condition type PR00
Hi All,
I am trying to create a BDC using the transaction V-41.
The first screen has fields:
ConditionType and Table, where I have to fill values ZPM1 and 800 respectively.
But as soon as I enter the tcode v-41 and say enter, the above mentioned fields are already having the values 'PR00' and ' 304'. Normally if you take an example fo t-code VA02, all fields are blank.
Then an error message is displayed:
Table 304 is not defined for use with condition type PR00
This behaviour is not allowing me to use the BDC feature.
Please advise me on why this is happening. What are the possible solutions I can use to clear these values programmatically?
Can anything be done via customizing?
Regards,
Namita.Dear ILHAN ,
Well the problem you are facing is having the following solution:
Table 304 is not defined for use with condition type PR00
Message no. VK024
Diagnosis
The selected condition type does not fit in the condition table, that is the basis for the condition record. Alternatively the selected condition type is not included in the condition types that were selected on the selection screen or that are defined in the variant of the standard selection report.
Procedure
Úse F4 help to choose a valid condition type.
If this does not give you the required condition type, check in Customizing for condition types and the related access sequences.
In the condition maintenance also check Customizing for the selection report (pricing report), that you have selected in the navigation tree, using the standard condition table as a reference.
I hope this helps.
It has worked for me.
I gave it a try and what I am getting using the transaction V-41 is create Price condition (PR00) : Fast Entry.
Please award points if you find it useful.
Regards,
Rakesh -
How to use INVOKE function with INT parameter types
Can you tell me how to use invoke function with int parameter type ?
Pass the int as an Integer.
-
Function with return type boolean
I have created a function with return type boolean as:
CREATE OR REPLACE FUNCTION fn RETURN BOOLEAN
AS
exp EXCEPTION;
BEGIN
return TRUE;
EXCEPTION
when OTHERS then RAISE exp;
END;
FUNCTION fn compiledThen I was trying to call this function into dbms_output.put_line procedure, I got this error:
EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'Can someone please help me understand, why this happened?
Is this because of boolean return type?952040 wrote:
I have created a function with return type boolean as:
Then I was trying to call this function into dbms_output.put_line procedure, I got this error:
EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
What is the parameter signature for DBMS_OUTPUT.put_line() ?
Is is string - as detailed in Oracle® Database PL/SQL Packages and Types Reference guide.
So how can you pass a boolean data type as parameter value, when the parameter's data type is string?
PL/SQL supports implicit data conversion. So you can for example pass a number or date value to DBMS_OUTPUT.put_line() - and the PL/SQL engine automatically (and implicitly) converts that (using the TO_CHAR() functions) to a string.
However, the TO_CHAR() parameter signature supports number and date - not boolean. It cannot convert a boolean value into a string.
So passing a boolean value means the implicit conversion fails - and results in the above error.
To make it work, you need to perform an explicit conversion. As as a data type conversion function from boolean to string is not available, you need to write a user defined function. E.g.
SQL> create or replace function BoolToChar( b boolean ) return varchar2 is
2 begin
3 case
4 when b then return( 'TRUE' );
5 when not b then return( 'FALSE' );
6 else
7 return( null );
8 end case;
9 end;
10 /
Function created.
SQL>
SQL> exec DBMS_OUTPUT.put_line( 'Flag is '||BoolToChar(true) );
Flag is TRUE
PL/SQL procedure successfully completed -
How I tie the formula with conditions type?
Hi,
Than create the formula with tcode O3I7:
1) how I tie the formula with conditions type?
2) how I tie the conditions type with the formula with Calculation Schema?
help me, please.
thanks
Edited by: celeste ziantoni on Feb 5, 2008 6:45 PMHello,
Pricing formula is created using transaction VOFM. It is tied to the condition types in Pricing Procedure definition in Alternate Calculation Type column. For Pricing procedure, the menu path is SPRO->Materials Management->Purchasing->Conditions->Define Price Determination Process->Define Calculation Schema.
Thanks,
Venu -
Dont work 'REUSE_ALV_FIELDCATALOG_MERGE' with table type
Hi Experts ;
My problem about 'REUSE_ALV_FIELDCATALOG_MERGE' .
I use intarnal table with Table Type ( with header line ). And 'REUSE_ALV_FIELDCATALOG_MERGE' is not working . Field catalog is employ. I dont use 'REUSE_ALV_FIELDCATALOG_MERGE' have any problem.'REUSE_ALV_FIELDCATALOG_MERGE' expects a flat structure.
Give the reference of the line type of the table type if you wish to have fieldcatalog as per that..
Even if you dont use 'REUSE_ALV_FIELDCATALOG_MERGE' you can create your own Fieldcatalog.. -
Java call stored procedure with nested table type parameter?
Hi experts!
I need to call stored procedure that contains nested table type parameter, but I don't know how to handle it.
The following is my pl/sql code:
create or replace package test_package as
type row_abc is record(
col1 varchar2(16),
col2 varchar2(16),
col3 varchar2(16 )
type matrix_abc is table of row_abc index by binary_integer;
PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
p_arg2 IN VARCHAR2,
p_arg3 IN VARCHAR2,
p_out OUT matrix_abc
END test_package;
create or replace package body test_package as
PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
p_arg2 IN VARCHAR2,
p_arg3 IN VARCHAR2,
p_out OUT matrix_abc
IS
v_sn NUMBER(8):=0 ;
BEGIN
LOOP
EXIT WHEN v_sn>5 ;
v_sn := v_sn + 1;
p_out(v_sn).col1 := 'col1_'||to_char(v_sn)|| p_arg1 ;
p_out(v_sn).col2 := 'col2_'||to_char(v_sn)||p_arg2 ;
p_out(v_sn).col3 := 'col3_'||to_char(v_sn)||p_arg3 ;
END LOOP ;
END ;
END test_package ;
My java code is following, it doesn't work:
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@10.16.102.176:1540:dev", "scott", "tiger");
con.setAutoCommit(false);
CallableStatement ps = null;
String sql = " begin test_package.test_matrix( ?, ? , ? , ? ); end ; ";
ps = con.prepareCall(sql);
ps.setString(1,"p1");
ps.setString(2,"p2");
ps.setString(3,"p3");
ps.registerOutParameter(4,OracleTypes.CURSOR);
ps.execute();
ResultSet rset = (ResultSet) ps.getObject(1);
error message :
PLS-00306: wrong number or types of arguments in call to 'TEST_MATRIX'
ORA-06550: line 1, column 8:
PL/SQL: Statement ignored
Regards
LouisLouis,
If I'm not mistaken, record types are not allowed. However, you can use object types instead. However, they must be database types. In other words, something like:
create or replace type ROW_ABC as object (
col1 varchar2(16),
col2 varchar2(16),
col3 varchar2(16 )
create or replace type MATRIX_ABC as table of ROW_ABC
/Then you can use the "ARRAY" and "STRUCT" (SQL) types in your java code. If I remember correctly, I recently answered a similar question either in this forum, or at JavaRanch -- but I'm too lazy to look for it now. Do a search for the terms "ARRAY" and "STRUCT".
For your information, there are also code samples of how to do this on the OTN Web site.
Good Luck,
Avi. -
How can I work lsmw with table control using mm01 appl?
Hi
How can I work lsmw with table control using mm01 appl?
Is it difefrent the way we handle table control in BDC?
Thank YouHi
How can I work lsmw with table control using mm01 appl?
Is it difefrent the way we handle table control in BDC?
Thank You -
How to use TRUNC function with dates in Expression Builder in OBIEE.
Hi There,
How to use TRUNC function with dates in Expression Builder in OBIEE.
TRUNC (SYSDATE, 'MM') returns '07/01/2010' where sysdate is '07/15/2010' in SQL. I need to use the same thing in expression builder in BMM layer logical column.
Thanks in advanceuse this instead:
TIMESTAMPADD(SQL_TSI_DAY, ( DAYOFMONTH(CURRENT_DATE) * -1) + 1, CURRENT_DATE) -
How Create procedure or function with ADO ?
Hello,
How Create procedure or function with ADO?It's my question.
Thanks.
HenriThis message if post by Taiwan-ChangHaw-Oracle-Stored-Procedure-For-Business-Rule-Club
public bool ConnectDatabase()
try
{ string strConnectionString =
"Provider=OraOLEDB.Oracle" +";"+
"Data Source=" + ConnectionParams.Datasource +";"+
"User Id =" + ConnectionParams.Username +";"+
"Password =" + ConnectionParams.Password;
m_conn=new ADODB.Connection();
m_conn.ConnectionString=strConnectionString;
m_conn.Open("","","",0); //i_"YYAOl Open the connection
catch(Exception e)
{ System.Windows.Forms.MessageBox.Show(e.Message);
return false;
return true; //YYAOl_B>3I9&connected successfully
public void InsertDescription(string p_product,string p_language,string p_tname,string p_tdescription)
{ string sql="{Call inserttranslateddescription(?,?,?,?,?)}";
try
{ ADODB._Command cmd=new ADODB.Command();//Create a command object
cmd.ActiveConnection=m_conn; //Set its active connection to open connection
ADODB.Properties properties=cmd.Properties;//Get the command properties into ADODB Properties object
IEnumerator ienum=properties.GetEnumerator();//Get an enumerator on above properties
ADODB.Property singleprop;
while(ienum.MoveNext()) //iterate through the enumerator
{singleprop=(ADODB.Property)ienum.Current;//Get the current property from enumerator
string propname= singleprop.Name; //Get the name of current property
if(propname.Equals("NDatatype")) //if the property is 'NDatatype' set its value to true
singleprop.Value=true;
cmd.CommandType=ADODB.CommandTypeEnum.adCmdText;
int pid=Int32.Parse(p_product);
ADODB._Parameter langid =cmd.CreateParameter("langid", ADODB.DataTypeEnum.adChar,ADODB.ParameterDirectionEnum.adParamInput, 100,p_language);
ADODB._Parameter productid =cmd.CreateParameter("productid", ADODB.DataTypeEnum.adNumeric,ADODB.ParameterDirectionEnum.adParamInput, 100,pid);
ADODB._Parameter tname =cmd.CreateParameter("tname", ADODB.DataTypeEnum.adBSTR,ADODB.ParameterDirectionEnum.adParamInput, 50,p_tname);
ADODB._Parameter tdescription=cmd.CreateParameter("tdescription",ADODB.DataTypeEnum.adBSTR,ADODB.ParameterDirectionEnum.adParamInput, 50,p_tdescription);
ADODB._Parameter check =cmd.CreateParameter("check", ADODB.DataTypeEnum.adNumeric,ADODB.ParameterDirectionEnum.adParamOutput,100,0);
cmd.Parameters.Append(langid);
cmd.Parameters.Append(productid);
cmd.Parameters.Append(tname);
cmd.Parameters.Append(tdescription);
cmd.Parameters.Append(check);
cmd.CommandText=sql;
//Execute the command to insert product details in database
object recs;
object param=p_language;
cmd.Execute(out recs,ref param,1);
ienum.Reset();
while(ienum.MoveNext()) //iterate through enumerator
{ singleprop=(ADODB.Property)ienum.Current;//Get the current property in to Property object
string propname= singleprop.Name; //Get the name of current property
if(propname.Equals("NDatatype")) //if it is 'NDatatype' set its value to true
singleprop.Value=false;
IEnumerator iprop=cmd.Parameters.GetEnumerator();//Get the enumerator for command parameters
while(iprop.MoveNext()) //loop through enumerator
{ //Get the current parameter in enumerator
ADODB._Parameter checkval=(ADODB._Parameter)iprop.Current;
if(checkval.Name.Equals("check")) //if the parameter is 'check'
if(checkval.Value.ToString().Equals("0")) //If check's value is zero data was inserted
System.Windows.Forms.MessageBox.Show("Product details Inserted successfully");
else
System.Windows.Forms.MessageBox.Show("Product Details Updated");//else data was updated
catch(Exception e)
System.Windows.Forms.MessageBox.Show(e.Message);//Display any error message
}
Maybe you are looking for
-
Conditional Routing in Reciever Determination: Best Practise
Hi ALL I am doing a File to EDI scenario.... And based on the vendor name in the file... I will be routing the EDI to various vendor destination hosts. Here is the Scenario A file which is coming from a single sender is being routed to multiple hosts
-
Mail crashes when .eps file is attached
Hi All, Running: Mac OS X 10.7.2 - Build 11C74 Mail 5.1 (1251/1251.1) My mail keeps craching on my 2 (mid 2011) iMac's when an eps file is attached. On my MacBook Pro there is no problem...
-
Reports 2.5 / Multi Org?
A Partner asked the following question: "I have been designing custom reports for a client using Reports 2.5 which are then implemented in Oracle Financials. The client has now moved to a Multi Org environment. What do I need to do to my reports to g
-
Hi, I'm having a bit of a nightmare with iCloud and my contacts. For some weeks now, iCloud duplicates (and triplicates) my contacts for no reason. I use the same ID on a MBP, iPad and an iPhone so I can access the same data on all of them. It has wo
-
Hi, We are trying to uprade our ESA to build 106. And we still get the following error: The following errors occurred during upgrade: Download error: http://updates.ironport.com/asyncos/phoebe-8-5-6-106/hints/default/1 Upgrade exited without success.