COLLECT into table of VARCHAR2 giving ORA-22814 error
Hello,
I am trying to collect a VARCHAR2(5 CHAR) column into a table type of VARCHAR2(5 CHAR) but it gives me the ORA-22814: attribute or element value is larger than specified in type.
Even if I cast my string to this data type.
SQL> CREATE OR REPLACE TYPE T_VARCHAR2_5_TAB AS TABLE OF VARCHAR2(5 CHAR);
2 /
Type created.
SQL>
SQL> DESC site_section_cours;
Name Null? Type
SEQ_SITE_COURS NOT NULL NUMBER
CODE_SESSION NOT NULL VARCHAR2(6 CHAR)
NUMERO_REFERENCE_SECTION_COURS NOT NULL VARCHAR2(5 CHAR)
CODE_STATUT_PUBLICATION_PDF NOT NULL VARCHAR2(2 CHAR)
CONTROLE_MODIFICATION NOT NULL NUMBER
SEQ_BAREME_NOTES NUMBER
SQL>
SQL> SELECT CAST(
2 COLLECT(
3 sisc.numero_reference_section_cours
4 ORDER BY sisc.code_session, sisc.numero_reference_section_cours
5 )
6 AS t_varchar2_5_tab
7 ) AS lov
8 FROM site_section_cours sisc;
COLLECT(
ERROR at line 2:
ORA-22814: attribute or element value is larger than specified in type
SQL>
SQL> SELECT CAST(
2 COLLECT(
3 CAST(
4 sisc.numero_reference_section_cours AS VARCHAR2 (5 CHAR)
5 )
6 ORDER BY sisc.code_session, sisc.numero_reference_section_cours
7 )
8 AS t_varchar2_5_tab
9 ) AS lov
10 FROM site_section_cours sisc;
COLLECT(
ERROR at line 2:
ORA-22814: attribute or element value is larger than specified in type What am I missing?
Thanks
Bruno
A new test: try to collect into 10 and 20 char table type.
Not working with 10 but working with 20.
SQL> SELECT CAST(
2 COLLECT(
3 sisc.numero_reference_section_cours
4 ORDER BY sisc.code_session, sisc.numero_reference_section_cours
5 )
6 AS t_varchar2_10_tab
7 ) AS lov
8 FROM site_section_cours sisc;
COLLECT(
ERROR at line 2:
ORA-22814: attribute or element value is larger than specified in type
SQL>
SQL> SELECT CAST(
2 COLLECT(
3 sisc.numero_reference_section_cours
4 ORDER BY sisc.code_session, sisc.numero_reference_section_cours
5 )
6 AS t_varchar2_20_tab
7 ) AS lov
8 FROM site_section_cours sisc;
LOV
T_VARCHAR2_20_TAB('10001', '10003', '10004', '10016', '10018', '10019', '10020',
'10022', '10025', '10028', '10029', '10030', '10031', '10032', '10039', '10040'
, '10041', '10003', '21000', '21001', '21002', '21004', '21005', '21006', '21007
', '21008', '21009', '21010', '82001', '11972', '11986', '10018', '10019') Bruno
Similar Messages
-
Creating Oracle table is giving ORA-00911 error
Hi,
I got a small code which I am trying to implement in order to create a table in Oracle 8i database. The code compiles fine. However, when I run, it is giving ORA-00911 error(invalid character). Any help is highly appreciated in advance. Thanks.
CODE:
import java.sql.*;
import java.io.*;
import sun.jdbc.odbc.*;
public class createor {
public static void main (String args[]) {
try{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@myserv:1521:cooler", "scott", "tiger");
Statement stmt = conn.createStatement ();
stmt.execute( "create table JoltData ("+
"programmer varchar (32),"+
"day char (3),"+
"cups integer);"
stmt.close();
}catch (Exception e) {e.printStackTrace();}Try this code, it works for me.
import java.sql.*;
import java.util.*;
import java.text.*;
class dbtestcreatetable {
public static void main (String args []) throws SQLException {
try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@myserver:1521:mysid",
"password",
"userid");
String sql = "CREATE TABLE MYTABLE3 (COL1 VARCHAR(3))";
Statement statement = conn.createStatement();
int cnt = statement.executeUpdate(sql);
statement.close();
conn.close();
catch (Exception e) {
System.out.println("Java Exception caught, error message="+e.getMessage());
} -
Nested tables and memory usage (ORA-04030 error)
Dear All,
I have table with approximately 5,000,000 records
and try to Bulk Collect part of it into nested table in PL/SQL, the code is bellow
Declare
Type TcardRec Is Record(
serno Pls_Integer,
numberx Char(16),
caccserno Pls_Integer
Type TcardList Is Table Of TcardRec;
fcardInfo TcardList;
Begin
Select c.serno, substr(c.numberx,1,16), c.caccserno
Bulk Collect Into fcardinfo
From cardx c;
End;
After reading approx. 80% it fails with error
ORA-04030: out of process memory when trying to allocate 16396 bytes (koh-kghu call ,pmucalm coll)
I 2G memory, is it realy no enough?
How can I tune memory usage for collection?
How can I estimate the maximum size of the collection the will fit into memory?
Thank you in advance for any help
ArtemDeclare it as a cursor.
Open the cursor.
Use fetch bulk collect with the limit option in the loop.
In your case, you could do like:
Declare
Cursor c1 is
Select c.serno, substr(c.numberx,1,16), c.caccserno
From cardx c;
TcardList Is Table Of c1%rowtype;
fcardInfo TcardList;
Begin
Open c1;
Loop
Fetch c1 Bulk Collect Into fcardInfo Limit 10000;
Exit when c1%notfound;
-- Do some processing here.
End Loop;
Close c1;
End;
I hope this helps. -
Mapping with Match and Merge operater giving ORA-06550 error while deploy..
Created a simplet mapping to source from Customer table to tstcustomer table thru' Match and Merge operator. The mapping validated successful but giving ORA-06550 line x column y error while deploying the mapping.
It is a simple mapping consisting of source Customer table, Match and Merge operator, tstcustomer target table.
Could anyone advise me on how to resolve this?The test mapping basically consists of :
source table - sh.customers
target table - tstcustomers (similar to sh.customers)
Match-Merge operator.
The mapping validation was successful but when attempt was made to deploy, its giving errors starting with ORA-06550.
I saved the code and executed thru' SQL Plus and the error details are as follows:
SQL> show errors;
Errors for PACKAGE BODY MMTEST4:
LINE/COL ERROR
594/6 PL/SQL: Statement ignored
594/37 PLS-00306: wrong number or types of arguments in call to 'RTRIM'
601/6 PL/SQL: Statement ignored
601/36 PLS-00306: wrong number or types of arguments in call to 'RTRIM'
1017/655 PL/SQL: SQL Statement ignored
30
1020/27 PL/SQL: ORA-00942: table or view does not exist
2163/6 PL/SQL: Statement ignored
2163/43 PLS-00201: identifier 'CUSTOMERS_0_CUST_GENDER' must be declared
2170/6 PL/SQL: Statement ignored
LINE/COL ERROR
2170/42 PLS-00201: identifier 'CUSTOMERS_0_COUNTRY_ID' must be declared
2586/655 PL/SQL: SQL Statement ignored
30
2589/27 PL/SQL: ORA-00942: table or view does not exist
SQL>
For your info, the same mapping without Match-Merge Operator is getting deployed and executed successfully.
But with Match-Merge operator, after setting Match bins, Match rules, Merge rules etc the mapping is validated successfully but errorring out while deployment.
Pls advise on how to resolve this.
I understand that the Match-Merge Operator gives Pl/Sql output from the documentation.
thanks
Naren. -
While updating a table i am getting ORA-00600 error.
Hi all,
While updating a table i am getting the following:
**SQL Error: ORA-00600: internal error code, arguments: [qkebCreateConstantOpn1], [], [], [], [], [], [], [], [], [], [], []**
**00600. 00000 - "internal error code, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s]"**
I am not getting how to proceed on this. Please guide me.
Thanks,
RiteshWhile performing some unspecified action (no DML) on an unknown table (no DDL) in an unknown version and edition of the Oracle database you had an untrapped Oracle exceptions.
There are too many unknowns to help you beyond recommending you open an SR at MyOracleSupport. -
Failed to sqlplus into ASM with the notorious ORA-12505 error
Hi guys,
I have a 2-node RAC testing environment and i have been having trouble trying to LOCALLY sqlplus into the ASM instance.
If I do "sqlplus sys/xxxxx@asm1", it just throws "ORA-12505:TNS: listener does not currently know of SID given in connect descriptor".
If I do "sqlplus / as SYSASM", it says "ORA-01031: insufficient privileges".
Can' figure out where I did wrong so really appreciate some help here (maybe in the listener file, i should give the GRID home for one of the ORACLE_HOME parameters)?
Here is the tns and listener file:
tnsnames.ora:
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = vbox-cluster)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
ASM1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = vbox-cluster)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = +ASM1)
listener.ora:
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line a
dded by Agent
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1))))
# line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent
SID_LIST_LISTENER_ASM=
(SID_LIST=
(SID_DESC=
(SID_NAME=PLSExtProc)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(PROGRAM=extproc)
(SID_DESC=
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME=+ASM1)
)user11957149 wrote:
Hi guys,
I have a 2-node RAC testing environment and i have been having trouble trying to LOCALLY sqlplus into the ASM instance.
If I do "sqlplus sys/xxxxx@asm1", it just throws "ORA-12505:TNS: listener does not currently know of SID given in connect descriptor".
If I do "sqlplus / as SYSASM", it says "ORA-01031: insufficient privileges".
Can' figure out where I did wrong so really appreciate some help here (maybe in the listener file, i should give the GRID home for one of the ORACLE_HOME parameters)?
Here is the tns and listener file:
tnsnames.ora:
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = vbox-cluster)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
ASM1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = vbox-cluster)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = +ASM1)
listener.ora:
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line a
dded by Agent
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1))))
# line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent
SID_LIST_LISTENER_ASM=
(SID_LIST=
(SID_DESC=
(SID_NAME=PLSExtProc)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(PROGRAM=extproc)
(SID_DESC=
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME=+ASM1)
)with regard to ASM instance, it is NEVER "online"
There is never any requirement to connect to ASM instance via SQL*Net.
Log onto DB Server directly & just start ASM instance -
JPub giving ORA-29545 error - Please Help!
All,
I am trying to consume Java Web Services for 9.2.0.1 RDBMS. While I run JPub, I get the following error:
E:\Ora9i\OraHome92\bin>jpub -user="SCOTT/TIGER" -sysuser="SYS/TIGER" -proxywsdl="e:\IMyFloatWebService.wsdl" -dir=ShowPi -plsqlpackage=soap_callout_wrpr_pi -proxyopts="soap,tabfun"
Note: ShowPi\MyFloatWebServiceProxy.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
ShowPi\MyFloatWebServiceProxyJPub.java
ShowPi\plsql_wrapper.sql
ShowPi\plsql_dropper.sql
ShowPi\plsql_grant.sql
ShowPi\plsql_revoke.sql
Executing ShowPi\plsql_dropper.sql
Executing ShowPi\plsql_wrapper.sql
Executing ShowPi\plsql_grant.sql
Loading ShowPi\plsql_proxy.jar
Error while creating class java/lang/StringBuilder
ORA-29545: badly formed class: User has attempted to load a class (java.lang
.StringBuilder) into a restricted package. Permission can be granted using dbms
java.grantpermission(<user>, LoadClassInPackage...
errors : class MyFloatWebServiceProxyJPub
ORA-29521: referenced name java/lang/StringBuilder could not be found
errors : class MyFloatWebServiceProxy
ORA-29521: referenced name java/lang/StringBuilder could not be found
The following operations failed
class MyFloatWebServiceProxyJPub: resolution
class MyFloatWebServiceProxy: resolution
class java/lang/StringBuilder: creation
exiting : Failures occurred during processing
Could somebody suggest me some way to go around this - I have been sitting on this since three days - any help is appreciated.
Regards,
Leslie, AHi,
I am having the same problem. Did u get this to work.
Thanks. -
ORA-04045 : errors during recompilation/revalidation of SYS.DBMS_STANDARD
Hi,
i am on 11.5.10.2 RHEL 4.0
i tried running catalog.log on DB Tier as sys, but was not successful.
later sqlplus apps/apps would start giving
ORA-00604 : error occured at recursive SQL level 1
ORA-04045 : errors during recompilation/revalidation of SYS.DBMS_STANDARD
$sqlplus /nolog works fine... BUT
$sqlplus conn /as sysdba HANGS!!!!
Also logging via URL > after clicking on E-Business Home Page gives
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, changeOnOHSInstall and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
could anybody suggest on this error?
Thanking You
Regards,
SKThanks for your quick reply
status of the object: INVALID
PLSQL_V2_COMPATIBLITY is set to FALSE
Run utlrp.sql to compile all invalid objects in the database
it gave me error as follows:
SQL> @utlrp.sql
declare
ERROR at line 1
ORA -00604 : error occured at recursive SQL level 1
ORA - 04045 : errors during recompilation/revalidation of SYS.DBMS_STANDARD
CREATE TABLE utl_recomp_invalid (obj# number)
ERROR at line 1
ORA -00604 : error occured at recursive SQL level 1
ORA - 04045 : errors during recompilation/revalidation of SYS.DBMS_STANDARD
CREATE TABLE utl_recomp_sorted (obj# number, depth number)
ERROR at line 1
ORA -00604 : error occured at recursive SQL level 1
ORA - 04045 : errors during recompilation/revalidation of SYS.DBMS_STANDARD
CREATE TABLE utl_recomp_compiled(obj# number)
ERROR at line 1
ORA -00604 : error occured at recursive SQL level 1
ORA - 04045 : errors during recompilation/revalidation of SYS.DBMS_STANDARD
CREATE INDEX utl_recomp_comp_idx1 ON utl_recomp_compiled(obj#)
ERROR at line 1
ORA -00604 : error occured at recursive SQL level 1
ORA - 04045 : errors during recompilation/revalidation of SYS.DBMS_STANDARD
CREATE TABLE utl_recomp_backup_jobs (command varchar2(100), status varchar2(1000))
ERROR at line 1
ORA -00604 : error occured at recursive SQL level 1
ORA - 04045 : errors during recompilation/revalidation of SYS.DBMS_STANDARD
SELECT o.obj#, o.type#, o. owner# FROM obj# o
ERROR at line 2
ORA -00604 : error occured at recursive SQL level 1
ORA - 04045 : errors during recompilation/revalidation of SYS.DBMS_STANDARD
Edited by: mirage on Dec 4, 2008 6:45 PM -
Ora-00604 error while taking tkprof of a trace file
Sorry i am giving the full erro but omitting exact table names
Hi ,
I have an error while taking tkprof of a trace file.
I gave the following command ---
tkprof <source.trc> <file.prc> sys=no sort=exeela,fchela,prsela explain= /
error is --
Error in create table of EXPLAIN PLAN table : unix_session_user.prof$paln_table
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: Step-6:DDL
Event Security. You are not permitted to perform the requested structural
changes to PROF (TABLE)
Event triggered : CREATE
ora_login_user
(session_user) : unix_session_user(dummy)
Search : select count(*) from
tabl(dummy table name) where obj_name like '%\%%' escape '\' and obj_type =
'TABLE' and obj_type = 'USER' and ( event_CREATE = 'Y' or status =
'Override')
ORA-06512: at line 162
ORA-06510: PL/SQL: unhandled
user-defined exception
EXPLAIN PLAN option disabled.
i searched for the error and in oracle forum i found a solution .. http://forums.oracle.com/forums/thread.jspa?threadID=844287&tstart=0
but after giving the table option it is giving the same error
tkprof <source.trc> <file.prc> sys=no sort=exeela,fchela,prsela table=old_schema.plan_table explain= /
it again gave the same error.
In both two cases it gives elapsed time results,library cache missing etc but before giving this it throws ORA-00604 error as stated above
then i again correct the tkprof statement ..
tkprof <source.trc> <file.prc> sys=no sort=exeela,fchela,prsela table=new_schema.plan_table explain= /
say this schema name here i used is dummy schema name.
My question is did this error came as we had not sufficient previlages in the old_schema but that previleges we have in new_schema?
My databse version is 9.2.0.4.0
Thanks in advance
Edited by: bp on Feb 3, 2009 11:36 PM
Edited by: bp on Feb 3, 2009 11:40 PMPlease post here full error message, there should be lines with ORA-00604 and then some other ORA as well.
And are there any trace files generated during this error?
And as You can see from error description, probably You will have to contact with Oracle support in order to solve this case:
oerr ora 00604
00604, 00000, "error occurred at recursive SQL level %s"
// *Cause: An error occurred while processing a recursive SQL statement
// (a statement applying to internal dictionary tables).
// *Action: If the situation described in the next error on the stack
// can be corrected, do so; otherwise contact Oracle Support. -
I have just installed the latest version of SQL Developer (1.2.1.3213) and am running an Oracle 9i database (version 9.2.0.7).
When I click on the SQL tab when looking at a table I get an ORA-06502 error and the DDL generated has "-- Unable to Render DDL with DBMS_METADATA using internal generator." at the top.
I then get a whole host of other errors when using other parts of the program until I disconnect and reconnect.
This error also occurs when I run the following query:
select dbms_metadata.get_ddl('TABLE',table_name , user ) from user_tables;
Any ideas?
Incidentally prior to this release I had an early version 1 release of SQL Developer and the SQL tab here showed nothing at all.
Any comments would be most appreciated.I am currently using v2.1.1.64, Build MAIN-64.45 and have the same or a similar problem. SQL developer will not generate the SQL code, but fails with the following error:
ORA-06502: PL/SQL: numeric or value error
LPX-00210: expected '<' instead of 'n'
ORA-06512: at "SYS.UTL_XML", line 0
ORA-06512: at "SYS.DBMS_METADATA_INT", line 3688
ORA-06512: at "SYS.DBMS_METADATA_INT", line 4544
ORA-06512: at "SYS.DBMS_METADATA", line 466
ORA-06512: at "SYS.DBMS_METADATA", line 640
ORA-06512: at "SYS.DBMS_METADATA", line 1260
ORA-06512: at line 1
This installation doesn't have the same directory structure as in the previous reply, so I can't run the catmeta.sql script which doesn't exist in this release.
Mike -
ORA-12514 error while connecting to server
I am using instantclient to connect to Oracle 9i server.
The connection string is given using this format
//host:[port][service name].
In our development environment we can successfully connect to the server. But the connection fails in the production environment giving ORA-12514 error. This occurs even when we copy the instant client dll's onto separate folder and set the library loading path to this folder.
Can u please help me in resolving this problem.Vinay,
Since you are using Windows, are you setting PATH (the lib loading path of Windows)? -
Re: ORA-13208: error
Hi all. I seem to encounter the following error for some spatial tables in my database but not all of them when I run a java application I developed on those tables:
java.sql.SQLException: ORA-29902: error in executing ODCIIndexStart() routine
ORA-13208: internal error while evaluating [window SRID does not match layer SRID] operator
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_9I", line 368
I have a hunch it results from the way I initially set up the tables in my spatial database. Does anyone out there know the best way to address this problem. Thanks, JoeHi Joe,
In Oracle9i, the optimized rectangle type is not supported for geodetic data. There are other possible issues also with geodetic data (for instance, no polygon can be greater than 1/2 the surface area of the earth).
In Oracle9i, there is a function:
sdo_cs.viewport_transform (geom, to_srid)
That function takes as input an optimized rectangle with SRID set to 0, and the SRID to put the optimized rectangle in.
If the SRID is associated with projected data or is null, all the function does is return the geometry back with SDO_SRID set to the value of the passed in parameter.
If the SRID is associated with a geodetic coordinate system, spatial will densify along lines of latitude, and if the geometry is > 1/2 the surface area of the earth it will break it up.
here is an example usage:
SELECT a.state
FROM geod_states a
WHERE sdo_filter(
a.geom,
sdo_cs.viewport_transform(
mdsys.sdo_geometry(2003, 0, NULL,
mdsys.sdo_elem_info_array(1,1003,3),
mdsys.sdo_ordinate_array(-90,35,-75,45)),
8307),
'querytype=window') = 'TRUE';
In Oracle Spatial 10g, there is no longer a need for sdo_cs.viewport_transform - if you specify the optimized rectangle type directly in spatial in a geodetic coordinate system, a viewport_transform-like operation is automatically done under the covers.
Note because the returned geometry will be in a different format (may be a multi-polygon, and will not necessarily be valid for all usage), Oracle recommends using viewport_transform only with SDO_FILTER, and SDO_RELATE with the anyinteract mask, as well as SDO_NN and SDO_WITHIN_DISTANCE.
Hope this helps. -
I am getting Error ORA-00600 for a procedure which tries get
a CLOB as output paramater. It is a simple stored proc which is
just querying to get this data.
However it fails at times giving ORA-00600 error which we have
no clue why it's happening.
There is sufficient space in the server and also we have
restarted the database several times.
Any pointers to why is this happening.
SunilCause: This is a catchall internal error message for Oracle
program exceptions. It indicates that a process has met a low-
level, unexpected condition.
Various causes of this message include:
time-outs
file corruption
failed data checks in memory
hardware, memory, or I/O errors
incorrectly restored files
The first argument is the internal message number. Other
arguments are various numbers, names, and character strings. The
numbers may change meanings between different versions of the
Oracle Server.
Action: Report this error to customer support after gathering
the following information:
-events that led up to the error
-the operations that were attempted that led to the
error
-the conditions of the operating system and database at
the time of the error
-any unusual circumstances that occurred before
receiving theORA-00600 message
contents of any trace files generated by the error
the relevant portions of the Alert file
Copyright (C) 1995, Oracle Corporation -
Collect giving error ORA 22814
getting ORA 22814 attribute or element value is larger than specified type.
TAB1(
item number(10)
item_id NVARCHAR2(250))
SELECT item, tab_to_nvarchar2(cast(collect(item_id order by item_id) as T_NVARCHAR2_TAB),',') as item_list
FROM TAB1
GROUP BY item
CREATE OR REPLACE TYPE T_NVARCHAR2_TAB AS TABLE OF NVARCHAR2 (4000);
CREATE OR REPLACE FUNCTION tab_to_nvarchar2 (p_nvarchar2_tab IN t_nvarchar2_tab, p_delimiter IN VARCHAR2 DEFAULT ',')
RETURN nvarchar2
IS
l_string NVARCHAR2 (32767) := NULL;
-- l_string VARCHAR2 (4000) := NULL;
BEGIN
FOR i IN REVERSE p_nvarchar2_tab.FIRST .. p_nvarchar2_tab.LAST
LOOP
IF i != p_nvarchar2_tab.LAST
THEN
l_string := p_delimiter || l_string;
END IF;
l_string := p_nvarchar2_tab (i) || l_string;
END LOOP;
RETURN l_string;
END tab_to_nvarchar2;Collect will not work here. Use:
select item,
tab_to_nvarchar2(
cast(
multiset(
select item_id
from tab1 t2
where t2.item = t1.item
as T_NVARCHAR2_TAB
) item_list
from tab1 t1
group by item
/For example:
SQL> CREATE OR REPLACE TYPE T_NVARCHAR2_TAB AS TABLE OF NVARCHAR2(4000)
2 /
Type created.
SQL> CREATE OR REPLACE FUNCTION tab_to_nvarchar2 (p_nvarchar2_tab IN t_nvarchar2_tab, p_delimiter IN VARCHAR2 DEFAULT ',')
2 RETURN nvarchar2
3 IS
4 l_string NVARCHAR2 (32767) := NULL;
5 -- l_string VARCHAR2 (4000) := NULL;
6 BEGIN
7 FOR i IN REVERSE p_nvarchar2_tab.FIRST .. p_nvarchar2_tab.LAST
8 LOOP
9 IF i != p_nvarchar2_tab.LAST
10 THEN
11 l_string := p_delimiter || l_string;
12 END IF;
13 l_string := p_nvarchar2_tab(i) || l_string;
14 END LOOP;
15 RETURN l_string;
16 END tab_to_nvarchar2;
17 /
Function created.
SQL> select deptno,
2 tab_to_nvarchar2(cast(collect(ename) as T_NVARCHAR2_TAB),',') as item_list
3 from emp
4 group by deptno
5 /
tab_to_nvarchar2(cast(collect(ename) as T_NVARCHAR2_TAB),',') as item_list
ERROR at line 2:
ORA-22814: attribute or element value is larger than specified in type
SQL> select deptno,
2 tab_to_nvarchar2(
3 cast(
4 multiset(
5 select ename
6 from emp e2
7 where e2.deptno = e1.deptno
8 )
9 as T_NVARCHAR2_TAB
10 ),
11 ','
12 ) item_list
13 from emp e1
14 group by deptno
15 /
DEPTNO ITEM_LIST
30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
20 SMITH,JONES,SCOTT,ADAMS,FORD
10 CLARK,KING,MILLER
SQL> But in general, scrap your code and use listagg (if you are on 11.2) or xmlagg:
SQL> select deptno,
2 listagg(ename,',') within group(order by ename) item_list
3 from emp
4 group by deptno
5 /
DEPTNO ITEM_LIST
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
SQL> select deptno,
2 rtrim(xmlagg(xmlelement(e,ename,',').extract('//text()')),',') item_list
3 from emp
4 group by deptno
5 /
DEPTNO ITEM_LIST
10 CLARK,MILLER,KING
20 JONES,FORD,ADAMS,SCOTT,SMITH
30 BLAKE,JAMES,TURNER,MARTIN,WARD,ALLEN
SQL> SY. -
Selecting the contents of a table(collection) into a strong REF Cursor
I'm trying to roll some data into a table collection and return it as a strong named cursor.
I have not been able to do this successfully yet.
I have tried casting the table and I couldn't get that to work either.
I have included the whole procedure but here is the line I am getting errors on:
SELECT * bulk collect into o_response_data_cur from table (response_data_tbl);
Any help on this would be great.
P.S. - As this is being picked up by BizTalk I can't return a table.
Thanks,
Todd M
PROCEDURE create_customer (
i_interface_hdr IN BizTalk_TestCustomer.interface_hdr_rec,
i_customer_rec IN BizTalk_TestCustomer.customer_rec,
i_address_cur IN BizTalk_TestCustomer.CUR_Addresses,
i_contact_cur IN BizTalk_TestCustomer.CUR_Contact,
o_interface_status OUT varchar2,
o_response_data_cur OUT BizTalk_TestCustomer.CUR_CreateCustResponse)
IS
l_response_rec create_cust_response_rec;
response_data_tbl create_cust_response_tbl;
BEGIN
FOR i IN 1 .. 10
LOOP
l_response_rec.ERROR_TYPE := 'Pre-Validation Error';
l_response_rec.ERROR_CODE := 'DUMMY-' || i;
l_response_rec.error_message := 'Test Error Message-' || i;
response_data_tbl (i) := l_response_rec;
END LOOP;
SELECT * bulk collect into o_response_data_cur from table (response_data_tbl);
o_interface_status := 'FAILURE';
END create_customer;
END BizTalk_TestCustomer;
Here is the important Spec info:
TYPE create_cust_response_rec
IS
RECORD (
orig_system_party_ref varchar2 (240),
orig_system_cust_acct_ref varchar2 (240),
orig_system_site_ref varchar2 (240),
oracle_party_id number,
oracle_customer_id number,
oracle_site_id number,
ERROR_TYPE strar_cust_intf_err.ERROR_TYPE%TYPE,
ERROR_CODE strar_cust_intf_err.ERROR_CODE%TYPE,
error_message strar_cust_intf_err.error_message%TYPE
TYPE CUR_Addresses IS REF CURSOR RETURN BizTalk_TestCustomer.address_rec;
TYPE CUR_Contact IS REF CURSOR RETURN BizTalk_TestCustomer.contact_rec;
TYPE CUR_CreateCustResponse IS REF CURSOR RETURN BizTalk_TestCustomer.create_cust_response_rec;
TYPE create_cust_response_tbl
IS
TABLE OF create_cust_response_rec
INDEX BY binary_integer;I think this is one of the most complicated one to develop and execute perfectly. ;)
Here is one such case ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.55
satyaki>
satyaki>
satyaki>create or replace type d_obj as object
2 (
3 buff varchar2(310)
4 );
5 /
Type created.
Elapsed: 00:00:00.05
satyaki>
satyaki>
satyaki>create or replace type d_rec as table of d_obj;
2 /
Type created.
Elapsed: 00:00:01.14
satyaki>
satyaki>
satyaki>
satyaki>
satyaki>create or replace function pipe_buff(e_sal in number)
2 return d_rec
3 pipelined
4 is
5 cursor c1
6 is
7 select d_obj(
8 ename||' Joined On '||to_char(hiredate,'DD-MON-YYYY hh24:mi:ss')
9 ) str
10 from emp
11 where sal > e_sal;
12
13 r1 c1%rowtype;
14 begin
15 for r1 in c1
16 loop
17 pipe row(r1.str);
18 end loop;
19 return;
20 end;
21 /
Function created.
Elapsed: 00:00:01.69
satyaki>
satyaki>
satyaki>
satyaki>create or replace procedure gen_cur_pipe(
2 s_sal in number,
3 rc in out sys_refcursor
4 )
5 is
6 str1 varchar2(500);
7 begin
8 str1 := 'select *
9 from table(cast(pipe_buff('||s_sal||') as d_rec))';
10
11 open rc for str1;
12 exception
13 when others then
14 dbms_output.put_line(sqlerrm);
15 end;
16 /
Procedure created.
Elapsed: 00:00:00.05
satyaki>
satyaki>
satyaki>
satyaki>create table test_dual
2 (
3 dummy varchar2(310)
4 );
Table created.
Elapsed: 00:00:00.10
satyaki>
satyaki>
satyaki>
satyaki>declare
2 rec_x test_dual%rowtype;
3 w sys_refcursor;
4 begin
5 dbms_output.enable(1000000);
6 gen_cur_pipe(&num,w);
7 loop
8 fetch w into rec_x;
9 exit when w%notfound;
10 dbms_output.put_line('Employee Special Deatils: '||rec_x.dummy);
11 end loop;
12 close w;
13 exception
14 when others then
15 dbms_output.put_line(sqlerrm);
16 end;
17 /
Enter value for num: 1000
old 6: gen_cur_pipe(&num,w);
new 6: gen_cur_pipe(1000,w);
Employee Special Deatils: SATYAKI Joined On 02-NOV-2008 12:07:30
Employee Special Deatils: SOURAV Joined On 14-SEP-2008 00:07:21
Employee Special Deatils: WARD Joined On 22-FEB-1981 00:00:00
Employee Special Deatils: JONES Joined On 02-APR-1981 00:00:00
Employee Special Deatils: MARTIN Joined On 28-SEP-1981 00:00:00
Employee Special Deatils: BLAKE Joined On 01-MAY-1981 00:00:00
Employee Special Deatils: CLARK Joined On 09-JUN-1981 00:00:00
Employee Special Deatils: SCOTT Joined On 19-APR-1987 00:00:00
Employee Special Deatils: KING Joined On 17-NOV-1981 00:00:00
Employee Special Deatils: TURNER Joined On 08-SEP-1981 00:00:00
Employee Special Deatils: ADAMS Joined On 23-MAY-1987 00:00:00
Employee Special Deatils: FORD Joined On 03-DEC-1981 00:00:00
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.30
satyaki>
satyaki>
satyaki>/
Enter value for num: 4000
old 6: gen_cur_pipe(&num,w);
new 6: gen_cur_pipe(4000,w);
Employee Special Deatils: SATYAKI Joined On 02-NOV-2008 12:07:30
Employee Special Deatils: SOURAV Joined On 14-SEP-2008 00:07:21
Employee Special Deatils: CLARK Joined On 09-JUN-1981 00:00:00
Employee Special Deatils: KING Joined On 17-NOV-1981 00:00:00
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.13
satyaki>I'm not so sure about the performance.
Regards.
Satyaki De.
Maybe you are looking for
-
Flash CC does not support .swf then how do i edit .swf?
Hello, I am at a stuck point with my clients website i downloaded a template for him and have everything good to go except for i have no experience in flash files and the main piece to this websites decor is a flash .swf file. As i stated i have no e
-
Bapi to create customer Master
Dear all, As far i know there is no standard bapi to create a customer. There i s standard fm used her is SD_CUSTOMER_MAINTAIN_ALL. I tried to create customer master using this and making the function module as remote enabled. i tried to created a
-
Can't print from Illustrator or Acrobat
Hi all, I just upgraded my iMac to Mavericks, and am now having trouble printing from CS5. The message I get is "Can't print the illustration. The Color Management settings are inconsistent." I hadn't made any color management changes, so I assume th
-
Old iMac fragged, want to sync iPhone to MacBook
My iMac's motherboard died. Shouldn't have happened, score one for corporate planned obsolescence, etc. Now I'm using my MacBook as my main computer. What files from what directories do I need to transfer from the old machine to allow my phone to syn
-
Synchronization of the lyrics on iPhone
Hi everybody! I have a problem with the synchronization between iTunes and my iPhone3GS....I inserted the lyrics in some songs of my library but, after the synchronization, when I play the song on the iPhone there's no text. Can somebody help me?