Confused: Returning Simple User Defined Type (non-built-in)
Hi, hope you can straighten out a confused newbie! This is probably laughingly simple if you know how...
I just want my weblogic workshop web service to return an ordinary record-style object to my static client. I'm not sure what to do, I've already tried a few approaches...
If I use two services deployed on Weblogic Server everything works great. Weblogic server must handle the seriali/deseriali - zation for you.
So I tried to use the java proxy downloaded from the test page, but it doesn't contain all the classes needed.
I read the Weblogic help files which said to use autotype, which compiles but gives class cast exceptions running. I tried both automatic and manual with same error. Trying to import to Workshop gave me a "no handler defined error".
And I bought a book from Amazon about J2EE and Weblogic but it does not include a section on user defined types!
Am I supposed to use XMLBeans or something??? Please help!
Regards, Ry.
> but the requirement is not allowing me to do either with ref cursor or with
returning clause. Because, in .Net development area , we are restricted for
using Returning clause.
The following is a Bad Idea (tm) where PL/SQL is used to "return data" to the caller, be that via PL/SQL record types or collection types..Net ---[calls]-------> PL/SQL
PL/SQL ---[calls]-------> SQL
PL/SQL <--[data]--------- SQL
PL/SQL [buffers] data
.Net <--[buffer data]-- PL/SQLWhy?
Because PL/SQL is a poor choice for a buffer as the db cache buffer used by the SQL engine is a very advance and sophisticated cache and core to the Oracle RDBMS.
Ain't no way you can do that better in PL/SQL than SQL.
What is the typical client-server approach in Oracle?.Net ---[calls]-------> PL/SQL
PL/SQL [constructs ref cursor]
.Net <--[ref cursor]-- PL/SQL
.Net --[fetches]----> SQL [using ref cursor]A ref cursor is a pointer the "compiled and executable SQL program" in Oracle that PL/SQL constructed for .Net in this case. Each FETCH call using the ref cursor pointer, executes the cursor "program" and returns the next row (or set of rows when using bulk processing) to the client.
Similar Messages
-
Add column to user defined type based on existing table
Hello guys,
I am trying to compile my function which returns a user defined type based on existing table. Throughout the initializing process though my query returns one additional column - SCORE(1). Here is my package:
create or replace
PACKAGE STAFF_AGENCY_PKG AS
TYPE TYPE_SEEKER_TABLE IS TABLE OF TOSS.SEEKER%ROWTYPE;
FUNCTION GET_SEEKERS(IN_KEYWORD IN VARCHAR2)
RETURN TYPE_SEEKER_TABLE PIPELINED;
END STAFF_AGENCY_PKG;
create or replace
PACKAGE BODY STAFF_AGENCY_PKG
AS
FUNCTION GET_SEEKERS(IN_KEYWORD IN VARCHAR2)
RETURN TYPE_SEEKER_TABLE PIPELINED
IS
R_TBL TYPE_SEEKER_TABLE; -- to be returned
BEGIN
FOR R IN(
SELECT Seeker.SEEKER_ID,
Seeker.FIRSTNAME,
Seeker.LASTNAME,
Seeker.NATIONALITY,
Seeker.ISELIGIBLE,
Seeker.BIRTHDATE,
Seeker.ISRECIEVEEMAILS,
Seeker.HIGHESTDEGREE,
Seeker.ETHNICITY,
Seeker.GENDER,
Seeker.ISDISABILITY,
Seeker.DISABILITY,
Seeker.CV,
Seeker.PASSWORD,
Seeker.PREFFERED_CITY,
SEEKER.EMAIL,
SEEKER.JOB_PREFERENCES_ID,
SCORE(1)
FROM SEEKER Seeker
WHERE CONTAINS(CV, '<query>
<textquery lang="ENGLISH" grammar="context">' ||
GET_RELATED_CATEGORIES(IN_KEYWORD) ||
'</textquery>
<score datatype="INTEGER"/>
</query>', 1) > 0
LOOP
PIPE ROW(R); --Error(38,10): PLS-00382: expression is of wrong type
END LOOP;
RETURN;
END GET_SEEKERS;
END STAFF_AGENCY_PKG;
How do I need to amend my user type in order to suffice?
Oracle Release 11.2.0.1.0
Many thanks in advance!>
How do I need to amend my user type in order to suffice?
>
You will need to create two new TYPEs. One that has all of the columns of the TOSS.SEEKER table and the new SCORE column and then a TYPE that is a table of the first type.
See the Example 12-22 Using a Pipelined Table Function For a Transformation in the PL/SQl language reference
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm#i53120
Here is the first part
-- Define the ref cursor types and function
CREATE OR REPLACE PACKAGE refcur_pkg IS
TYPE refcur_t IS REF CURSOR RETURN employees%ROWTYPE;
TYPE outrec_typ IS RECORD (
var_num NUMBER(6),
var_char1 VARCHAR2(30),
var_char2 VARCHAR2(30));
TYPE outrecset IS TABLE OF outrec_typ;
FUNCTION f_trans(p refcur_t)
RETURN outrecset PIPELINED;
END refcur_pkg;
CREATE OR REPLACE PACKAGE BODY refcur_pkg IS
FUNCTION f_trans(p refcur_t)
RETURN outrecset PIPELINED IS
out_rec outrec_typ;
in_rec p%ROWTYPE;
BEGINModify
TYPE outrec_typ IS RECORD (
var_num NUMBER(6),
var_char1 VARCHAR2(30),
var_char2 VARCHAR2(30));
TYPE outrecset IS TABLE OF outrec_typ;to include all of the columns you need. Unfortunately you will have to manually list all of the columns of the TOSS.SEEKER table. If you expect to need this same structure in other places you should create them as SQL types instead of PL/SQL types.
This example should be enough to show you how to change your code to do something similar. -
Access result set in user define type of table
here is the situation. I have a stored procedure that dequeues messages of a AQ and passes them as an OUT parameter in a collection of a user defined type. The same type used to define the queues. The java code executes properly but seems like we don't/can't access the result set. We don't receive any erros but don't know how to access the results. I've included relevant parts of the problem.
I know this should be doable but........Can someone please tell us what we are doing wrong....thanks in advance.
-----create object type
create type evt_ot as object(
table_name varchar(40),
table_data varchar(4000));
---create table of object types.
create type msg_evt_table is table of evt_ot;
----create queue table with object type
begin
DBMS_AQADM.CREATE_QUEUE_TABLE (
Queue_table => 'etlload.aq_qtt_text',
Queue_payload_type => 'etlload.evt_ot');
end;
---create queues.
begin
DBMS_AQADM.CREATE_QUEUE (
Queue_name => 'etlload.aq_text_que',
Queue_table => 'etlload.aq_qtt_text');
end;
Rem
Rem Starting the queues and enable both enqueue and dequeue
Rem
EXECUTE DBMS_AQADM.START_QUEUE (Queue_name => 'etlload.aq_text_que');
----create procedure to dequeue an array and pass it OUT using msg_evt_table ---type collection.
create or replace procedure test_aq_q (
i_array_size in number ,
o_array_size out number ,
text1 out msg_evt_table) is
begin
DECLARE
message_properties_array dbms_aq.message_properties_array_t :=
dbms_aq.message_properties_array_t();
msgid_array dbms_aq.msgid_array_t;
dequeue_options dbms_aq.dequeue_options_t;
message etlload.msg_evt_table;
id pls_integer := 0;
retval pls_integer := 0;
total_retval pls_integer := 0;
ctr number :=0;
havedata boolean :=true;
java_exp exception;
no_messages exception;
pragma EXCEPTION_INIT (java_exp, -24197);
pragma exception_init (no_messages, -25228);
BEGIN
DBMS_OUTPUT.ENABLE (20000);
dequeue_options.wait :=0;
dequeue_options.correlation := 'event' ;
id := i_array_size;
-- Dequeue this message from AQ queue using DBMS_AQ package
begin
retval := dbms_aq.dequeue_array(
queue_name => 'etlload.aq_text_que',
dequeue_options => dequeue_options,
array_size => id,
message_properties_array => message_properties_array,
payload_array => message,
msgid_array => msgid_array);
text1 := message;
o_array_size := retval;
EXCEPTION
WHEN java_exp THEN
dbms_output.put_line('exception information:');
WHEN no_messages THEN
havedata := false;
o_array_size := 0;
end;
end;
END;
----below is the java code....
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Struct;
import oracle.jdbc.driver.OracleCallableStatement;
import oracle.jdbc.driver.OracleTypes;
public class TestOracleArray {
private final String SQL = "{call etlload.test_aq_q(?,?,?)}";//array size, var name for return value, MessageEventTable
private final String driverClass = "oracle.jdbc.driver.OracleDriver";
private final String serverName = "OurServerName";
private final String port = "1500";
private final String sid = "OurSid";
private final String userId = "OurUser";
private final String pwd = "OurPwd";
Connection conn = null;
public static void main(String[] args){
TestOracleArray toa = new TestOracleArray();
try {
toa.go();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
private void go() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
Class.forName(driverClass).newInstance();
String url = "jdbc:oracle:thin:@"+serverName+":"+port+":"+sid;
conn = DriverManager.getConnection(url,userId,pwd);
OracleCallableStatement stmt = (OracleCallableStatement)conn.prepareCall(SQL);
//set 1 input
stmt.setInt(1, 50);
//register out 1
stmt.registerOutParameter(2, OracleTypes.NUMERIC);
//register out 2
stmt.registerOutParameter(3, OracleTypes.ARRAY, "MSG_EVT_TABLE");
* This code returns a non-null ResultSet but there is no data in the ResultSet
* ResultSet rs = stmt.executeQuery();
* rs.close();
* Tried all sorts of combinations of getXXXX(1);
* All return the same error Message: Invalid column index
* So it appears that the execute statment returns no data.
stmt.execute();
Struct myObject = (Struct)stmt.getObject(1);
stmt.close();
conn.close();
}Hi,
Sorry but I'd refer you to the following sections (and code samples/snippets) in my book:
Mapping User-Defined Object Types (AD) to oracle.sql.STRUCT in section 3.3, shows how to pass user defined types as IN, OUT,IN/OUT
JMS over Streams/AQ in the Database: shows how to consume AQ
message paylod in section 4.2.4
CorporateOnine, in section 17.2, show how to exchanges user defined type objects b/w AQ and JMS
All these will hopefully help you achieve what you are trying to do.
Kuassi -
Oracle 11g AQ : problem enqueue user-defined type with varchar2 attribute
Hello.
I have a problem enqueuing a user-defined type to the queue on Oracle 10g.
I'm using jdbc driver (ojdbc5.jar, version 11.1.0.6.0) as they provide oracle.jdbc.aq package.
The type is following:
CREATE OR REPLACE TYPE FIXED_T5 AS OBJECT
(id integer,
label varchar2(100),
code integer,
today date
)I have created a java class for this type with jpub utility supplied with oracle 11g client package:
jpub -user=scott/tger -url=jdbc:oracle:thin:@host:sid-sql=FIXED_T5:ru.invito.FixedType -compile=falseIt generated FixedType.java and FixedTypeRef.java files. Don't understand why i need the latter (FixedTypeRef).
Then in test app:
package ru.invito;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Properties;
import java.util.UUID;
import junit.framework.TestCase;
import oracle.jdbc.aq.AQAgent;
import oracle.jdbc.aq.AQEnqueueOptions;
import oracle.jdbc.aq.AQFactory;
import oracle.jdbc.aq.AQMessage;
import oracle.jdbc.aq.AQMessageProperties;
import oracle.jdbc.aq.AQEnqueueOptions.DeliveryMode;
import oracle.jdbc.aq.AQEnqueueOptions.VisibilityOption;
import oracle.jdbc.driver.OracleConnection;
import oracle.jdbc.driver.OracleDriver;
import oracle.sql.Datum;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class AqTest extends TestCase {
protected Log logger = LogFactory.getLog(getClass());
public void testEnqueue() throws Exception {
OracleDriver dr = new OracleDriver();
Properties prop = new Properties();
prop.setProperty("user", Config.USERNAME);
prop.setProperty("password", Config.PASSWORD);
OracleConnection connection = (OracleConnection) dr.connect(Config.JDBC_URL, prop);
assertNotNull(connection);
connection.setAutoCommit(false);
enqueueMessage(connection, "INVITO.FIXED_T5Q", null);
connection.commit();
private void enqueueMessage(OracleConnection conn, String queueName, AQAgent[] recipients) throws SQLException,
IOException {
logger.debug("----------- Enqueue start ------------");
AQMessageProperties props = makeProps(queueName);
AQMessage mesg = AQFactory.createAQMessage(props);
String msqText = String.format("Hello, %s!", queueName);
FixedType data = createData(36, msqText);
Datum d = data.toDatum(conn);
STRUCT s = (STRUCT) d;
debugStruct("s", s);
String toIdStr = byteBufferToHexString(s.getDescriptor().getOracleTypeADT().getTOID(), 20);
logger.debug("s.toIdStr: " + toIdStr);
StructDescriptor sd = StructDescriptor.createDescriptor("INVITO.FIXED_T5", conn);
logger.debug("sd.toXMLString(): " + sd.toXMLString());
mesg.setPayload(s);
AQEnqueueOptions opt = makeEnqueueOptions();
logger.debug("sending............");
// execute the actual enqueue operation:
conn.enqueue(queueName, opt, mesg);
debugMessageId(mesg);
logger.debug("----------- Enqueue done ------------");
private void debugMessageId(AQMessage mesg) throws SQLException {
byte[] mesgId = mesg.getMessageId();
if (mesgId == null) {
throw new IllegalStateException("message id is NULL");
String mesgIdStr = byteBufferToHexString(mesgId, 20);
logger.debug("Message ID from enqueue call: " + mesgIdStr);
* @return
* @throws SQLException
private FixedType createData(int ID, String label) throws SQLException {
FixedType data = new FixedType();
data._struct.setNChar(1);// initializes the flag for 'label' field
data.setId(ID);
data.setLabel(label);
data.setCode(1);
Date today = new Date();
data.setToday(new Timestamp(today.getTime()));
return data;
* @param string
* @param s
* @throws SQLException
private void debugStruct(String string, STRUCT s) throws SQLException {
logger.debug(s + ".debugString(): " + s.debugString());
logger.debug(s + "s.dump(): " + s.dump());
* @return
* @throws SQLException
private AQAgent makeAgent() throws SQLException {
AQAgent ag = AQFactory.createAQAgent();
ag.setName("AQ_TEST");
String agentAddress = null;
try {
agentAddress = InetAddress.getLocalHost().getHostAddress();
catch (UnknownHostException e) {
logger.error("cannot resolve localhost ip address. will not set it as AQ Agent address");
agentAddress = "NA";
ag.setAddress(agentAddress);
return ag;
private AQMessageProperties makeProps(String queueName) throws SQLException {
final String EXCEPTION_Q_TEMPLATE = "AQ$_%sT_E";
final int DEFAULT_DELAY = 0;
final int DEFAULT_EXPIRATION = -1;
final int DEFAULT_PRIORITY = 0;
AQMessageProperties propeties = AQFactory.createAQMessageProperties();
propeties.setCorrelation(UUID.randomUUID().toString());
propeties.setDelay(DEFAULT_DELAY);
propeties.setExceptionQueue(String.format(EXCEPTION_Q_TEMPLATE, queueName));
propeties.setExpiration(DEFAULT_EXPIRATION);
propeties.setPriority(DEFAULT_PRIORITY);
// propeties.setRecipientList(null);//should not set
propeties.setSender(makeAgent());
return propeties;
* @return
* @throws SQLException
private AQEnqueueOptions makeEnqueueOptions() throws SQLException {
AQEnqueueOptions opt = new AQEnqueueOptions();
opt.setRetrieveMessageId(true);
// these are the default settings (if none specified)
opt.setDeliveryMode(DeliveryMode.PERSISTENT);
opt.setTransformation(null);
opt.setVisibility(VisibilityOption.ON_COMMIT);
return opt;
* Form the AQ reference
* @param buffer
* @param maxNbOfBytes
* @return
private static final String byteBufferToHexString(byte[] buffer, int maxNbOfBytes) {
if (buffer == null)
return null;
int offset = 0;
StringBuffer sb = new StringBuffer();
while (offset < buffer.length && offset < maxNbOfBytes) {
String hexrep = Integer.toHexString((int) buffer[offset] & 0xFF);
if (hexrep.length() == 1)
hexrep = "0" + hexrep;
sb.append(hexrep);
offset++;
String ret = sb.toString();
return ret;
}The output is following:
[main] 2008-07-03 19:09:49,863 DEBUG [ru.invito.AqTest] - ----------- Enqueue start ------------
[main] 2008-07-03 19:09:50,348 DEBUG [ru.invito.AqTest] - [email protected](): name = INVITO.FIXED_T5 length = 4 attribute[0] = 36 attribute[1] = Hell
o, INVITO.FIXED_T5Q! attribute[2] = 1 attribute[3] = 2008-07-03 19:09:49.0
[main] 2008-07-03 19:09:50,363 DEBUG [ru.invito.AqTest] - [email protected](): name = INVITO.FIXED_T5
length = 4
ID = 36
LABEL = Hello, INVITO.FIXED_T5Q!
CODE = 1
TODAY = 2008-07-03 19:09:49.0
[main] 2008-07-03 19:09:50,363 DEBUG [ru.invito.AqTest] - s.toIdStr: 507ccce5b6e9f572e040007f01007203
[main] 2008-07-03 19:09:50,363 DEBUG [ru.invito.AqTest] - sd.toXMLString(): <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StructDescriptor sqlName="INVITO.FIXED_T5" >
<OracleTypeADT sqlName="INVITO.FIXED_T5" typecode="0" tds_version="1"
is_embedded="false" is_top_level="true" is_upt="false" finalType="true" subtype="false">
<attributes>
<attribute name="ID" type="INTEGER" >
<OracleType typecode="2" />
</attribute>
<attribute name="LABEL" type="VARCHAR2" >
<OracleType typecode="12" />
</attribute>
<attribute name="CODE" type="INTEGER" >
<OracleType typecode="2" />
</attribute>
<attribute name="TODAY" type="DATE" >
<OracleType typecode="0" />
</attribute>
</attributes>
</OracleTypeADT>
</StructDescriptor>
[main] 2008-07-03 19:09:50,379 DEBUG [ru.invito.AqTest] - sending............
[main] 2008-07-03 19:09:50,395 DEBUG [ru.invito.AqTest] - Message ID from enqueue call: 511ff143bd4fa536e040007f01003192
[main] 2008-07-03 19:09:50,395 DEBUG [ru.invito.AqTest] - ----------- Enqueue done ------------But when dequeueing the 'label' attribute is lost:
DECLARE
dequeue_options DBMS_AQ.dequeue_options_t;
message_properties DBMS_AQ.message_properties_t;
message_handle RAW(16);
message fixed_t5;
BEGIN
dequeue_options.navigation := DBMS_AQ.FIRST_MESSAGE;
DBMS_AQ.DEQUEUE(
queue_name => 'fixed_t5q',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
DBMS_OUTPUT.PUT_LINE('ID : '||message.id);
DBMS_OUTPUT.PUT_LINE('Label: '||message.label);
DBMS_OUTPUT.PUT_LINE('Code : '||message.code);
DBMS_OUTPUT.PUT_LINE('Today: '||message.today);
COMMIT;
END;
ID : 36
Label:
Code : 1
Today: 03.07.08
Could anyone tell me what is wrong with the setup/code?
Why 'label' not saved in queue, though i saw it is not empty in STRUCT?Thank you for the reply!
I have enqueued:
[main] 2008-07-04 15:30:30,639 DEBUG [ru.invito.UserDefinedTypeAqTest$1] - [email protected](): name = INVITO.FIXED_T5
length = 4
ID = 41
LABEL = Hello, INVITO.FIXED_T5Q!
CODE = 1
TODAY = 2008-07-04 15:30:30.0and in table (select * from FIXED_T5QT) the 'label' is blank:
Q_NAME FIXED_T5Q
MSGID 51310809B5EA3728E040007F01000C79
CORRID b8f38fd3-4fa6-4e0f-85d1-2440d02d655e
PRIORITY 0
STATE 0
DELAY
EXPIRATION
TIME_MANAGER_INFO
LOCAL_ORDER_NO 0
CHAIN_NO 0
CSCN 0
DSCN 0
ENQ_TIME 04.07.2008 15:28:44
ENQ_UID INVITO
ENQ_TID 4012
DEQ_TIME
DEQ_UID
DEQ_TID
RETRY_COUNT 0
EXCEPTION_QSCHEMA AQ$_INVITO
EXCEPTION_QUEUE FIXED_T5QT_E
STEP_NO 0
RECIPIENT_KEY 0
DEQUEUE_MSGID
SENDER_NAME AQ_TEST
SENDER_ADDRESS 10.1.1.137
SENDER_PROTOCOL
USER_DATA.ID 41
USER_DATA.LABEL
USER_DATA.CODE 1
USER_DATA.TODAY 04.07.2008 15:30:30I must point to a strange thing: when the FixedType instance is created (via new operator) and then the setLabel("....") called as:
FixedType data = new FixedType();
// hack: proper initialization for 'label' field
data._struct.setNChar(1);
data.setId(ID);
data.setLabel(label);
data.setCode(1);
Date today = new Date();
data.setToday(new Timestamp(today.getTime()));
Datum d = data.toDatum(connection);
STRUCT s = (STRUCT) d;
logger.debug(s + ".debugString(): " + s.debugString());
logger.debug(s + ".dump(): " + s.dump());and if i comment line (data._struct.setNChar(1);) the debug messages for created STRUCT also shows empty value for label.
But if i explicitly call data._struct.setNChar(1) then debug contains the label i defined in call to the setLabel method. -
Selecting Columns with User Defined Types... in PHP
I've looked all over google and this forum and can't find anything about this... here's what I've got:
a User Defined Type:
CREATE TYPE "ADDRESS" AS OBJECT (
ADDRESS VARCHAR2(256),
COUNTRY VARCHAR2(256),
STATE VARCHAR2(256),
SUBURB VARCHAR2(256),
TOWNCITY VARCHAR2(256)
and it is used in a column in one of my tables:
CREATE TABLE "SUPPLIERS" (
"ID" NUMBER,
"USER_ID" NUMBER,
"NAME" VARCHAR2(50),
"ADDRESS" "ADDRESS"
so that column "address" is of type "address". I am then able to insert a row using:
INSERT INTO "SUPPLIERS" VALUES(1,1,'name',ADDRESS('address','country','state','suburb','town city'));
and that all works as expected. I can select the data using iSqlPlus and get the result I expect;
ADDRESS('address', 'country', 'state', 'suburb', 'town city')
So here's the problem. I cannot reterieve the data as expected, using PHP. If I make a select statement on the table that excludes the ADDRESS column I get the results as expected. If the ADDRESS column is included I get an error when fetching the row:
ORA-00932: inconsistent datatypes: expected CHAR got ADT
I'm assuming this is because the the cell cannot be cast to a string. How can I select the row so that the ADDRESS column is returned as an object? Can I even? If I can't, I don't see the use of Object Data Types... :(
I have found that I can select a field of the type using:
SELECT t.ADDRESS.TOWNCITY FROM SUPPLIERS t;
But this is not ideal, because the whole idea was that I could (potentially) change the format for, in my example, an address, and not need to alter my SQL statements.
Any ideas??PHP OCI8 can currently only bind simple types. Here are two possible
solutions.
-- cj
create or replace type mytype as object (myid number, mydata varchar2(20));
show errors
create or replace type mytabletype as table of mytype;
show errors
create or replace procedure mycreatedata1(outdata out mytabletype) as
begin
outdata := mytabletype();
for i in 1..10 loop
outdata.extend;
outdata(i) := mytype(i, 'some name'||i);
end loop;
end;
show errors
-- Turn the data into a ref cursor (but PHP OCI8 doesn't use prefetching for ref cursors)
create or replace procedure mywrapper1(rcemp out sys_refcursor) as
data mytabletype;
begin
mycreatedata1(data);
open rcemp for select * from table(cast(data as mytabletype));
end mywrapper1;
show errors
-- Turn the data into two collections
-- This might be faster than returning a ref cursor because you can
-- use oci_bind_array_by_name() on each parameter.
create or replace procedure mywrapper2(pempno out dbms_sql.NUMBER_table, pename out dbms_sql.VARCHAR2_table) as
data mytabletype;
begin
mycreatedata1(data);
select myid, mydata
bulk collect into pempno, pename
from table(cast(data as mytabletype));
end mywrapper2;
show errorsThen in PHP you could do:
// Use a Ref Cursor
$s = oci_parse($c, "begin mywrapper1(:myid); end;");
$rc = oci_new_cursor($c);
oci_bind_by_name($s, ':myid', $rc, -1, OCI_B_CURSOR);
oci_execute($s);
oci_execute($rc);
oci_fetch_all($rc, $res);
var_dump($res);
// Use Collections
$s = oci_parse($c, "begin mywrapper2(:myid, :mydata); end;");
oci_bind_array_by_name($s, ":myid", $myid, 10, -1, SQLT_INT);
oci_bind_array_by_name($s, ":mydata", $mydata, 10, 20, SQLT_CHR);
oci_execute($s);
var_dump($myid);
var_dump($mydata); -
Guys i am using Entity Framework 5 code first (I am not using edmx) with Oracle and all works good, Now i am trying to get data from stored procedure which is under package but stored procedure have out param which is user define type, Now my question is
how i will call stored procedure from entity framework
Thanks in advance.I agree with you, but issue is we have lots of existing store procedure, which we need to call where damn required. I am sure those will be few but still i need to find out.
If you think you are going to get existing MS Stored Procedures or Oracle Packages that had nothing to do with the ORM previously to work that are not geared to do simple CRUD operations with the ORM and the database tables, you have a rude awakening
coming that's for sure. You had better look into using ADO.NET and Oracle Command objects and call those Oracle Packages by those means and use a datareader.
You could use the EF backdoor, call Oracle Command object and use the Packages, if that's even possible, just like you can use MS SQL Server Stored Procedures or in-line T-SQL via the EF backdoor.
That's about your best shot.
http://blogs.msdn.com/b/alexj/archive/2009/11/07/tip-41-how-to-execute-t-sql-directly-against-the-database.aspx -
Table OF user defined type in c#
Hello
I am running C# using Oracle (PL/SQL, provider ODP.NET
11.1.0.6.20) and I have a procedure which at the moment returns a table of
records. The code below demonstrates this.
TYPE R_OutData_tab IS RECORD ( ... );
TYPE OutData_tab IS TABLE OF R_OutData_tab INDEX BY BINARY_INTEGER;
PROCEDURE PROPERTY_GET (tOutData OUT <packagename>.OutData_tab);
Since .NET doesn't support Oracle records I'm looking into rewriting the
procedure so that it returns a table of a user defined type instead. The
code below demonstrates this.
create type person_type as object (name varchar2(30), address varchar2(60),
age varchar2(3));
TYPE person_table IS TABLE OF odp_obj1_sample_person_type;
PROCEDURE PERSONS_GET(out_persons OUT person_table);
I know how to handle a single user-defined type in .NET returned from a
Oralce procedure but what I need to do now is to receive a or pass table of a user
defined type using procedure. Is this supported in .NET?Dear ,
I have posted a similar kind of reply in one of the thread which may help u defining the User Defined Tabel /Filed .Just check this Out :
For cm25/CM21 : Assuming that you have all the other set up for Capacity Requirement in place , please note the belwo steps for layout design for CM25 OR cm21 or cm22( all you will be used same overall profile )
1.Make sure that you have proper Overall profile defined in OPD0-Define Overall profile .Here u will define Time Profile , Startegy prfoile . Lay out Profile etc .
2.To paint your layout your soultion is to Goto -CY38-Pop down the menu -Select the Lay out Key which have been used as lay out -Goto Change Mode (Pencil symbol)-Now you will find the fields are high ligheted as per CM25 dipaly in a sequnce -You can un chekcde the Filed like Operation , Operation text , Setup what ever you do not want to show in Order Pool and Hit SAVE butotn and come back .
CM25 --> Settings --> Display Profiles --> Planning tab.profile --> I01 --> Layout ID ( Example : 'SAPSFCLA05') which is Main Capacity Lay out id .
If you goto CY38-Pop down the menu -You will find Main Capcitity Lay out Id : Example SAPSFCAS01 -Enter this lay out and chenage accordingly as I have explained in above
Once you save this , then go back to CM25 and execute with coupe of work centres to check how is the order pool looks now .
Refer this threade for Layout Id and option which u may need for CM25 front end
Exception messages in CM21 or CM25
I hope this should work
Regards -
We have recently updated our libraries to the latest version (2.102.2.20) - and have lost access to the critical objects and methods that were accessing our User Defined Types on Oracle.
In particular, this code:
OracleUdtDescriptor descriptor = OracleUdtDescriptor.GetOracleUdtDescriptor((OracleConnection)conn, "MY_USER.MYTYPE");
OracleArray items = new OracleArray(descriptor);
foreach (string s in testArrayItems)
items.Append(s);
IDbDataParameter itemsParam = cmd.OracleParameters.Add("items", OracleDbType.VArray, items, ParameterDirection.Input);
simply doesn't work anymore. The 'OracleUdtDescriptor' and 'OracleArray' references no longer exist. This has brought all development on a critical application to a halt. (Doesn't it always.)
How can I get the same functionality using the new version (2.102.2.20) of the Oracle.DataAccess library?Hi,
Here's what I was referring to... say you wanted to execute the same procedure from PLSQL via an anonymous block. Execute the same anonymous block via ODP.NET.
Here's a simple dumb example that passes an object type to a stored procedure, hope it helps. Hokey example, but hopefully points out what I was trying to say.
Greg
SQL
========
create or replace type person_typ as object (name varchar2(50), age number(4))
create table person_tab(col1 number, col2 person_typ);
create or replace procedure insert_person_proc(v1 in number, v2 in person_typ) as
begin
insert into person_tab values(v1,v2);
end;
You could execute that via PLSQL as follows
=================================
declare
myperson person_typ;
begin
myperson := person_typ('melody',5);
insert_person_proc(1,myperson);
end;
/And do the same thing via ODP.NET
=============================
using System;
using System.Data;
using Oracle.DataAccess.Client;
class Program
static void Main(string[] args)
using (OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger"))
con.Open();
using (OracleCommand cmd = new OracleCommand("",con))
string strsql = "declare " +
"myperson person_typ; " +
"begin " +
"myperson := person_typ(:1,:2); " +
"insert_person(:3,myperson); " +
"end; ";
cmd.CommandText = strsql;
cmd.Parameters.Add(new OracleParameter("", "Melody"));
cmd.Parameters.Add(new OracleParameter("", 5));
cmd.Parameters.Add(new OracleParameter("", 1));
cmd.ExecuteNonQuery();
} -
How to convert Collection to user defined type in db
Hello All,
I am using Apex 4.1.0.00.32 and Oracle 11g.
I have page process to store the user selected rows (keys) in a collection as follows:
declare
temp varchar2(4000);
vrow number;
begin
apex_collection.CREATE_OR_TRUNCATE_COLLECTION('SELECTED_PERSONS');
IF (apex_application.g_f32.COUNT > 0) THEN
FOR ii IN 1 .. htmldb_application.g_f32.COUNT
LOOP
vrow := apex_application.g_f32(ii);
APEX_COLLECTION.ADD_MEMBER('SELECTED_PERSONS', apex_application.g_f30(vrow));
END LOOP;
END IF;
end;I need to call a database function which takes an user defined type VC_ARRAY_1 defined as:
create or replace TYPE "VC_ARRAY_1" AS TABLE OF VARCHAR2(4000) How do I convert the collection to VC_ARRAY_1, so that I can call the db function?
Thanks,
RoseHi Joel,
Yes, the collection contains the person_ids. But, I am selecting from a function which returns a pipelined table. In Oracle Database, few user defined types and functions are defined as given below:
create or replace TYPE "VC_ARRAY_1" as table of varchar2(4000)
create or replace FUNCTION "GET_ARRAY" ( p_array IN varchar2, p_delimiter IN varchar2 default ':') return VC_ARRAY_1 PIPELINED
create or replace TYPE "AFFECTED_INDIVIDUAL" as object("PERSONKEY" VARCHAR2(4000), "FIRST_NAME" VARCHAR2(4000), "LAST_NAME" VARCHAR2(4000)… more variables)
create or replace TYPE "AFF_IND_TAB" as table of "AFFECTED_INDIVIDUAL"
create or replace FUNCTION GET_AFF_INDIVIDUALS(personKeys IN VC_ARRAY_1) return AFF_IND_TAB PIPELINEDThe function GET_AFF_INDIVIDUALS uses several tables and returns pipelined table. In Apex, I have a SQL query that feeds the Report query.
select * from table (get_aff_individuals(get_array(:F_SELECTED_PERSONS, ',')))The application item F_SELECTED_PERSONS is a varchar2 that contains comma separated person ids. I want to replace the application item with Apex collection. Initially, I thought that I can convert the apex collection to an array of vc_array_1.
Thanks for your time and help.
Rose -
Problem calling stored procedure with user-defined type of input parameters
Hi,
I have to call a stored procedure with IN parameters, but these are user-defined types of input parameters.
function fv_createnews (
pit_groups in T_APPLICATION_USER_GROUPS,
pit_documents in T_DOCUMENTS
return varchar2;
TYPE T_APPLICATION_USER_GROUPS IS
TABLE OF varchar2(500)
INDEX BY binary_integer;
TYPE T_DOCUMENT IS record (
name varchar2(256)
,url varchar2(1024)
,lang varchar2(30)
,foldername varchar2(150)
TYPE T_DOCUMENTS IS
TABLE OF T_DOCUMENT
INDEX BY binary_integer;
How can I do this using the TopLink 10.1.3 API.
I already found following related posts, but I still can' t make it up:
Using VARRAYs as parameters to a Stored Procedure
Pass Object as In/Out Parameter in Stored Procedure
Or do I have to create my own PreparedStatement for this special stored procedure call using Java and Toplink?As the related posts suggest, you will need to use direct JDBC code for this.
Also I'm not sure JDBC supports the RECORD type, so you may need to wrap your stored functions with ones that either flatten the record out, or take OBJECT types. -
How to execute function takes user defined type parameters as input &output
Hi All,
I want to execute a function which takes user defined type as input & output parameters. But i don't know how to execute that function in pl/sql statements.
CREATE TYPE T_INPUT AS OBJECT
USER VARCHAR2(255),
APPLICATION VARCHAR2(255),
REFERENCE VARCHAR2(30)
) NOT FINAL;
CREATE TYPE T_ID UNDER T_INPUT
E_ID VARCHAR2 (50),
CODE VARCHAR2 (3),
SERVICE VARCHAR2 (10),
C_TYPE VARCHAR2 (1)
) NOT FINAL;
CREATE TYPE T_OUTPUT AS OBJECT
R_STATUS NUMBER(10),
E_DESC_LANG_1 VARCHAR2(1000),
E_DESC_LANG_2 VARCHAR2(1000),
A_REFERENCE VARCHAR2(30)
) NOT FINAL;
CREATE TYPE T_INFO UNDER T_OUTPUT
E_INFO XMLTYPE
CREATE FUNCTION Get_Dtls
I_DETAILS IN T_ID,
O_DETAILS OUT T_INFO
RETURN NUMBER AS
END;
Here
1. T_ID is an input parameter which is a combination of T_ID + T_INPUT,
2. T_INFO is an output parameter which is a combination of T_INFO + T_OUTPUT.
Here i'll assign the T_ID values.
--- T_INPUT values
USER = "admin";
APPLICATION = "test";
REFERENCE = "null";
---- T_ID values
E_ID = "1234";
CODE = "TTT";
SERVICE = "NEW";
C_TYPE = "P";
Now i want to execute Get_Dtls function with T_ID,T_INFO parameters in pl/sql statements.
I want to catch the E_INFO value from T_INFO type.
How can i Do this ?
Pls Help. Thanxs in advance.
Anil.I am very new to this. New to Oracle, PL/SQL, OO programming or testing?
set serveroutput on
declare
tst_obj ctype;
begin
tst_obj := pkg.proc(11);
dbms_output.put_line('id='||tst_obj.id||'::code='||tst_obj.code||'::usage='||tst_obj.usage);
end;
/Generally I disapprove of the use of DBMS_OUTPUT (for just about anything) but it is sufficient to demonstrate the basic principle.
Really you should start using proper testing practices, ideally with an automated test harness like QUTE.
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/ -
Create user defined type under SQL type
Hello guys,
I have a table PART_NEEDED and a table function which returns table of PART_NEEDED%ROWTYPE. This works fine but if I try to create new user defined type with with the same attributes as PART_NEEDED and pipe the rows into table of that type I am getting an inconsistency of types error - Error(30,16): PLS-00382: expression is of wrong type.
Please refer to the script below. I appreciate any help!
CREATE TABLE "TOSS"."PART_NEEDED"
"PART_NEEDED_ID" NUMBER NOT NULL ENABLE,
"TYPE_OF_PART_NEEDS_ID" NUMBER,
"TYPE_OF_PART_IS_NEEDED_ID" NUMBER,
"AMOUNT" NUMBER
SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT
TABLESPACE "USERS" ;
CREATE OR REPLACE TYPE "TYPE_PART_NEEDED" AS OBJECT
ID NUMBER,
PART_ID NUMBER,
SUB_PART_ID NUMBER,
AMOUNT NUMBER
create or replace package KOLEV_ADMIN_PKG as
TYPE TYPE_PART_NEEDED_TBL IS TABLE OF TOSS.TYPE_PART_NEEDED; -- if the type here is PART_NEEDED%ROWTYPE it works perfectly fine
FUNCTION GET_SUBPARTS (IN_PART_ID IN NUMBER)
RETURN TYPE_PART_NEEDED_TBL PIPELINED;
end;
CREATE OR REPLACE PACKAGE BODY "KOLEV_ADMIN_PKG" AS
FUNCTION GET_SUBPARTS (IN_PART_ID IN NUMBER)
RETURN TYPE_PART_NEEDED_TBL PIPELINED
IS
R_TBL TYPE_PART_NEEDED_TBL; -- To be returned
BEGIN
FOR R IN (
WITH
SUBPARTS(ID, PART_ID, SUBPART_ID, AMOUNT) AS
SELECT PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT
FROM PART_NEEDED
WHERE TYPE_OF_PART_NEEDS_ID = IN_PART_ID
UNION ALL
SELECT PN.PART_NEEDED_ID, PN.TYPE_OF_PART_NEEDS_ID, PN.TYPE_OF_PART_IS_NEEDED_ID, PN.AMOUNT
FROM SUBPARTS SP, PART_NEEDED PN
WHERE PN.TYPE_OF_PART_NEEDS_ID = SP.SUBPART_ID
SELECT SP.ID, SP.PART_ID, SP.SUBPART_ID, SP.AMOUNT
FROM SUBPARTS SP
ORDER BY PART_ID
LOOP
PIPE ROW(R); -- Error(30,16): PLS-00382: expression is of wrong type
END LOOP;
RETURN;
END GET_SUBPARTS;
END "KOLEV_ADMIN_PKG";
INSERT INTO "TOSS"."PART_NEEDED" (PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT) VALUES ('4', '2', '3', '2')
INSERT INTO "TOSS"."PART_NEEDED" (PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT) VALUES ('5', '3', '1', '2')
INSERT INTO "TOSS"."PART_NEEDED" (PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT) VALUES ('3', '2', '1', '4')
INSERT INTO "TOSS"."PART_NEEDED" (PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT) VALUES ('17', '3', '4', '1')
Database Release 11.2.0.1.0
I want this functionality because I need to make some joins and add descriptions for each part. Now this table PART_NEEDED contains only IDs - many to many.
Regards!
Edited by: Todor Kolev on Mar 3, 2012 12:47 PMCREATE OR REPLACE
PACKAGE BODY KOLEV_ADMIN_PKG
AS
FUNCTION GET_SUBPARTS (IN_PART_ID IN NUMBER)
RETURN TYPE_PART_NEEDED_TBL PIPELINED
IS
BEGIN
FOR R IN (
WITH SUBPARTS(ID, PART_ID, SUBPART_ID, AMOUNT)
AS (
SELECT PART_NEEDED_ID,
TYPE_OF_PART_NEEDS_ID,
TYPE_OF_PART_IS_NEEDED_ID,
AMOUNT
FROM PART_NEEDED
WHERE TYPE_OF_PART_NEEDS_ID = IN_PART_ID
UNION ALL
SELECT PN.PART_NEEDED_ID,
PN.TYPE_OF_PART_NEEDS_ID,
PN.TYPE_OF_PART_IS_NEEDED_ID,
PN.AMOUNT
FROM SUBPARTS SP,
PART_NEEDED PN
WHERE PN.TYPE_OF_PART_NEEDS_ID = SP.SUBPART_ID
SELECT TYPE_PART_NEEDED(
SP.ID,
SP.PART_ID,
SP.SUBPART_ID,
SP.AMOUNT
) O
FROM SUBPARTS SP
ORDER BY PART_ID
) LOOP
PIPE ROW(R.O);
END LOOP;
RETURN;
END GET_SUBPARTS;
END KOLEV_ADMIN_PKG;
/SY. -
I have a table in which one of the columns is a user-defined datatype:
SQL> describe my_table
USER_DATA MYTYPEThe type "MYTYPE" is a simple object that contains one field: a CLOB called MESSAGE:
SQL> describe mytype
Name Null? Type
MESSAGE CLOBWhen I do a "select * ..." from this table, the column USER_DATA is displayed as "MYTYPE(oracle.sql.CLOB@898c2d)"
I know that for CLOB and BLOB fields, SQL Developer will let me double click the value and view the contents. But for a user-defined type like this that contains a field, I cannot browse into the data members of the type. I find myself wanting to do something like a "select user_data.message from my_table", but this is not valid syntax. Is there a way to query a specific data member of this user-defined type with the rest of the columns in the table so that I can be shown the CLOB member instead of a representation of the object? If not, is there a way to configure SQL Developer to allow me to browse the data members of user-defined types? TOAD has a feature like this but I would like to use SQL Developer exclusively and this is one table I must work with regularly.Just to back up a previous post:
sqldeveloper 1.5.5.59.69 against 10.2 (Express Edition)
desc r2
input:
select r.message from r2; --fails
select r2.r.message from r2; --fails
select this.r.message from r2 this; --succeeds
output:
desc r2
Name Null Type
R REALLY_CLOB()
Error starting at line 1 in command:
select r.message from r2
Error at Command Line:1 Column:7
Error report:
SQL Error: ORA-00904: "R"."MESSAGE": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error starting at line 2 in command:
select r2.r.message from r2
Error at Command Line:2 Column:7
Error report:
SQL Error: ORA-00904: "R2"."R"."MESSAGE": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
R.MESSAGE
(CLOB)
(CLOB)
(CLOB) start of clob
3 rows selected -
User-Defined Type does not display values in Table Data grid
I have a User defined Type that is a collection of one character VARCHAR2 values. In the Table Data grid it does not display the character values. I know on all our other Oracle development applications these values display. Is this a bug or is there a snippet to display these values?
Version: 1.0.0.15
DB: 10.2.0
Workstation OS: Windows XP -
Using columns of user defined types
Can anyone help me display data from a column within a table which is of a user defined type - a object with 4 elements .
Discoverer wont currently display the data - it says a MAP or ORDER method is required.
The type is declared as :
create or replace type m_p as object
( m_p_id number(9),
m_p_start number,
m_p_end number,
m_p_length number )
and the table is declared as
create table t_m_p (
N_ID NUMBER,
N_PL M_P,
N_ATT VARCHAR2(1)
What do I need to do to allow Discoverer 3.1 to display the data held in the N_PL column?
Also : can anyone tell me if it is possible to display data in Discoverer from a thre dimensional varray? - or would I have to create a view on it?Discoverer does not currently allow queries to contain the extended Oracle 8 object types. The way to resolve this is to write views that present a relational view of the object structure and then build a business area based on these views
Oracle Discoverer Team
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by nikstace ([email protected]):
Can anyone help me display data from a column within a table which is of a user defined type - a object with 4 elements .
Discoverer wont currently display the data - it says a MAP or ORDER method is required.
The type is declared as :
create or replace type m_p as object
( m_p_id number(9),
m_p_start number,
m_p_end number,
m_p_length number )
and the table is declared as
create table t_m_p (
N_ID NUMBER,
N_PL M_P,
N_ATT VARCHAR2(1)
What do I need to do to allow Discoverer 3.1 to display the data held in the N_PL column?
Also : can anyone tell me if it is possible to display data in Discoverer from a thre dimensional varray? - or would I have to create a view on it?<HR></BLOCKQUOTE>
null
Maybe you are looking for
-
How to use Purch. Info Record, for different Valuation Types ?
Hi All, While doing Split Valuation, I have created three valuation types - say, M1,M2,M3. for material M. Now, I want to create Info record for material M and Vendor V1. when i go to me11, system is allowing me to create info record for M and V1 on
-
Logic Pro version 9.0.0 not working with OS ML version 10.8.4
try to update my Logic Pro but it says "A newer version of Logic Pro is already installed in the Applications folder."
-
XML Job is error out due to "emsg:was terminated by signal 11"
We are using XML report to print checks and today suddenly program started error out. Due to following reason. APPLLCSP Environment Variable set to : XML_REPORTS_XENVIRONMENT is : /u30/app/applmgr/abghfprd/806/guicommon6/tk60/admin/Tk2Motif_UTF8.rgb
-
Oracle Web Service Manager Login failed
Hi , I had installed advance version of SOA 10.1.3.1 on windows xp. I abel to login to all component other than web service manager.I am using the oc4jadmin user id and its password to login.Please let me know what i have to do to fix it. Regards, Pa
-
Doubts in Query & Infoset Builder
Hi All, I have a problem/doubt with my query, Due to a requirement I have to place a Check box in my Selection scree of Query. Unfortunately when I place my Checkbox in Info-set(SQ02), Its showing check Box at first place. Example: We have a Query wi