Handling NULL in Oracle Function
I try to handle NULL with IS NULL in side the Function. But I some how can't do it. Control always goes to NO_DATA_FOUND Exception block.
In BEGIN block, if I try to handle with IS NULL condition but it doesn't work. But if I use DBMS_OUTPUT.PUTLINE and display the variable with NVL, it tells me it is NULL.
My code is like;
<code>
FUNCTION F_GetProductKey (p_CompanyCod varchar2, p_ProductCod varchar2) return number;
as
vi_ProductKey Number;
BEGIN
DBMS_OUTPUT.PUT_LINE( NVL(p_ProductCod,'abc') <----- This displays 'abc'
IF p_ProductCod IS NULL THEN
SELECT PRODUCT_KEY in vi_ProductKey from DIM_PRODUCT WHERE Product_Cod=-2;
ELSE <---- Control Always Goes to ELSE even p_ProductCod is NULL & then it goes to NO_DATA_FOUND Exception
SELECT PRODUCT_KEY in vi_ProductKey from DIM_PRODUCT WHERE Product_Cod=p_ProductCod AND COMPANY_COD = p_CompanyCod ;
END IF;
return vi_Product_Key;
EXCEPTION
WHEN NO_DATA_FOUND THEN
return -20060;
WHEN OTHERS THEN
return -20001;
END;
</code>
I've a hard coded value in table for Product_Cod=-2, so I should never get No_Data_Found exception if ProductCod is NULL. I checked, for CompanyCod and it is NOT NULL when I call function.
I Googled to look at what I'm doing wrong. I find that NULL values can be handled by ISNULL but some how it doesn't work in my case.
Is there any other way to handle NULL inside function??
I've a hard coded value in table for Product_Cod=-2, so I should
never get No_Data_Found exception if ProductCod is NULL.Are you sure? It seems to me the behaviour you describe could equally well be explained by the control going down the IF ... IS NULL branch and then not finding the PRODUCT_COD in question.
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/
P.S. Having read your subsequent message, specifically this
Product_cod is varchar2. It is actually comparing to
'UNK' not -2 in side the code.I am even more certain that the problem lies in your data. Larry Ellison did not become a multi-billionnaire on the basis of code which behaved in an unpredictable fashion.
Message was edited by:
APC
Similar Messages
-
How to call oracle Function which has If else condition in Data Template
Hi,
currently I am working on creating Data Template which uses a Oracle Function which I need to make use in my data template. But I have some confusions on using the same. Could anybody please help me in this regard.
I have a function like this,
function invoice_query (p_facility_id facility.facility_id%TYPE,
p_wave_nbr pick_directive.wave_nbr%TYPE,
p_container_id unit_pick_group_detail.container_id%TYPE,
p_distro_nbr unit_pick_group_detail.distro_nbr%TYPE) return invoice_refcur IS
refcur invoice_refcur;
begin
IF p_wave_nbr IS NOT NULL THEN
OPEN refcur FOR SELECT t1.distro_nbr,
t1.cust_order_nbr,
t1.pick_not_before_date,
SYSDATE,
t1.ship_address_description,
t1.ship_address1,
t1.ship_address2,
t1.ship_address3,
t1.ship_address4,
t1.ship_address5,
t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip,
t1.ship_country_code,
t1.bill_address_description,
t1.bill_address1,
t1.bill_address2,
t1.bill_address3,
t1.bill_address4,
t1.bill_address5,
t1.bill_city || ', ' || t1.bill_state || ' ' || t1.bill_zip,
t1.bill_country_code,
min(t2.pick_order),
NULL,
t2.wave_nbr
FROM stock_order t1,
pick_directive t2,
unit_pick_group_detail t3
WHERE t1.facility_id = t2.facility_id
AND t1.facility_id = t3.facility_id
AND t2.facility_id = t3.facility_id
AND t1.distro_nbr = t2.distro_nbr
AND t1.distro_nbr = t3.distro_nbr
AND t2.distro_nbr = t3.distro_nbr
AND t1.facility_id = p_facility_id
AND t2.wave_nbr = p_wave_nbr
AND g_scp(p_facility_id, 'interface_tcp_flag') = 'N'
AND t2.pick_type = 'U'
AND t3.group_id in (SELECT t4.group_id
FROM unit_pick_group t4
WHERE t4.facility_id = p_facility_id
AND t4.wave_nbr = p_wave_nbr)
GROUP BY t1.distro_nbr,
t1.cust_order_nbr,
t1.pick_not_before_date,
t1.ship_address_description,
t1.ship_address1,
t1.ship_address2,
t1.ship_address3,
t1.ship_address4,
t1.ship_address5,
t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip,
t1.ship_country_code,
t1.bill_address_description,
t1.bill_address1,
t1.bill_address2,
t1.bill_address3,
t1.bill_address4,
t1.bill_address5,
t1.bill_city || ', ' || t1.bill_state || ' ' || t1.bill_zip,
t1.bill_country_code,
t2.wave_nbr
ORDER BY MIN(t3.group_id), MAX(t3.slot);
elsif p_container_id is not null then
OPEN refcur FOR SELECT distinct t1.distro_nbr,
t1.cust_order_nbr,
t1.pick_not_before_date,
SYSDATE,
t1.ship_address_description,
t1.ship_address1,
t1.ship_address2,
t1.ship_address3,
t1.ship_address4,
t1.ship_address5,
t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip,
t1.ship_country_code,
t1.bill_address_description,
t1.bill_address1,
t1.bill_address2,
t1.bill_address3,
t1.bill_address4,
t1.bill_address5,
t1.bill_city || ', ' || t1.bill_state || ' ' || t1.bill_zip,
t1.bill_country_code,
NULL,
t2.dest_id,
null
FROM stock_order t1,
unit_pick_group_detail t2
WHERE t1.facility_id = t2.facility_id
and t1.distro_nbr = t2.distro_nbr
and t1.facility_id = p_facility_id
AND g_scp(p_facility_id, 'interface_tcp_flag') = 'N'
AND t2.container_id = p_container_id;
else
open refcur for SELECT distinct t1.distro_nbr,
t1.cust_order_nbr,
t1.pick_not_before_date,
SYSDATE,
t1.ship_address_description,
t1.ship_address1,
t1.ship_address2,
t1.ship_address3,
t1.ship_address4,
t1.ship_address5,
t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip,
t1.ship_country_code,
t1.bill_address_description,
t1.bill_address1,
t1.bill_address2,
t1.bill_address3,
t1.bill_address4,
t1.bill_address5,
t1.bill_city || ', ' || t1.bill_state || ' ' || t1.bill_zip,
t1.bill_country_code,
NULL,
NULL,
t3.wave_nbr
FROM stock_order t1,
unit_pick_group_detail t2,
unit_pick_group t3
WHERE t1.facility_id = t2.facility_id
and t2.facility_id = t3.facility_id
and t1.distro_nbr = t2.distro_nbr
and t2.group_id = t3.group_id
and t1.facility_id = p_facility_id
AND g_scp(p_facility_id, 'interface_tcp_flag') = 'N'
AND t2.distro_nbr = p_distro_nbr;
END IF;
return refcur;
end;
I have created data template like following,
<sqlStatement name="Q_INVOICE">
<![CDATA[
SELECT Pack_Slip_R.invoice_query(:P_FACILITY_ID,:P_WAVE_NBR,:P_CONTAINER_ID,:P_DISTRO_NBR) from dual
]]>
</sqlStatement>
But how does I create a element for the "t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip" column in the oracle function. I normally create an element like following,
<group name="G_INVOICE" source="Q_INVOICE">
<element name="CUST_ORDER_NBR" value="cust_order_nbr"/>
<element name=":dest_id" value="dest_id"/>
</Group>
But how do i create element if a column name is kind of dynamic. Please help. I cannot Rename/change the Column in SQL Query. Please let me know If I could handle this whole logic in BI Publsiher.
Regards,
Ashoka BLtry useing alias
t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip as <COLUMN_ALIAS> -
Calling oracle function in OMB script
Hi
Can anyone please tell me how can i get the returned value of an oracle function in OMB script. or how can i get the value into OMB variable and use it.
Basically i want to set the properties of OWB mapping via OMB script.
Following OMB code sets the max error limit of a mapping.
OMBALTER MAPPING 'MAP_DATA' SET PROPERTIES (MAXIMUM_NUMBER_OF_ERRORS) VALUES ('100')
i dont want to hard code the value 100 rather i want this value to be returned from a function.
If it is not possible then plz tell me how can i set MAXIMUM_NUMBER_OF_ERRORS property of OWB mapping via sql or pl/sql.
Any type of clue will be highly appreciated.
Best RegardsHere is my bare-bones OMB SQL Library to allow you to do pure SQL calls from within OMB+. All I have ever used it for is to run queries, so I don't have a library procedure for calling a function, however if your function is SQL-callable (e.g. select my_func() from dual) then it would work. Either that or you'll want to augment this library to build a procedure that will call and return the results from a java preparedStatement. It's something I've been meaning to do, but haven't got around to it yet.
All you should need to do is save this as it's own tcl file and then source it at the top of your own script, or embed it into your script.
EDIT: Here is a page with some sample code on using java.sql.CallableStatement to call a Pl/SQL procedure from Java which should certainly do the trick for you in conjunction with the basic session control in my library.
http://www.exampledepot.com/egs/java.sql/CallProcedure.html
Cheers,
Mike
package require java
#file omb_sql_library.tcl
proc oracleConnect { serverName databaseName portNumber username password } {
# import required classes
java::import java.sql.Connection
java::import java.sql.DriverManager
java::import java.sql.ResultSet
java::import java.sql.SQLWarning
java::import java.sql.Statement
java::import java.sql.CallableStatement
java::import java.sql.ResultSetMetaData
java::import java.sql.DatabaseMetaData
java::import java.sql.Types
java::import oracle.jdbc.OracleDatabaseMetaData
# load database driver .
java::call Class forName oracle.jdbc.OracleDriver
# set the connection url.
append url jdbc:oracle:thin
append url :
append url $username
append url /
append url $password
append url "@"
append url $serverName
append url :
append url $portNumber
append url :
append url $databaseName
set oraConnection [ java::call DriverManager getConnection $url ]
set oraDatabaseMetaData [ $oraConnection getMetaData ]
set oraDatabaseVersion [ $oraDatabaseMetaData getDatabaseProductVersion ]
puts "Connected to: $url"
puts "$oraDatabaseVersion"
return $oraConnection
proc oracleDisconnect { oraConnect } {
$oraConnect close
proc oraJDBCType { oraType } {
#translation of JDBC types as defined in XOPEN interface
set rv "NUMBER"
switch $oraType {
"0" {set rv "NULL"}
"1" {set rv "CHAR"}
"2" {set rv "NUMBER"}
"3" {set rv "DECIMAL"}
"4" {set rv "INTEGER"}
"5" {set rv "SMALLINT"}
"6" {set rv "FLOAT"}
"7" {set rv "REAL"}
"8" {set rv "DOUBLE"}
"12" {set rv "VARCHAR"}
"16" {set rv "BOOLEAN"}
"91" {set rv "DATE"}
"92" {set rv "TIME"}
"93" {set rv "TIMESTAMP"}
default {set rv "OBJECT"}
return $rv
proc oracleQuery { oraConnect oraQuery } {
set oraStatement [ $oraConnect createStatement ]
set oraResults [ $oraStatement executeQuery $oraQuery ]
# The following metadata dump is not required, but will be a helpfull sort of thing
# if ever want to really build an abstraction layer
set oraResultsMetaData [ $oraResults getMetaData ]
set columnCount [ $oraResultsMetaData getColumnCount ]
set i 1
#puts "ResultSet Metadata:"
while { $i <= $columnCount} {
set fname [ $oraResultsMetaData getColumnName $i]
set ftype [oraJDBCType [ $oraResultsMetaData getColumnType $i]]
#puts "Output Field $i Name: $fname Type: $ftype"
incr i
# end of metadata dump
return $oraResults
# SAMPLE CODE to run a quick query and dump the results. #
#set oraConn [ oracleConnect myserver orcl 1555 scott tiger ]
#set oraRs [ oracleQuery $oraConn "select name, count(*) numlines from user_source group by name" ]
#for each row in the result set
#while {[$oraRs next]} {
#grab the field values
# set procName [$oraRs getString name]
# set procCount [$oraRs getInt numlines]
# puts "Program unit $procName comprises $procCount lines"
#$oraRs close
#oracleDisconnect $oraConnEdited by: zeppo on Nov 25, 2008 7:19 AM -
On making call to Oracle procedures from Java, Value becomes null on oracle
We are using some user defined Oracle data types in my Java/J2EE application
and some of them are Oracle collections(ex. VARRAY).
We are making a call to Procedures/Functions from Java, there are some
parameters of user defined data types declared in the
procedures/functions, from java the values are properly setting to these
user defined data type parameters and sending to Procedures.
We are not getting any exception at Java side and Oracle side and values
are becoming blank/null at oracle procedure side for the parameters of
user defined data types.
But when do the count of collection of user defined data type then it is
properly giving the size of collection(VARRAY).
When we are trying to read the values from the collection(VARRAY) it is
giving blank/null value and there is no exception.
Please let me know if you have any suggestion on this?user7671994 wrote:
When we are trying to read the values from the collection(VARRAY) it is
giving blank/null value and there is no exception.If you are talking about VARCHAR2 parameters of the objects - then you should add orai18n.jar to classpath. -
How to call oracle function from ejb3
i'm trying to call an oracle query-function from ejb3.
The oracle function:
create or replace FUNCTION getSecThreadCount(secId in NUMBER,avai in NUMBER)
RETURN SYS_REFCURSOR is cur SYS_REFCURSOR;
m_sql VARCHAR2(250);
BEGIN
m_sql:='select count(thrId) from thread where secId='|| secid||'
and thrAvai='|| avai;
open cur for m_sql;
return cur;
END;
I'v tried several ways to call it,but all failed:
1. the calling code:
public Object getSectionThreadCount(int secId,int avai){
Query query=manager.createNativeQuery("{call getSecThreadCount(?,?) }");
query.setParameter(1, secId);
query.setParameter(2, avai);
return query.getSingleResult();
but i got the exception:
Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query; nested exception is: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLException: ORA-06550: row 1, col 7:
PLS-00221: 'GETSECTHREADCOUNT' not procedure or not defined
ORA-06550: row 1, col 7:
PL/SQL: Statement ignored
2. the calling code:
@SqlResultSetMapping(name = "getSecThreadCount_Mapping")
@NamedNativeQuery(name = "getSecThreadCount",
query = "{?=call getSecThreadCount(:secId,:avai)}",
resultSetMapping = "getSecThreadCount_Mapping",
hints = {@QueryHint(name = "org.hibernate.callable", value = "true"),
@QueryHint(name = "org.hibernate.readOnly", value = "true")})
public Object getSectionThreadCount(int secId,int avai){
Query query=manager.createNamedQuery("getSecThreadCount");
query.setParameter("secId", secId);
query.setParameter("avai", avai);
return query.getSingleResult();
but i run into the exception:
Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query; nested exception is: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLException: lost in index IN or OUT parameter:: 3
By the way, i have successfully called the function from hibernate. And i use oracle 11g, JBoss5 RC1.
Could anyone tell me how to call the function from EJB3?
Thanks.Here's a working model:
package.procedure: (created in example schema scott)
CREATE OR REPLACE package body data_pkg as
type c_refcursor is ref cursor;
-- function that return all emps of a certain dept
function getEmployees ( p_deptId in number
return c_refcursor
is
l_refcursor c_refcursor;
begin
open l_refcursor
for
select e.empno as emp_id
, e.ename as emp_name
, e.job as emp_job
, e.hiredate as emp_hiredate
from emp e
where e.DEPTNO = p_deptId;
return l_refcursor;
end getEmployees;
end data_pkg;
/entity class:
package net.app.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedNativeQuery;
import javax.persistence.QueryHint;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@SuppressWarnings("serial")
@Entity
@Table (name="emp")
@SequenceGenerator(name = "EmployeeSequence", sequenceName = "emp_seq")
@NamedNativeQuery( name = "getEmpsByDeptId"
, query = "{ ? = call data_pkg.getEmployees(?)}"
, resultClass = Employee.class
, hints = { @QueryHint(name = "org.hibernate.callable", value = "true")
, @QueryHint(name = "org.hibernate.readOnly", value = "true")
public class Employee implements Serializable
@Id
@Column(name="emp_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EmployeeSequence")
private int id;
@Column(name="emp_name")
private String name;
@Column(name="emp_job")
private String job;
@Column(name="emp_hiredate")
private Date hiredate;
// constructor
public Employee (){}
// getters and setters
public int getId()
return id;
etc...session bean:
package net.app.entity;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import net.app.entity.Employee;
import net.app.iface.ScottAdmin;
@Stateless
public class ScottAdminImpl implements ScottAdmin
@PersistenceContext
private EntityManager entityManager;
@SuppressWarnings("unchecked")
public List<Employee> getEmployeesByDeptId(int deptId)
ArrayList<Employee> empList;
try
Query query = entityManager.createNamedQuery("getEmpsByDeptId");
query.setParameter(1, deptId);
empList = (ArrayList<Employee>) query.getResultList();
return empList;
catch (Exception e)
e.printStackTrace(System.out);
return null;
}client:
package net.app.client;
import java.util.List;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import net.app.entity.Employee;
import net.app.iface.ScottAdmin;
public class ScottClient
public static void main(String[] args)
try
// create local interface
InitialContext ctx = new InitialContext();
ScottAdmin adminInterface = (ScottAdmin) ctx.lookup("ScottAdminImpl/remote");
// select employees by deptno
int deptno = 20;
List<Employee> empList = adminInterface.getEmployeesByDeptId(deptno);
// output
System.out.println("Listing employees:");
for (Employee emp : empList)
System.out.println(emp.getId() + ": " + emp.getName() + ", " + emp.getJob() + ", " + emp.getHiredate());
catch (NamingException e)
e.printStackTrace(System.out);
}Basically you just ignore the refcursor outbound parameter.
This is a stored function, have yet to try outbound refcursor parameters in stored procedures...
Edited by: _Locutus on Apr 2, 2009 2:37 PM -
Calling Oracle function and Procedure using OCCI with in C++ code
Could any body send me the sample code to create and execute Oracle function and Procedure using OCCI concept in C++?.
Edited by: 788634 on Aug 16, 2010 4:09 AMHi Vishnu,
Yes, sure, you can create a PL/SQL procedure, function, package, package body, etc. from within an OCCI application. I would say that, generally, this is not the sort of activity a typical client application would perform unless there is some initialization/installation processes that need to happen. In any case, here is a simple demo showing how to create a stand alone procedure (in a real application I would use a package and body) that returns a ref cursor. The ref cursor is just a simple select of two columns in the hr.countries sample table. Of course, there is no error handling, object orientation, etc. in this demo - I wanted to keep the code as short and as simple as possible to illustrate the concept.
Regards,
Mark
#include <occi.h>
#include <iostream>
using namespace std;
using namespace oracle::occi;
int main(void)
// occi variables
Environment *env;
Connection *con;
Statement *stmt;
ResultSet *rs;
// database connection information
string user = "hr";
string passwd = "hr";
string db = "orademo";
// sql to create the procedure which returns a ref cursor as out parameter
// should be run as hr sample user or in a schema that has select privilege
// on the hr.countries table and a synonym (countries) that points to the
// hr.countries table
string sqlCreate =
"create or replace procedure get_countries(p_rc out sys_refcursor) as "
"begin"
" open p_rc for"
" select country_id, country_name from countries order by country_name; "
"end;";
// pl/sql anonymous block to call the procedure
string sqlCall = "begin get_countries(:1); end;";
// create a default environment for this demo
env = Environment::createEnvironment(Environment::DEFAULT);
cout << endl;
// open the connection to the database
con = env->createConnection(user, passwd, db);
// display database version
cout << con->getServerVersion() << endl << endl;
// create statement object for creating procedure
stmt = con->createStatement(sqlCreate);
// create the procedure
stmt->executeUpdate();
// terminate the statement object
con->terminateStatement(stmt);
// now create new statement object to call procedure
stmt = con->createStatement(sqlCall);
// need to register the ref cursor output parameter
stmt->registerOutParam(1, OCCICURSOR);
// call the procedure through the anonymous block
stmt->executeUpdate();
// get the ref cursor as an occi resultset
rs = stmt->getCursor(1);
// loop through the result set
// and write the values to the console
while (rs->next())
cout << rs->getString(1) << ": " << rs->getString(2) << endl;
// close the result set after looping
stmt->closeResultSet(rs);
// terminate the statement object
con->terminateStatement(stmt);
// terminate the connection to the database
env->terminateConnection(con);
// terminate the environment
Environment::terminateEnvironment(env);
// use this as a prompt to keep the console window from
// closing when run interactively from the IDE
cout << endl << "ENTER to continue...";
cin.get();
return 0;
} -
Problem calling Oracle function from Access 2007 / ADO
Hopefully, I'm posting this in the correct forum. I'm also posting on an Access forum as I'm not entirely sure where the issue lies.
I'm calling an Oracle function from Access 2007 using an ADO Command object.
The function takes three input parameters and has a return value and an output parameter. The output parameter is a BLOB, and the return value is varchar2 (either "T" or "N") based on the outcome of the function.
If I pass correct values to the function, I get the following error message (errs out on the command.execute line):
Run-time error '-2147467259 (80004005)':
[Oracle][ODBC][Ora]ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 1
Here's the function:
FUNCTION GET_ITEMREV_ATTACH(P_ORGANIZATION_ID IN NUMBER,
P_INVENTORY_ITEM_ID IN NUMBER,
P_REVISION IN VARCHAR2,
X_DRAWING OUT BLOB) RETURN VARCHAR2 IS
RESULT VARCHAR2(1);
BEGIN
RESULT := 'T';
BEGIN
SELECT L.FILE_DATA
INTO X_DRAWING
FROM FND_ATTACHED_DOCUMENTS AD,
MTL_ITEM_REVISIONS_B IR,
FND_DOCUMENTS_TL D,
FND_LOBS L
WHERE AD.ENTITY_NAME = 'MTL_ITEM_REVISIONS' AND
AD.PK1_VALUE = IR.ORGANIZATION_ID AND
AD.PK2_VALUE = IR.INVENTORY_ITEM_ID AND
AD.PK3_VALUE = IR.REVISION_ID AND
AD.CATEGORY_ID = 1001216 AND
D.DOCUMENT_ID = AD.DOCUMENT_ID AND
D.LANGUAGE = 'US' AND
L.FILE_ID = D.MEDIA_ID AND
IR.ORGANIZATION_ID = P_ORGANIZATION_ID AND
IR.INVENTORY_ITEM_ID = P_INVENTORY_ITEM_ID AND
IR.REVISION = P_REVISION;
EXCEPTION
WHEN OTHERS THEN
RESULT := 'N';
END;
RETURN(RESULT);
END GET_ITEMREV_ATTACH;
Here's the VB code I'm using to call the function:
Private Sub Command8_Click()
Dim CMD As New ADODB.Command
Dim conn As ADODB.Connection
Dim Param1 As ADODB.Parameter
Dim Param2 As ADODB.Parameter
Dim Param3 As ADODB.Parameter
Dim ParamBlob As ADODB.Parameter
Dim ParamReturn As ADODB.Parameter
Set conn = New ADODB.Connection
With conn
.ConnectionString = "Driver={Oracle in OraHome92};Dbq=OAPLY;UID=***;PWD=*******"
.CursorLocation = adUseClient
.Open
End With
Set CMD = New ADODB.Command
Set CMD.ActiveConnection = conn
CMD.CommandText = "immi_attach_pub.get_itemrev_attach"
CMD.CommandType = adCmdStoredProc
Set ParamReturn = CMD.CreateParameter("RESULT", adVarChar, adParamReturnValue, 1)
CMD.Parameters.Append ParamReturn
Set Param1 = CMD.CreateParameter("P_ORGANIZATION_ID", adInteger, adParamInput, 1, 6)
CMD.Parameters.Append Param1
Set Param2 = CMD.CreateParameter("P_INVENTORY_ITEM_ID", adInteger, adParamInput, 4, 5207)
CMD.Parameters.Append Param2
Set Param3 = CMD.CreateParameter("P_REVISION", adVarChar, adParamInput, 2, "04")
CMD.Parameters.Append Param3
Set ParamBlob = CMD.CreateParameter("X_DRAWING", adLongVarBinary, adParamOutput, 200000)
CMD.Parameters.Append ParamBlob
CMD.Execute , , adExecuteNoRecords *** this is where the error occurs
conn.Close
MsgBox CMD.Parameters("RESULT")
End Sub
I've tried using different data types for the varchar2 parameters (adVarChar, adBSTR, adChar) with no difference.
If I pass a bogus value for Param3...."'04'"...the function returns "N" indicating that it actually executed something. But, when I pass the correct value "04", it returns the above mentioned error.
I can execute the function in PL/SQL just fine, so I'm thinking there's something wrong with the parameters, datatype, or other definitions on the Access side.
Does anyone have any thoughts? I'm at a dead end with this. Sorry for the long post. Thank you.I tried your code with 11107 ODBC/client/database (but with a NULL output blob for convenience sake) and got no errors.
If you're using 92 ODBC/client, you may want to try upgrading to something more current, or at least getting the latest patch(9208) to see if that helps. Since it works for me I'm guessing it may be a resolved bug in that version.
Hope it helps,
Greg -
Hi
I have a simple oracle function
create or replace function doubleme(x in integer) return integer as
begin
return x*x;
end;
i am calling this function using DBAdapter in BPEL project. I am not able to get the return value from function. Its throwing timeout exception and when i see the process the return value is null. Please let me know if i am missing anything.I think you're going to have to use it as a string and use string comparison.
~Jer -
Pl-Sql Oracle Function Concurrency Issue
Hi All,
Issue - pl-sql Oracle Function performance issue, when muliple users are accessing the function
Detail -
Oracle 11g / Linux Server
I have developed a pl-sql oracle function to retrieve information from 3 tables, output as a particluar type array.
Single request is getting processed within 2.2 seconds, but when multiple request are sent concurrently <tested with 50>, time taken for each output is different.
BreakUp of Response times:-
8 messages took - 2.2 sec
+8 messages took - 4.4 sec
++8 messages took - 6.6 sec....etc
I'm looking for any DB tunning parameter, which will help to resolve this issue.
My only aim is to expose developed function to multiple users, who all can access it concurrently, but response should limit within 2.2 seconds.
Any thoughts + guidance is higly appreciated.
Thanks
Preetam SinghSupporting data insert statements:
=======================================================================================================================
REM INSERTING into EXPERTISE
Insert into EXPERTISE (USH_USER_NAME,USH_SKILL_SET1,USH_SKILL_SET2,USH_SKILL_SET3,USH_SKILL_SET4,USH_SKILL_SET5,USH_SKILL_SET6,USH_SKILL_SET7,USH_SKILL_SET8,USH_SKILL_SET9,USH_SKILL_SET10,USH_SKILL_SET11,USH_SKILL_SET12,USH_SKILL_SET13,USH_SKILL_SET14,USH_SKILL_SET15,USH_SKILL_SET16,USH_SKILL_SET17,USH_SKILL_SET18,USH_SKILL_SET19,USH_SKILL_SET20) values ('A','ENGLISH','FRENCH','HINDI',null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into EXPERTISE (USH_USER_NAME,USH_SKILL_SET1,USH_SKILL_SET2,USH_SKILL_SET3,USH_SKILL_SET4,USH_SKILL_SET5,USH_SKILL_SET6,USH_SKILL_SET7,USH_SKILL_SET8,USH_SKILL_SET9,USH_SKILL_SET10,USH_SKILL_SET11,USH_SKILL_SET12,USH_SKILL_SET13,USH_SKILL_SET14,USH_SKILL_SET15,USH_SKILL_SET16,USH_SKILL_SET17,USH_SKILL_SET18,USH_SKILL_SET19,USH_SKILL_SET20) values ('B',null,'GERMAN','CHINIESE','HINDI',null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
Insert into EXPERTISE (USH_USER_NAME,USH_SKILL_SET1,USH_SKILL_SET2,USH_SKILL_SET3,USH_SKILL_SET4,USH_SKILL_SET5,USH_SKILL_SET6,USH_SKILL_SET7,USH_SKILL_SET8,USH_SKILL_SET9,USH_SKILL_SET10,USH_SKILL_SET11,USH_SKILL_SET12,USH_SKILL_SET13,USH_SKILL_SET14,USH_SKILL_SET15,USH_SKILL_SET16,USH_SKILL_SET17,USH_SKILL_SET18,USH_SKILL_SET19,USH_SKILL_SET20) values ('C','ENGLISH',null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
=======================================================================================================================
==================================================================
REM INSERTING into WORKING
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('A','MON','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('A','TUE','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('A','WED',null,null);
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('A','THU','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('A','FRI','09:00','12:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('B','MON','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('B','TUE','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('B','WED','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('B','THU','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('B','FRI','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('C','MON',null,null);
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('C','TUE','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('C','WED','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('C','THU','09:00','18:00');
Insert into WORKING (NAME,WEEKDAY,DAYSTARTTIME,DAYENDTIME) values ('C','FRI','09:00','12:00');
==================================================================
=====================================================================================================================
REM INSERTING into SCHEDULE
Insert into SCHEDULE (APPOINTMENTDATE,APPOINTMENTSTART,APPOINTMENTEND,STATUS,NAME) values (to_timestamp('11-FEB-12 10.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-FEB-12 10.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-FEB-12 11.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),'MEETING','A');
Insert into SCHEDULE (APPOINTMENTDATE,APPOINTMENTSTART,APPOINTMENTEND,STATUS,NAME) values (to_timestamp('11-FEB-12 10.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-FEB-12 10.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-FEB-12 11.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),'TRAINING','B');
Insert into SCHEDULE (APPOINTMENTDATE,APPOINTMENTSTART,APPOINTMENTEND,STATUS,NAME) values (to_timestamp('13-FEB-12 10.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-FEB-12 10.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-FEB-12 11.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),'MEETING','A');
Insert into SCHEDULE (APPOINTMENTDATE,APPOINTMENTSTART,APPOINTMENTEND,STATUS,NAME) values (to_timestamp('11-FEB-12 10.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-FEB-12 11.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-FEB-12 11.30.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),'MEETING','B');
=====================================================================================================================
Edited by: 910614 on Feb 10, 2012 9:29 AM -
Getting the position in SQLLoader using oracle function
Hi. I have a problem to create .ctl file.
i have a oracle function to retrieve position
CREATE OR REPLACE FUNCTION "TEST_KEYFIELDS" (rec_type IN VARCHAR2,fieldName in varchar2)
RETURN VARCHAR2
AS
pos_result VARCHAR2(10) := null;
BEGIN
select '(' || field_start || ':' || (field_start + field_length -1) || ')' into pos_result from test_layout
where record_type=rec_type and field_name=fieldName;
RETURN pos_result;
END TEST_KEYFIELDS;
and this will return
(16:25)
my question is can i use this function and call it in my .ctl. so i don't have to hardcoded the position.
please help me.
TQAs yourself if you think it will be performant to call a query within a function for every row of data being processed in your loading rather than just hard-coding known values.
You can use functions if you really want, but I would suggest they are used sparingly. -
Get the current Oracle Function
Is it possible to obtain the current Oracle function from within the controller? From the OADBTransaction it is possible to obtain the current responsibility using the getResponsibilityId() method but there appears to be no way of identifying the current function. Any ideas?
Thanks for your reply however I am finding that (String)oapagecontext.getWebBeanValue(oawebbean, "FUNCTION_NAME") is coming back as null.
I have found that when a page is involved in a workflow that OANavigation.getItemAttrText(oapagecontext, "P_CALLED_FROM") does return the correct function name. -
Concatenate using SQL rather than Oracle functions Oracle 8i
Is it possible to concatenate field values using SQL alone and not an Oracle function
For the following dataset I would like the results to be the following
1 User_lastname1 2,7
2 User_lastname2 2,7
3 User_lastname3 2
4 User_lastname4 7
CREATE TABLE users
( user_id NUMBER(10)
, user_lastname VARCHAR2 (50)
, workgroup NUMBER(10)
INSERT ALL
INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 2)
INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 7)
INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 2)
INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 7)
INTO users(user_id, user_lastname, workgroup) VALUES (3, User_lastname3, 2)
INTO users(user_id, user_lastname, workgroup) VALUES (4, User_lastname4, 7)Maybe (provided a user is not a member of more than six workgroups)
select user_id,
user_lastname,
max(decode(rno,1,workgroup,null)) || max(decode(rno,2,','||workgroup,null)) ||
max(decode(rno,3,','||workgroup,null)) ||
max(decode(rno,4,','||workgroup,null)) ||
max(decode(rno,5,','||workgroup,null)) ||
max(decode(rno,6,','||workgroup,null)) string
from (select user_id,
user_lastname,
workgroup,
row_number() over (partition by user_id,user_lastname order by workgroup) rno
from users
group by user_id,
user_lastname
order by user_id,
user_lastnameor (provided a user is not a member of more than five workgroups)
select user_id,
user_lastname,
string
from (select user_id,
user_lastname,
row_number() over (partition by user_id,user_lastname order by workgroup) rno,
workgroup || lead(','||workgroup,1) over (partition by user_id,user_lastname order by workgroup) ||
lead(','||workgroup,2) over (partition by user_id,user_lastname order by workgroup) ||
lead(','||workgroup,3) over (partition by user_id,user_lastname order by workgroup) ||
lead(','||workgroup,4) over (partition by user_id,user_lastname order by workgroup) string
from users
where rno = 1
order by user_id,
user_lastnameRegards
Etbin -
Oracle function to strip HTML tags in data
Hi, may I know if there is any oracle function that can strip HTML tags from the data? I am currently using Oracle 9i. Therefore is unable to use the RegExp_Replace functionality provided by Oracle 10g.
Any help will be appreciated.
Thanks a lot!I found this function:
function str_html ( line in varchar2 ) return
varchar2 is
x varchar2(32767) := null;Let's hope whoever uses this doesn't want to deal with large XML's.
This question would have been better asked over in the XDB forum. All depends whether there is a schema available to describe the XML, what version of the database etc. With a schema, the schema could be registered into the Oracle 10g database and that used to create relational tables automatically, from where you can load in the XML files. Loads of information available on the XDB forum, most likely in the FAQ's on there. -
SQL Server Procedures to Oracle Functions
Is there an option in the Migration Assistant 1.2.0 that will convert the SQL Server procedures into Oracle Functions (rather than procedures)?
By default the T/SQL procedures return a integer status code. Our middle-tier requires calls to procedures to return a status code (integer), and I'd like the migration to modify the "procedure" to a "Function returning Integer" rather than Procedure.Thomas,
This is not an option currently. We will look into this for a future release. You could manually make the changes post conversion, prior to generation. As well as adding appropriate RETURN statements, you may want to add additional exception handling so the appropriate error is passed back.
Donal -
Hi frzz,
Can any one explain me how exactly HANA handles NULL values??
Best Regards,
Krishna.Hi Krishna,
You can use IFNULL for the SQL queries/script instead of ISNULL . Since ISNULL is binary function and will be mostly used for the CE Functions based Calc views.
Try using the same queries with IFNULL instead of ISNULL, it should work
Best Regards
Rahul Jha
Maybe you are looking for
-
Unable to import the excel template into form in HFM
Has any one came across this issue that I am facing now? I have a form in HFM and I exported the form to Excel and the export works fine. but when I import the excel template into form, it was not successful. I have 250 rows in the template. I delete
-
My phone says your purchase could not be completed?
My phone says the purchase cannot be completed and i need to buy something. What should i do? Someone please help!
-
I did create a standby database and shipping redo logs from primary, archives are applying at standby, but when i see the below command why it shows oldest online log sequence as zero and also next log sequence as zero please let me know the problem?
-
Is Adobe CS4 compatable with a mac 10.5.8?
I'm having troubles opening up Ai with my Mac 10.5.8. I open it and click File>New and the screen is still blank with occasional pop-ups about "plug-ins." Not quite sure what to do. Should I uninstall?
-
New Computer - missing menu items & where do I find my thumbnails?
I have just upgraded to a new computer and intalled Photoshop Elements 8 on it. I have a viewing problem on the organizer - all I can see on the header bar is a little arrow that drops down to file, edit, find etc. The other writing on the bar is m