Working with Collection in PL/SQL
Hi,
I am new in PL/SQL programming.
I am writing a PL/SQL stored procedure that have a "data collection" output argument. It extracts a list of data items (eg. id, temperature) from a table. The data items are stored in a collection (as the number of items is unknown therefore I am going to use nested table instead of varray). Some of the fields in the data items on the data collection will be transformed (eg. convert temperature from Fahrenheit to Celsius) before it is returned to the caller program.
* Question1:
How can I add data into a nested table (or varray) one at a time? (see sample codes below)
Eg.
I declared a nested table in the spec:
type test_record_t is record (
test_id number,
test_value number);
type test_list_t is table of test_record_t;
test record test_record_t;
test_list test_list_t;
Then in the body:
i := 1;
loop
fetch test_cursor into test_record;
exit when test_cursor%notfound;
test_list(i) := test_record; -- syntax error
i := i+1;
end loop;
All the examples I have seen so far that the list is populated when it is initialised:
Eg.
test_list := test_list_t(test_record1, test_record2);
but not
test_list(1) := test_record1;
test_list(2) := test_record2;
It could be that I am trying to implement the PL/SQL codes with my C/C++ thinking instead of PL/SQL. Do you have any suggestion?
* Question2:
How do you declare a PL/SQL procedure that have a nested table (or varray) output argument?
Eg.
PROCEDURE test_proc(data_list OUT ???);
Thank you very much and best regards,
Phil
PS. I am using Oracle 9.2
Phil, why are you using a collection to pass the data? PL/SQL collections reside in expensive PGA memory. Collections are thus not very scalable. The bigger they are, the less server memory for everyone else on the server. The more processes/sessions using your code, the more collections there are.. and again less server memory to go around for everyone else.
The primary reason for using collections in PL/SQL is to create a buffer that allows you to pass more rows between the PL and SQL engines in a single call. This reduces context switching and increases performance. PL in 10G already does this implicitly for you as bulk fetching/passing data is so critical to performance. PL/SQL collections allow you to explicitly manage this yourself.
Using a PL/SQL collection to "buffer" data for a client application is usually not the best of ideas. It involves using expensive PGA memory. It involves copying data from the inexpensive and scalable buffer cache into PL. It requires PL to crunch that data.
Typically doing all this in SQL is significantly faster and many times more scalable. E.g. using PL to construct the SQL statement that does this data crunching and processing, have PL create a cursor in the SQL engine for that statement, and then pass a reference handle to the client for using that cursor - fetching the data directly from the buffer cache and SQL engine.
Remember that despite the PL being very similar to other procedural languages, the environment it runs in is very different environment. Inside a database server process. With tight integration with the SQL engine.
PL is both a client language (it uses SQL as the server supplying data) and a server language (it is called by clients as a service on the server).
In order to use PL effectively, the very basic design rule is minimise PL/SQL and maximise SQL. Do not do in PL what SQL is perfectly capable of doing.. as the SQL engine will do it better and faster and more scalable than your PL code can ever do it.
Similar Messages
-
I am having an issue with working with lists of objects and would greatly appreciate some help on this. would like to cast indirectlist to arraylist.
I have a collection of data declared as below.
private Collection<PersistableTableData> tableData = (Collection<PersistableTableData>) new ArrayList();
then I try to access the data like below.
ArrayList<PersistableTableData> td = (ArrayList<PersistableTableData>) tableData;
but I get an error...
java.lang.ClassCastException: oracle.toplink.essentials.indirection.IndirectList cannot be cast to java.util.ArrayList
The question is am I doing something stupid here? I know I can create an arraylist like..
ArrayList<PersistableTableData> td = new ArrayList<PersistableTableData>(getTableData());
but it seems like that is allot of overhead when the list was created as an arraylist to begin with.
Is there a better way todo this?
Thanks in advanceWhat is the reason for trying to get the collection values outside of the session? Maybe
there is no need for that. If you want to query the table, you need to grant access to that
table to your workspace user and I wouldn't recommend that practice. Also, since your
application has many sessions, the data you get will be multiplicated by that factor.
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/apex/f?p=107:7
http://htmldb.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
Working with collections in powershell
Hi,
I'm struggeling with collections in Powershell in general.
I have a variable of type SPWebCollection created and want to add
1) a single SPWeb - Object
2) another collection of SPWeb - Objects
Can someone tell me please why the following doesn't work:
[Microsoft.Sharepoint.SPWebCollection]$allWebs += Get-SPWeb $URL1
or this
[Microsoft.Sharepoint.SPWebCollection]$allWebs += $site.AllWebs | Where-Object {$_.Url -like $URL2}
Finally I want to empty the $allWebs collection i.e. remove all objects. How do I do that?
I appreciate any feedback
Thank youHi,
According to your description, you might want to gather all the SPWeb object into a collection object in order to delete all of them finally.
As we can see, there is no such method in
SPWebCollection object can meet you requirement, as a workaround, we can push all the SPWeb objects into an array, then operate
these SPWeb objects in this array would do the trick.
Here is a link about how to create a generic collection for a list of objects:
http://www.andreasbijl.com/powershell-create-collections-of-custom-objects/
More information about using collection in PowerShell:
https://www.simple-talk.com/sysadmin/powershell/powershell-one-liners--collections,-hashtables,-arrays-and-strings/
Best regards,
Patrick
Patrick Liang
TechNet Community Support -
Why can't I work with SQLCe files in SQL 2012 Express?
I installed SQL2012 Express with the latest sp and have not been able to modify a SqlCe version 4.0 database. Comments from will be appreciated.
thanksHi,
SQL Server Management Studio does not support SSCE 4.0. You can use SSCE 4.0 Design Tools(SSCEVSTools) which installs the SQL Server Compact
4.0 design-time components with Visual Studio.
Does Sql Management Studio work with SSCE 4.0?
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/7588375e-3069-4d68-9365-29feb25b7296/does-sql-management-studio-work-with-ssce-40?forum=sqltools
VS 2010 SP1 and SQL CE
http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx
Thanks.
Tracy Cai
TechNet Community Support -
Why doesn't PIVOT clause work with COLLECT aggregate function in 11g ?
Hello all !
I am really puzzled as to what is considered an aggregate function in the context of the PIVOT clause in 11g.
I have been toying with quite a few things related to collections lately and this arose as an aside :
CREATE TABLE TEST_COLL
NODE_ID VARCHAR2(15 CHAR) NOT NULL,
NODE_VALUE VARCHAR2(45 CHAR) NOT NULL,
NODE_LEVEL NUMBER(1) NOT NULL
CREATE OR REPLACE TYPE TREE_NODE AS OBJECT
NODE_KEY VARCHAR2( 15 CHAR),
NODE_NAME VARCHAR2(127 CHAR)
CREATE OR REPLACE TYPE TREE_NODES AS TABLE OF TREE_NODE NOT NULL;At this stage I am sure we all agree that the query
SELECT NODE_LEVEL,
CAST(COLLECT(TREE_NODE(NODE_ID, NODE_VALUE)) AS TREE_NODES) AS NODES
FROM TEST_COLL
GROUP BY NODE_LEVEL;is perfectly valid as the COLLECT function is an aggregate function according to the [Official Documentation|http://docs.oracle.com/cd/E11882_01/server.112/e10592/functions031.htm#i1271564]
But then, one of the following two queries should work
SELECT CAST(REGION_NODES AS TREE_NODES) AS REGIONS,
CAST(DEPARTMENT_NODES AS TREE_NODES) AS DEPARTMENTS,
CAST(AREA_NODES AS TREE_NODES) AS AREAS,
CAST(CENTRE_NODES AS TREE_NODES) AS CENTRES
FROM (SELECT NODE_LEVEL, TREE_NODE(NODE_ID, NODE_VALUE) AS NODE
FROM TREE_COLL
PIVOT (COLLECT(NODE) FOR NODE_LEVEL IN (1 AS REGION_NODES,
2 AS DEPARTMENT_NODES,
3 AS AREA_NODES,
4 AS CENTRE_NODES
or (better)
SELECT REGION_NODES AS REGIONS,
DEPARTMENT_NODES AS DEPARTMENTS,
AREA_NODES AS AREAS,
CENTRE_NODES AS CENTRES
FROM (SELECT NODE_LEVEL, TREE_NODE(NODE_ID, NODE_VALUE) AS NODE
FROM TREE_COLL
PIVOT (CAST(COLLECT(NODE) AS TREE_NODES) FOR NODE_LEVEL IN (1 AS REGION_NODES,
2 AS DEPARTMENT_NODES,
3 AS AREA_NODES,
4 AS CENTRE_NODES
);yet, both fail with
ORA-56902: expect aggregate function inside pivot operationInvestigating further, I found the same behaviour when using XMLAGG as the aggregate function in the PIVOT clause.
Is this normal ? And if it is, is there any other way to achieve the result I was anticipating ?
My version is
SQL> SELECT BANNER FROM V$VERSION;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - ProductionThanks in advance
Best Regards
PhilipMost likely a bug. But you can bypass it by using any other aggregate making sure group consists of a single row and apply collect to a pivoted value. Yes, the cost is double aggregation. And also there is another cost - you would need to create MAP member function otherwise aggreations like MAX/MIN, etc. will not work:
CREATE OR REPLACE TYPE TREE_NODE AS OBJECT
NODE_KEY VARCHAR2( 15 CHAR),
NODE_NAME VARCHAR2(127 CHAR),
map member function f return varchar2
Type created.
CREATE OR REPLACE TYPE BODY TREE_NODE AS
map member function f return varchar2 is
begin
return NODE_NAME;
end f;
end;
Type body created.
CREATE OR REPLACE TYPE TREE_NODES AS TABLE OF TREE_NODE NOT NULL
Type created.
SQL> select *
2 from test_coll
3 /
NODE_ID NODE_VALUE NODE_LEVEL
1 A 1
2 B 2
3 C 3
4 D 4
5 E 1
6 F 2
7 G 3
8 H 4
8 rows selected.
SQL> Now:
SELECT CAST(COLLECT(REGION_NODES) AS TREE_NODES) AS REGIONS,
CAST(COLLECT(DEPARTMENT_NODES) AS TREE_NODES) AS DEPARTMENTS,
CAST(COLLECT(AREA_NODES) AS TREE_NODES) AS AREAS,
CAST(COLLECT(CENTRE_NODES) AS TREE_NODES) AS CENTRES
FROM (
SELECT ROWID RID,
NODE_LEVEL,
TREE_NODE(NODE_ID, NODE_VALUE) AS NODE
FROM TEST_COLL
PIVOT (MAX(NODE) FOR NODE_LEVEL IN (
1 AS REGION_NODES,
2 AS DEPARTMENT_NODES,
3 AS AREA_NODES,
4 AS CENTRE_NODES
REGIONS(NODE_KEY, NODE_NAME) DEPARTMENTS(NODE_KEY, NODE_NAME) AREAS(NODE_KEY, NODE_NAME) CENTRES(NODE_KEY, NODE_NAME)
TREE_NODES(TREE_NODE('1', 'A'), TREE_NODE('5', 'E')) TREE_NODES(TREE_NODE('6', 'F'), TREE_NODE('2', 'B')) TREE_NODES(TREE_NODE('7', 'G'), TREE_NODE('3', 'C')) TREE_NODES(TREE_NODE('8', 'H'), TREE_NODE('4', 'D'))
SQL> SY. -
Hi. I had a List in my page, and using JSTL could happily use <c:foreach /> to scan through it, and each of my objects in the List could succesfully be used for output with their setters and getters.
Now I have a new situation where I have a Map, which contains a number of pairings of a Key to a List. Then each List contains one or more Maps. I need to use JSTL to work through the structure until I get a reference to the final Map. Can this be done?
So I have...
Map (key---->List)
List--of several---Map
I need ref to this map.
Thanks!Hi,
According to your description, you might want to gather all the SPWeb object into a collection object in order to delete all of them finally.
As we can see, there is no such method in
SPWebCollection object can meet you requirement, as a workaround, we can push all the SPWeb objects into an array, then operate
these SPWeb objects in this array would do the trick.
Here is a link about how to create a generic collection for a list of objects:
http://www.andreasbijl.com/powershell-create-collections-of-custom-objects/
More information about using collection in PowerShell:
https://www.simple-talk.com/sysadmin/powershell/powershell-one-liners--collections,-hashtables,-arrays-and-strings/
Best regards,
Patrick
Patrick Liang
TechNet Community Support -
Working with Images in PL/SQL
Hello,
I want to insert rows into a table having a column of LONG RAW
type. I can do that from Forms 4.5 onwards, but, how can I do
the same if I'm not using any of the front-end tools from
Oracle. To be specific, is it possible to from PL/SQL writing
any procedures etc ... Please let me know
Thanks
KeshabaAshok,
Thanks for the reply. but, is it possible to do with Oracle 7. I
think LOB datatype was introduced in Oracle 8 only.
- Keshaba -
How JAVA works with collection from function
All,
I have a DB function which returns object collection of values. Could someone please tell me how java talks with the function and get the value?
ThanksThis is database function. my question is how java get those values from the function.
Could you please post some sample code also?
CREATE OR REPLACE
Type T_PREO_RoleINFO is Object
ROLE_ID NUMBER(10),
ROLE_NAME VARCHAR2(20))
CREATE OR REPLACE
TYPE T_RoleInfo IS TABLE OF PREORDER.
T_PREO_RoleINFO
Function F_GetUserRole(Userid in number)
return T_RoleInfo as
V_Role T_RoleInfo;
begin
select T_PREO_RoleINFO(PREO_Role.ROLE_ID,PREO_Role.ROLE_NAME)
BULK COLLECT INTO V_Role
from preorder.PREO_Role, preorder.PREO_User_Role
where PREO_Role.Role_id = PREO_User_Role.Role_id
and PREO_User_Role.user_id = userid;
return V_Role;
end; -
Will Report Builder 2012 Work with SQL Server 2008???
Simple question really
Will Report Builder 2012 work in conjunction with SQL Server 2008???
Is it worth while upgrading?
The main reason i ask is the ability to export in an xlsx format
ThanksHi Gmach,
The version of Report Builder on SQL Server Reporting Service (SSRS) 2012 is Report Builder 3.0. The Report Builder 3.0 manufactures 2010 RDL reports, so it only works with the version of SQL Server 2008 R2 or later. So in your scenario, we can no connect
to SQL Server 2008 Server using Report Builder that on SSRS 2012.
If you have any questions, please feel free to ask.
Regards,
Charlie Liao
TechNet Community Support -
PreparedStatement not working with Oracle
Hi All,
I am using preparedStatement in my JDBC code to fetch/insert values from oracle9i database.
I am checking condition like if a given record does not exist then insert it else update it.
First time it works when there is no row in database, however for subsequent run it's not able to return me the result though that row exist in database and this resulting in DuplicateKeyException becuase it try to create the row in db again.
The code is working fine for MySQL DB2 and SQLServer but doesn't work in case oracle 9i
Here is mycode
//problem is here 1st time it works next time it is not retunring true though record is there in DB.
if(isItemExist("1","CORP"))
updateItem("1","CORP","DESC1");
else
insertItem("1","CORP","DESC1");
public boolean isItemExist(String itemid, String storeid)
String FIND_SQL = "SELECT item_desc from item where item_id = ? and store_id = ? ";
c = utils.getConnection();
ps = c.prepareStatement();
int i = 1;
ps.setString(i++, storeid);
ps.setString(i++, itemid);
rs = ps.executeQuery();
if(rs.next()){
return true;
utils.close(c, ps, rs);
else{
return false;
utils.close(c, ps, rs);
public void createItem(String itemid, String storeid, String item_desc)
String INSERT_SQL = "INSERT INTO item(item_id,store_id,item_desc)values(?, ?, ?)";
c = utils.getConnection();
ps = c.prepareStatement();
int i = 1;
ps.setString(i++, itemid);
ps.setString(i++, storeid);
ps.setString(i++, item_desc);
ps.executeUpdate();
utils.close(c, ps, null);
public void updateItem(String itemid, String storeid, String item_desc)
String INSERT_SQL = "UPDATE item SET item_desc = ?, store_id=? WHERE item_id = ?";
c = utils.getConnection();
ps = c.prepareStatement();
int i = 1;
ps.setString(i++, item_desc);
ps.setString(i++, storeid);
ps.setString(i++, itemid);
ps.executeUpdate();
utils.close(c, ps, null);
Kindly suggest what's wrong with code. because same code works with other databse like SQL Server, MySQL but it is not working with oracle9i.if(isItemExist("1","CORP"))
updateItem("1","CORP","DESC1");
else
insertItem("1","CORP","DESC1");
String FIND_SQL = "SELECT item_desc from item where item_id = ? and store_id = ? ";
ps.setString(i++, storeid);
ps.setString(i++, itemid);
String INSERT_SQL = "INSERT INTO item(item_id,store_id,item_desc)values(?, ?, ?)";
ps.setString(i++, itemid);
ps.setString(i++, storeid);
ps.setString(i++, item_desc);
String INSERT_SQL = "UPDATE item SET item_desc = ?, store_id=? WHERE item_id = ?";
ps.setString(i++, item_desc);
ps.setString(i++, storeid);
ps.setString(i++, itemid);My first guess, looking at the above snippets, would be that the item_id field is a number and not a string and so you should be calling ps.setInt instead of ps.setString when setting that parameter.
This is only a guess, however, since you have not posted what the actual error is, which will probably give a hint to what the actual error is. -
Problems with collective search help
Hello SDNers,
I was working with collective search help.
Ex : zc_srch1 (Collective)
In the 'Include search help' i have included 2 search elementary search
help
Ex : zsrc1 and zsrc2 (both elementary)
I have also assigned the parameter assignment for each included search help.
I have also mentioned the search help parameter under definition tab
Ex field form zsrch1 and field1 from zsrch2
and also checked the import and export checkboxes.
Now i have used the search help in the abap program
ex: tmp type field1 matchcode object zc_srch1.
Now when i execute the program the collective search help is getting populated. when i try to choose a value it is not getting selected to the parameter box.
Regards,
Ranjith NHi,
Once again check back your seach help creation by following the link below.
http://help.sap.com/saphelp_erp2005/helpdata/en/cf/21ee86446011d189700000e8322d00/content.htm
Cheers!!
VEnk@ -
Problems working with source files
Just downloaded the new 1343 release. Really like the product. But ... working with source files in SQL Developer is my worst nightmare. When I open a source file either from SQL Worksheet or from File/Open menu my PC freezes for an extended period of time. CPU utilization shots up to 100% and stays this high until the tab is open. I am on Windows XPSP2. Help!!!.
We have reproduced your issue. If I open a large plsql program from the main SQL developer window (File Open) option it opens in a second or less. If from within the SQL worksheet, i right click and do a file / open on a small file it open in a second or less. If I right click in the SQL worksheet and do a file/open of a larger plsql program it appears to hang SQL developer.
We are looking into the issue.
Thanks,
Mike -
Procedure failed while using bulk collect into clause and works with cursor
hi all,
I am using "BULK collect into" clause in my procedure and it is failing after 21 minutes and gives the error "end of file communication channel".
after this error comes when i tried to connect database it is giving following error.
ORA -01034 - Oracle not available.
ORA- 27101 - shared memory realm does not exist.
svr4- error :2 : No such file or directory.
when i use cursor instead of BULK COLLECT INTO clause it is running successful.
Following code is working with cursor.
procedure work_kiosk_full(an_jobid in number ,ac_sqlcode out varchar2 ,ac_sqlerrm out varchar2) is
ld_curr_time Date;
cursor cur_work_kiosk is
select distinct jt.jt_id AS jt_id,
NVL ((ROUND ((jt_date_completed - jt_date_requested) * 24, 2)
0
) AS actual_hrs_to_complete,
NVL ((ROUND ((jt_date_responded - jt_date_requested) * 24, 2)
0
) AS actual_hrs_to_respond,
peo1.peo_name AS agent_name,
peo1.peo_user_name AS asagent_soe_id,
le.lglent_desc AS ap_system,
' ' AS assign_work_request_comment,
DECODE (jt.jt_bill_id,
138802, 'CLIENT BILLABLE',
138803, 'CONTRACTED',
138804, 'INTERNAL BILLABLE',
NULL, ' '
) AS billable,
bl.bldg_name_cc AS building, bl.bldg_id_ls AS building_id,
DECODE (bl.bldg_active_cc,
'Y', 'ACTIVE',
'INACTIVE'
) AS building_status,
DECODE (jt.jt_wrk_cause_id,
141521, 'STANDARD WEAR AND TEAR',
141522, 'NEGLIGENCE',
141523, 'ACCIDENTAL',
141524, 'MECHANICAL MALFUNCTION',
141525, 'OVERSIGHT',
141526, 'VANDAL',
141527, 'STANDARD',
141528, 'PROJECT WORK',
6058229, 'TEST',
NULL, ' '
) AS cause_type,
' ' AS comments, peo3.peo_name AS completed_by,
jt.jt_requestor_email AS contact_email,
jt.jt_requestor_name_first
|| ' '
|| jt.jt_requestor_name_last AS contact_name,
jt.jt_requestor_phone AS contact_phone,
cc.cstctrcd_apcode AS corp_code,
cc.cstctrcd_code AS cost_center,
jt.jt_date_closed AS date_closed,
jt.jt_date_completed AS date_completed,
jt.jt_date_requested AS date_requested,
jt.jt_date_responded AS date_responded,
jt.jt_date_response_ecd AS date_response_ecd,
jt.jt_date_scheduled AS date_scheduled,
DECODE (jt.jt_def_id,
139949, 'WTG VENDOR RESPONSE',
139950, 'WAITING ON PARTS',
139951, 'LABOR AVAILABILITY',
139952, 'DEFERRED- HI PRI WORK',
139953, 'WTG APPROVAL',
139954, 'FUNDING REQUIRED',
139955, 'ACCESS DENIED',
139956, 'WTG MATERIAL',
NULL, ' '
) AS deferral_reason,
jt.jt_description AS description,
jt.jt_date_resched_ecd AS ecd,
fmg.facility_manager AS facility_manager,
fl.floors_text AS FLOOR, gl.genled_desc AS general_ledger,
' ' AS kiosk_date_requested, ' ' AS kiosk_dispatch_confirmed,
' ' AS kiosk_dispatched,
eqp.equip_customer_code AS linked_equipment_alias,
eqp.equip_id AS linked_equipment_id,
eqp.equip_text AS linked_equipment_name,
DECODE (jt_originator_type_id,
1000, 'PROJECT MOVE REQUEST',
138834, 'CUSTOMER INITIATED CORRECTION',
138835, 'CUSTOMER INITIATED REQUEST',
138836, 'CORRECTIVE MAINTENANCE',
138837, 'CONFERENCE ROOM BOOKING',
138838, 'PROJECT INITIATED REQUEST',
138839, 'PLANNED PREVENTIVE MAINTENANCE',
138840, 'SELF INITATED REQUEST',
NULL, ' '
) AS originator_type,
' ' AS payment_terms, priority_text AS priority_code,
swoty.sworktype_text AS problem_type,
prop.property_name_cc AS property,
jt.jt_cost_quote_total AS quote_total,
par.levels_name AS region,
DECODE (jt.jt_repdef_id,
141534, 'ADJUSTED SETTING',
141535, 'TRAINING FOR END',
141536, 'NEW REQUEST',
141537, 'NO REPAIR REQUIR',
141538, 'REPLACED PARTS',
141539, 'REPLACE EQUIPMEN',
1000699, 'NEW REQUEST',
NULL, ' '
) AS repair_definitions,
jt.jt_repairdesc AS repair_description,
jt.jt_requestor AS requestor, ' ' AS requestor_cost_center,
jt.jt_requestor_email AS requestor_email,
jt.jt_requestor_name_first AS requestor_name,
jt.jt_requestor_phone AS requestor_phone,
' ' AS response_time, rm.room_name_cc AS room,
p1.peo_provider_code1 AS service_provider,
p1.peo_address_1 AS service_provider_address,
peocity.city_text service_provider_city,
p1.peo_provider_code1 AS service_provider_code,
peocity.city_country_name AS service_provider_country,
peocur.currency_text AS service_provider_currency,
p1.peo_name AS service_provider_description,
p1.peo_dispatch_method AS serv_prov_dispatc_hmethod,
p1.peo_rate_double AS serv_prov_double_time_rate,
p1.peo_email AS service_provider_email,
p1.peo_emergency_phone AS serv_prov_emergency_phone,
p1.peo_fax AS service_provider_fax_number,
p1.peo_home_phone AS service_provider_home_phone,
p1.peo_rate_hourly AS service_provider_hourly_rate,
p1.peo_title AS service_provider_job_title,
p1.peo_method_id AS service_provider_method,
p1.peo_cell_phone AS service_provider_mobile_phone,
p1.peo_pager AS service_provider_pager,
p1.peo_rate_differential AS service_provider_rates,
p1.peo_rate_differential AS ser_prov_shift_differential,
peocity.city_state_prov_text AS serv_prov_state_province,
DECODE (p1.peo_active,
'Y', 'ACTIVE',
'INACTIVE'
) AS service_provider_status,
p1.peo_url AS serv_prov_web_site_address,
p1.peo_phone AS service_provider_work_phone,
p1.peo_postal_code AS serv_prov_zip_postal_code, ' ' AS shift,
' ' AS skill,
DECODE (jt.jt_bigstatus_id,
138813, 'NEW',
138814, 'PENDING',
138815, 'OPEN',
138816, 'COMPLETED',
138817, 'CLOSED',
138818, 'CANCELLED',
NULL, ' '
) AS status,
lev.levels_name AS subregion, ' ' AS trade,
p1.peo_ls_interface_code1 AS vendor_id,
p1.peo_fax AS vendor_purchasing_fax,
p1.peo_vendor_site_code AS vendor_sitecode,
jt.jt_id AS vendor_ticket, p1.peo_name AS vendor_companyname,
jt.jt_requestor_vip AS vip, wo.wo_id AS work_order_no,
jt.jt_id AS work_request,
jt.jt_class_id AS work_request_class,
woty.worktype_text AS work_type, ' ' AS wr_cost,
jt.jt_description AS wr_description,
' ' AS wr_dispatch_method,
DECODE (jt.jt_bigstatus_id,
138813, 'NEW',
138814, 'PENDING',
138815, 'OPEN',
138816, 'COMPLETED',
138817, 'CLOSED',
138818, 'CANCELLED',
NULL, ' '
) AS wr_status,
ctry.country_name AS country
FROM citi.jobticket jt,
citi.property prop,
citi.bldg bl,
citi.bldg_levels bldglvl,
citi.LEVELS lev,
citi.LEVELS par,
(SELECT crstools.stragg (peo_name) facility_manager,
bldgcon_bldg_id
FROM citi.bldg_contacts, citi.people
WHERE bldgcon_peo_id = peo_id
AND bldgcon_contype_id IN (40181, 10142)
GROUP BY bldgcon_bldg_id) fmg,
citi.floors fl,
citi.room rm,
citi.general_ledger gl,
citi.legal_entity le,
citi.cost_center_codes cc,
citi.equipment eqp,
citi.worktype woty,
citi.subworktype swoty,
citi.work_order wo,
citi.jt_workers jtwo,
citi.priority,
citi.country ctry,
citi.people p1,
citi.people peo3,
citi.people peo1,
citi.city peocity,
citi.currency peocur
WHERE jt.jt_bldg_id = bl.bldg_id
AND bl.bldg_id = bldglvl.bldg_levels_bldg_id
AND bldglvl.bldg_levels_levels_id = lev.levels_id
AND lev.levels_parent = par.levels_id(+)
AND prop.property_id = bl.bldg_property_id
AND bl.bldg_active_ls <> 'N'
AND jt.jt_floors_id = fl.floors_id(+)
AND jt.jt_room_id = rm.room_id(+)
AND jt.jt_bldg_id = fmg.bldgcon_bldg_id(+)
AND jt.jt_genled_id = gl.genled_id(+)
AND gl.genled_lglent_id = le.lglent_id(+)
AND jt.jt_cstctrcd_id = cc.cstctrcd_id(+)
AND jt.jt_equip_id = eqp.equip_id(+)
AND jt.jt_id = jtwo.jtw_jt_id(+)
AND jt.jt_worktype_id = woty.worktype_id(+)
AND jt.jt_sworktype_id = swoty.sworktype_id(+)
AND jt.jt_wo_id = wo.wo_id
AND jt.jt_priority_id = priority_id(+)
--AND jt.jt_date_requested >= ADD_MONTHS (SYSDATE, -12)
AND jt.jt_last_update >= ADD_MONTHS (ld_curr_time, -12)
AND bl.bldg_country_id = ctry.country_id
AND jtwo.jtw_peo_id = p1.peo_id(+)
AND p1.peo_city_id = peocity.city_id(+)
AND jt.jt_completed_by_peo_id = peo3.peo_id(+)
AND p1.peo_rate_currency_id = peocur.currency_id(+)
AND jt.jt_agent_peo_id = peo1.peo_id(+);
BEGIN
execute immediate 'truncate table crstools.drt_bom_work_kiosk';
select sysdate into ld_curr_time from dual;
FOR cur_rec in cur_work_kiosk LOOP
IF MOD(cur_work_kiosk%rowcount,10000 ) = 0 then
COMMIT;
END IF;
INSERT INTO crstools.drt_bom_work_kiosk
( JT_ID
,ACTUAL_HRS_TO_COMPLETE
,ACTUAL_HRS_TO_RESPOND
,AGENT_NAME
,ASAGENT_SOE_ID
,AP_SYSTEM
,ASSIGN_WORK_REQUEST_COMMENT
,BILLABLE
,BUILDING
,BUILDING_ID
,BUILDING_STATUS
,CAUSE_TYPE
,COMMENTS
,COMPLETED_BY
,CONTACT_EMAIL
,CONTACT_NAME
,CONTACT_PHONE
,CORP_CODE
,COST_CENTER
,DATE_CLOSED
,DATE_COMPLETED
,DATE_REQUESTED
,DATE_RESPONDED
,DATE_RESPONSE_ECD
,DATE_SCHEDULED
,DEFERRAL_REASON
,DESCRIPTION
,ECD
,FACILITY_MANAGER
,FLOOR
,GENERAL_LEDGER
,KIOSK_DATE_REQUESTED
,KIOSK_DISPATCH_CONFIRMED
,KIOSK_DISPATCHED
,LINKED_EQUIPMENT_ALIAS
,LINKED_EQUIPMENT_ID
,LINKED_EQUIPMENT_NAME
,ORIGINATOR_TYPE
,PAYMENT_TERMS
,PRIORITY_CODE
,PROBLEM_TYPE
,PROPERTY
,QUOTE_TOTAL
,REGION
,REPAIR_DEFINITIONS
,REPAIR_DESCRIPTION
,REQUESTOR
,REQUESTOR_COST_CENTER
,REQUESTOR_EMAIL
,REQUESTOR_NAME
,REQUESTOR_PHONE
,RESPONSE_TIME
,ROOM
,SERVICE_PROVIDER
,SERVICE_PROVIDER_ADDRESS
,SERVICE_PROVIDER_CITY
,SERVICE_PROVIDER_CODE
,SERVICE_PROVIDER_COUNTRY
,SERVICE_PROVIDER_CURRENCY
,SERVICE_PROVIDER_DESCRIPTION
,SERV_PROV_DISPATC_HMETHOD
,SERV_PROV_DOUBLE_TIME_RATE
,SERVICE_PROVIDER_EMAIL
,SERV_PROV_EMERGENCY_PHONE
,SERVICE_PROVIDER_FAX_NUMBER
,SERVICE_PROVIDER_HOME_PHONE
,SERVICE_PROVIDER_HOURLY_RATE
,SERVICE_PROVIDER_JOB_TITLE
,SERVICE_PROVIDER_METHOD
,SERVICE_PROVIDER_MOBILE_PHONE
,SERVICE_PROVIDER_PAGER
,SERVICE_PROVIDER_RATES
,SER_PROV_SHIFT_DIFFERENTIAL
,SERV_PROV_STATE_PROVINCE
,SERVICE_PROVIDER_STATUS
,SERV_PROV_WEB_SITE_ADDRESS
,SERVICE_PROVIDER_WORK_PHONE
,SERV_PROV_ZIP_POSTAL_CODE
,SHIFT
,SKILL
,STATUS
,SUBREGION
,TRADE
,VENDOR_ID
,VENDOR_PURCHASING_FAX
,VENDOR_SITECODE
,VENDOR_TICKET
,VENDOR_COMPANYNAME
,VIP
,WORK_ORDER_NO
,WORK_REQUEST
,WORK_REQUEST_CLASS
,WORK_TYPE
,WR_COST
,WR_DESCRIPTION
,WR_DISPATCH_METHOD
,WR_STATUS
,COUNTRY
,CREATE_DATE
VALUES
(cur_rec.jt_id
,cur_rec.ACTUAL_HRS_TO_COMPLETE
,cur_rec.ACTUAL_HRS_TO_RESPOND
,cur_rec.AGENT_NAME
,cur_rec.ASAGENT_SOE_ID
,cur_rec.AP_SYSTEM
,cur_rec.ASSIGN_WORK_REQUEST_COMMENT
,cur_rec.BILLABLE
,cur_rec.BUILDING
,cur_rec.BUILDING_ID
,cur_rec.BUILDING_STATUS
,cur_rec.CAUSE_TYPE
,cur_rec.COMMENTS
,cur_rec.COMPLETED_BY
,cur_rec.CONTACT_EMAIL
,cur_rec.CONTACT_NAME
,cur_rec.CONTACT_PHONE
,cur_rec.CORP_CODE
,cur_rec.COST_CENTER
,cur_rec.DATE_CLOSED
,cur_rec.DATE_COMPLETED
,cur_rec.DATE_REQUESTED
,cur_rec.DATE_RESPONDED
,cur_rec.DATE_RESPONSE_ECD
,cur_rec.DATE_SCHEDULED
,cur_rec.DEFERRAL_REASON
,cur_rec.DESCRIPTION
,cur_rec.ECD
,cur_rec.FACILITY_MANAGER
,cur_rec.FLOOR
,cur_rec.GENERAL_LEDGER
,cur_rec.KIOSK_DATE_REQUESTED
,cur_rec.KIOSK_DISPATCH_CONFIRMED
,cur_rec.KIOSK_DISPATCHED
,cur_rec.LINKED_EQUIPMENT_ALIAS
,cur_rec.LINKED_EQUIPMENT_ID
,cur_rec.LINKED_EQUIPMENT_NAME
,cur_rec.ORIGINATOR_TYPE
,cur_rec.PAYMENT_TERMS
,cur_rec.PRIORITY_CODE
,cur_rec.PROBLEM_TYPE
,cur_rec.PROPERTY
,cur_rec.QUOTE_TOTAL
,cur_rec.REGION
,cur_rec.REPAIR_DEFINITIONS
,cur_rec.REPAIR_DESCRIPTION
,cur_rec.REQUESTOR
,cur_rec.REQUESTOR_COST_CENTER
,cur_rec.REQUESTOR_EMAIL
,cur_rec.REQUESTOR_NAME
,cur_rec.REQUESTOR_PHONE
,cur_rec.RESPONSE_TIME
,cur_rec.ROOM
,cur_rec.SERVICE_PROVIDER
,cur_rec.SERVICE_PROVIDER_ADDRESS
,cur_rec.SERVICE_PROVIDER_CITY
,cur_rec.SERVICE_PROVIDER_CODE
,cur_rec.SERVICE_PROVIDER_COUNTRY
,cur_rec.SERVICE_PROVIDER_CURRENCY
,cur_rec.SERVICE_PROVIDER_DESCRIPTION
,cur_rec.SERV_PROV_DISPATC_HMETHOD
,cur_rec.SERV_PROV_DOUBLE_TIME_RATE
,cur_rec.SERVICE_PROVIDER_EMAIL
,cur_rec.SERV_PROV_EMERGENCY_PHONE
,cur_rec.SERVICE_PROVIDER_FAX_NUMBER
,cur_rec.SERVICE_PROVIDER_HOME_PHONE
,cur_rec.SERVICE_PROVIDER_HOURLY_RATE
,cur_rec.SERVICE_PROVIDER_JOB_TITLE
,cur_rec.SERVICE_PROVIDER_METHOD
,cur_rec.SERVICE_PROVIDER_MOBILE_PHONE
,cur_rec.SERVICE_PROVIDER_PAGER
,cur_rec.SERVICE_PROVIDER_RATES
,cur_rec.SER_PROV_SHIFT_DIFFERENTIAL
,cur_rec.SERV_PROV_STATE_PROVINCE
,cur_rec.SERVICE_PROVIDER_STATUS
,cur_rec.SERV_PROV_WEB_SITE_ADDRESS
,cur_rec.SERVICE_PROVIDER_WORK_PHONE
,cur_rec.SERV_PROV_ZIP_POSTAL_CODE
,cur_rec.SHIFT
,cur_rec.SKILL
,cur_rec.STATUS
,cur_rec.SUBREGION
,cur_rec.TRADE
,cur_rec.VENDOR_ID
,cur_rec.VENDOR_PURCHASING_FAX
,cur_rec.VENDOR_SITECODE
,cur_rec.VENDOR_TICKET
,cur_rec.VENDOR_COMPANYNAME
,cur_rec.VIP
,cur_rec.WORK_ORDER_NO
,cur_rec.WORK_REQUEST
,cur_rec.WORK_REQUEST_CLASS
,cur_rec.WORK_TYPE
,cur_rec.WR_COST
,cur_rec.WR_DESCRIPTION
,cur_rec.WR_DISPATCH_METHOD
,cur_rec.WR_STATUS
,cur_rec.COUNTRY
,ld_curr_time
END LOOP;
COMMIT;
exception
when others then
rollback;
dbms_output.put_line('SQLCODE :'||sqlcode ||' Error :'||sqlerrm);
end work_kiosk_full;
Note : total record inserted 849000.
The same code does not work with bulk collect into caluse.
Please help me out why this is happening.
Thanks & regards
shyam~Shyam,
I agree with Billy.
Why are you not using an INSERT..SELECT ?
Also, what are you trying to achieve by
- incremental commits?
- copying data from one table to another (using expensive I/O)?
- using dynamic DML?
Most of these approaches are typically wrong - and not recommended for scalable and performant Oracle applications.I could see you using a CURSOR FOR LOOP if you were changing the data being inserted in such a way that you couldn't encapsulate the changes in a query, but you are doing a straight insert into the table from your Cursor. A much more efficient way would be to use the following modifications I made to your code example:
PROCEDURE WORK_KIOSK_FULL(AN_JOBID IN NUMBER,
AC_SQLCODE OUT VARCHAR2,
AC_SQLERRM OUT VARCHAR2) IS
BEGIN
EXECUTE IMMEDIATE 'truncate table crstools.drt_bom_work_kiosk';
/* Note: The APPEND hint forces a Direct Path INSERT (see Link below code sample) and is combined with the NOLOGGING Hint */
/* To dramtically increase performance. The Direct Path INSERT inserts records above the High-Water Mark on the table. */
INSERT /*+ APPEND NOLOGGING */ INTO CRSTOOLS.DRT_BOM_WORK_KIOSK
(JT_ID
,ACTUAL_HRS_TO_COMPLETE
,ACTUAL_HRS_TO_RESPOND
,AGENT_NAME
,ASAGENT_SOE_ID
,AP_SYSTEM
-- ,ASSIGN_WORK_REQUEST_COMMENT /* I commented out this COLUMN because it doesn't make sense to me to insert */
,BILLABLE /* a couple of space characters into a table. If the intent is to leave the column NULL */
,BUILDING /* don't include it in your INSERT statement and it will be NULL. If there is a valid reason */
,BUILDING_ID /* for inserting the spaces, then remove the "line comments" from the insert and select statments */
,BUILDING_STATUS
,CAUSE_TYPE
-- ,COMMENTS
,COMPLETED_BY
,CONTACT_EMAIL
,CONTACT_NAME
,CONTACT_PHONE
,CORP_CODE
,COST_CENTER
,DATE_CLOSED
,DATE_COMPLETED
,DATE_REQUESTED
,DATE_RESPONDED
,DATE_RESPONSE_ECD
,DATE_SCHEDULED
,DEFERRAL_REASON
,DESCRIPTION
,ECD
,FACILITY_MANAGER
,FLOOR
,GENERAL_LEDGER
-- ,KIOSK_DATE_REQUESTED
-- ,KIOSK_DISPATCH_CONFIRMED
-- ,KIOSK_DISPATCHED
,LINKED_EQUIPMENT_ALIAS
,LINKED_EQUIPMENT_ID
,LINKED_EQUIPMENT_NAME
,ORIGINATOR_TYPE
-- ,PAYMENT_TERMS
,PRIORITY_CODE
,PROBLEM_TYPE
,PROPERTY
,QUOTE_TOTAL
,REGION
,REPAIR_DEFINITIONS
,REPAIR_DESCRIPTION
,REQUESTOR
-- ,REQUESTOR_COST_CENTER
,REQUESTOR_EMAIL
,REQUESTOR_NAME
,REQUESTOR_PHONE
-- ,RESPONSE_TIME
,ROOM
,SERVICE_PROVIDER
,SERVICE_PROVIDER_ADDRESS
,SERVICE_PROVIDER_CITY
,SERVICE_PROVIDER_CODE
,SERVICE_PROVIDER_COUNTRY
,SERVICE_PROVIDER_CURRENCY
,SERVICE_PROVIDER_DESCRIPTION
,SERV_PROV_DISPATC_HMETHOD
,SERV_PROV_DOUBLE_TIME_RATE
,SERVICE_PROVIDER_EMAIL
,SERV_PROV_EMERGENCY_PHONE
,SERVICE_PROVIDER_FAX_NUMBER
,SERVICE_PROVIDER_HOME_PHONE
,SERVICE_PROVIDER_HOURLY_RATE
,SERVICE_PROVIDER_JOB_TITLE
,SERVICE_PROVIDER_METHOD
,SERVICE_PROVIDER_MOBILE_PHONE
,SERVICE_PROVIDER_PAGER
,SERVICE_PROVIDER_RATES
,SER_PROV_SHIFT_DIFFERENTIAL
,SERV_PROV_STATE_PROVINCE
,SERVICE_PROVIDER_STATUS
,SERV_PROV_WEB_SITE_ADDRESS
,SERVICE_PROVIDER_WORK_PHONE
,SERV_PROV_ZIP_POSTAL_CODE
-- ,SHIFT
-- ,SKILL
,STATUS
,SUBREGION
-- ,TRADE
,VENDOR_ID
,VENDOR_PURCHASING_FAX
,VENDOR_SITECODE
,VENDOR_TICKET
,VENDOR_COMPANYNAME
,VIP
,WORK_ORDER_NO
,WORK_REQUEST
,WORK_REQUEST_CLASS
,WORK_TYPE
-- ,WR_COST
,WR_DESCRIPTION
-- ,WR_DISPATCH_METHOD
,WR_STATUS
,COUNTRY
,CREATE_DATE
VALUES
(SELECT DISTINCT
JT.JT_ID AS JT_ID
,NVL((ROUND((JT_DATE_COMPLETED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_COMPLETE
,NVL((ROUND((JT_DATE_RESPONDED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_RESPOND
,PEO1.PEO_NAME AS AGENT_NAME
,PEO1.PEO_USER_NAME AS ASAGENT_SOE_ID
,LE.LGLENT_DESC AS AP_SYSTEM
-- ,' ' AS ASSIGN_WORK_REQUEST_COMMENT
,DECODE(JT.JT_BILL_ID,138802,'CLIENT BILLABLE'
,138803,'CONTRACTED'
,138804,'INTERNAL BILLABLE',NULL,' ') AS BILLABLE
,BL.BLDG_NAME_CC AS BUILDING
,BL.BLDG_ID_LS AS BUILDING_ID
,DECODE(BL.BLDG_ACTIVE_CC, 'Y', 'ACTIVE', 'INACTIVE') AS BUILDING_STATUS
,DECODE(JT.JT_WRK_CAUSE_ID,141521,'STANDARD WEAR AND TEAR'
,141522,'NEGLIGENCE'
,141523,'ACCIDENTAL'
,141524,'MECHANICAL MALFUNCTION'
,141525,'OVERSIGHT'
,141526,'VANDAL'
,141527,'STANDARD'
,141528,'PROJECT WORK'
,6058229,'TEST',NULL,' ') AS CAUSE_TYPE
-- ,' ' AS COMMENTS
,PEO3.PEO_NAME AS COMPLETED_BY
,JT.JT_REQUESTOR_EMAIL AS CONTACT_EMAIL
,JT.JT_REQUESTOR_NAME_FIRST || ' ' ||JT.JT_REQUESTOR_NAME_LAST AS CONTACT_NAME
,JT.JT_REQUESTOR_PHONE AS CONTACT_PHONE
,CC.CSTCTRCD_APCODE AS CORP_CODE
,CC.CSTCTRCD_CODE AS COST_CENTER
,JT.JT_DATE_CLOSED AS DATE_CLOSED
,JT.JT_DATE_COMPLETED AS DATE_COMPLETED
,JT.JT_DATE_REQUESTED AS DATE_REQUESTED
,JT.JT_DATE_RESPONDED AS DATE_RESPONDED
,JT.JT_DATE_RESPONSE_ECD AS DATE_RESPONSE_ECD
,JT.JT_DATE_SCHEDULED AS DATE_SCHEDULED
,DECODE(JT.JT_DEF_ID,139949,'WTG VENDOR RESPONSE'
,139950,'WAITING ON PARTS'
,139951,'LABOR AVAILABILITY'
,139952,'DEFERRED- HI PRI WORK'
,139953,'WTG APPROVAL'
,139954,'FUNDING REQUIRED'
,139955,'ACCESS DENIED'
,139956,'WTG MATERIAL',NULL,' ') AS DEFERRAL_REASON
,JT.JT_DESCRIPTION AS DESCRIPTION
,JT.JT_DATE_RESCHED_ECD AS ECD
,FMG.FACILITY_MANAGER AS FACILITY_MANAGER
,FL.FLOORS_TEXT AS FLOOR
,GL.GENLED_DESC AS GENERAL_LEDGER
-- ,' ' AS KIOSK_DATE_REQUESTED
-- ,' ' AS KIOSK_DISPATCH_CONFIRMED
-- ,' ' AS KIOSK_DISPATCHED
,EQP.EQUIP_CUSTOMER_CODE AS LINKED_EQUIPMENT_ALIAS
,EQP.EQUIP_ID AS LINKED_EQUIPMENT_ID
,EQP.EQUIP_TEXT AS LINKED_EQUIPMENT_NAME
,DECODE(JT_ORIGINATOR_TYPE_ID,1000,'PROJECT MOVE REQUEST'
,138834,'CUSTOMER INITIATED CORRECTION'
,138835,'CUSTOMER INITIATED REQUEST'
,138836,'CORRECTIVE MAINTENANCE'
,138837,'CONFERENCE ROOM BOOKING'
,138838,'PROJECT INITIATED REQUEST'
,138839,'PLANNED PREVENTIVE MAINTENANCE'
,138840,'SELF INITATED REQUEST',NULL,' ') AS ORIGINATOR_TYPE
-- ,' ' AS PAYMENT_TERMS
,PRIORITY_TEXT AS PRIORITY_CODE
,SWOTY.SWORKTYPE_TEXT AS PROBLEM_TYPE
,PROP.PROPERTY_NAME_CC AS PROPERTY
,JT.JT_COST_QUOTE_TOTAL AS QUOTE_TOTAL
,PAR.LEVELS_NAME AS REGION
,DECODE(JT.JT_REPDEF_ID,141534,'ADJUSTED SETTING'
,141535,'TRAINING FOR END'
,141536,'NEW REQUEST'
,141537,'NO REPAIR REQUIR'
,141538,'REPLACED PARTS'
,141539,'REPLACE EQUIPMEN'
,1000699,'NEW REQUEST',NULL,' ') AS REPAIR_DEFINITIONS
,JT.JT_REPAIRDESC AS REPAIR_DESCRIPTION
,JT.JT_REQUESTOR AS REQUESTOR
-- ,' ' AS REQUESTOR_COST_CENTER
,JT.JT_REQUESTOR_EMAIL AS REQUESTOR_EMAIL
,JT.JT_REQUESTOR_NAME_FIRST AS REQUESTOR_NAME
,JT.JT_REQUESTOR_PHONE AS REQUESTOR_PHONE
-- ,' ' AS RESPONSE_TIME
,RM.ROOM_NAME_CC AS ROOM
,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER
,P1.PEO_ADDRESS_1 AS SERVICE_PROVIDER_ADDRESS
,PEOCITY.CITY_TEXT SERVICE_PROVIDER_CITY
,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER_CODE
,PEOCITY.CITY_COUNTRY_NAME AS SERVICE_PROVIDER_COUNTRY
,PEOCUR.CURRENCY_TEXT AS SERVICE_PROVIDER_CURRENCY
,P1.PEO_NAME AS SERVICE_PROVIDER_DESCRIPTION
,P1.PEO_DISPATCH_METHOD AS SERV_PROV_DISPATC_HMETHOD
,P1.PEO_RATE_DOUBLE AS SERV_PROV_DOUBLE_TIME_RATE
,P1.PEO_EMAIL AS SERVICE_PROVIDER_EMAIL
,P1.PEO_EMERGENCY_PHONE AS SERV_PROV_EMERGENCY_PHONE
,P1.PEO_FAX AS SERVICE_PROVIDER_FAX_NUMBER
,P1.PEO_HOME_PHONE AS SERVICE_PROVIDER_HOME_PHONE
,P1.PEO_RATE_HOURLY AS SERVICE_PROVIDER_HOURLY_RATE
,P1.PEO_TITLE AS SERVICE_PROVIDER_JOB_TITLE
,P1.PEO_METHOD_ID AS SERVICE_PROVIDER_METHOD
,P1.PEO_CELL_PHONE AS SERVICE_PROVIDER_MOBILE_PHONE
,P1.PEO_PAGER AS SERVICE_PROVIDER_PAGER
,P1.PEO_RATE_DIFFERENTIAL AS SERVICE_PROVIDER_RATES
,P1.PEO_RATE_DIFFERENTIAL AS SER_PROV_SHIFT_DIFFERENTIAL
,PEOCITY.CITY_STATE_PROV_TEXT AS SERV_PROV_STATE_PROVINCE
,DECODE(P1.PEO_ACTIVE, 'Y', 'ACTIVE', 'INACTIVE') AS SERVICE_PROVIDER_STATUS
,P1.PEO_URL AS SERV_PROV_WEB_SITE_ADDRESS
,P1.PEO_PHONE AS SERVICE_PROVIDER_WORK_PHONE
,P1.PEO_POSTAL_CODE AS SERV_PROV_ZIP_POSTAL_CODE
-- ,' ' AS SHIFT
-- ,' ' AS SKILL
,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
,138814,'PENDING'
,138815,'OPEN'
,138816,'COMPLETED'
,138817,'CLOSED'
,138818,'CANCELLED',NULL,' ') AS STATUS
,LEV.LEVELS_NAME AS SUBREGION
-- ,' ' AS TRADE
,P1.PEO_LS_INTERFACE_CODE1 AS VENDOR_ID
,P1.PEO_FAX AS VENDOR_PURCHASING_FAX
,P1.PEO_VENDOR_SITE_CODE AS VENDOR_SITECODE
,JT.JT_ID AS VENDOR_TICKET
,P1.PEO_NAME AS VENDOR_COMPANYNAME
,JT.JT_REQUESTOR_VIP AS VIP
,WO.WO_ID AS WORK_ORDER_NO
,JT.JT_ID AS WORK_REQUEST
,JT.JT_CLASS_ID AS WORK_REQUEST_CLASS
,WOTY.WORKTYPE_TEXT AS WORK_TYPE
-- ,' ' AS WR_COST
,JT.JT_DESCRIPTION AS WR_DESCRIPTION
-- ,' ' AS WR_DISPATCH_METHOD
,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
,138814,'PENDING'
,138815,'OPEN'
,138816,'COMPLETED'
,138817,'CLOSED'
,138818,'CANCELLED',NULL,' ') AS WR_STATUS
,CTRY.COUNTRY_NAME AS COUNTRY
,SYSDATE --LD_CURR_TIME
FROM CITI.JOBTICKET JT,
CITI.PROPERTY PROP,
CITI.BLDG BL,
CITI.BLDG_LEVELS BLDGLVL,
CITI.LEVELS LEV,
CITI.LEVELS PAR,
(SELECT CRSTOOLS.STRAGG(PEO_NAME) FACILITY_MANAGER,
BLDGCON_BLDG_ID
FROM CITI.BLDG_CONTACTS, CITI.PEOPLE
WHERE BLDGCON_PEO_ID = PEO_ID
AND BLDGCON_CONTYPE_ID IN (40181, 10142)
GROUP BY BLDGCON_BLDG_ID) FMG,
CITI.FLOORS FL,
CITI.ROOM RM,
CITI.GENERAL_LEDGER GL,
CITI.LEGAL_ENTITY LE,
CITI.COST_CENTER_CODES CC,
CITI.EQUIPMENT EQP,
CITI.WORKTYPE WOTY,
CITI.SUBWORKTYPE SWOTY,
CITI.WORK_ORDER WO,
CITI.JT_WORKERS JTWO,
CITI.PRIORITY,
CITI.COUNTRY CTRY,
CITI.PEOPLE P1,
CITI.PEOPLE PEO3,
CITI.PEOPLE PEO1,
CITI.CITY PEOCITY,
CITI.CURRENCY PEOCUR
WHERE JT.JT_BLDG_ID = BL.BLDG_ID
AND BL.BLDG_ID = BLDGLVL.BLDG_LEVELS_BLDG_ID
AND BLDGLVL.BLDG_LEVELS_LEVELS_ID = LEV.LEVELS_ID
AND LEV.LEVELS_PARENT = PAR.LEVELS_ID(+)
AND PROP.PROPERTY_ID = BL.BLDG_PROPERTY_ID
AND BL.BLDG_ACTIVE_LS = 'N'
AND JT.JT_FLOORS_ID = FL.FLOORS_ID(+)
AND JT.JT_ROOM_ID = RM.ROOM_ID(+)
AND JT.JT_BLDG_ID = FMG.BLDGCON_BLDG_ID(+)
AND JT.JT_GENLED_ID = GL.GENLED_ID(+)
AND GL.GENLED_LGLENT_ID = LE.LGLENT_ID(+)
AND JT.JT_CSTCTRCD_ID = CC.CSTCTRCD_ID(+)
AND JT.JT_EQUIP_ID = EQP.EQUIP_ID(+)
AND JT.JT_ID = JTWO.JTW_JT_ID(+)
AND JT.JT_WORKTYPE_ID = WOTY.WORKTYPE_ID(+)
AND JT.JT_SWORKTYPE_ID = SWOTY.SWORKTYPE_ID(+)
AND JT.JT_WO_ID = WO.WO_ID
AND JT.JT_PRIORITY_ID = PRIORITY_ID(+)
--AND jt.jt_date_requested >= ADD_MONTHS (SYSDATE, -12)
AND JT.JT_LAST_UPDATE >= ADD_MONTHS(LD_CURR_TIME, -12)
AND BL.BLDG_COUNTRY_ID = CTRY.COUNTRY_ID
AND JTWO.JTW_PEO_ID = P1.PEO_ID(+)
AND P1.PEO_CITY_ID = PEOCITY.CITY_ID(+)
AND JT.JT_COMPLETED_BY_PEO_ID = PEO3.PEO_ID(+)
AND P1.PEO_RATE_CURRENCY_ID = PEOCUR.CURRENCY_ID(+)
AND JT.JT_AGENT_PEO_ID = PEO1.PEO_ID(+)
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE('SQLCODE :' || SQLCODE || ' Error :' || SQLERRM);
END WORK_KIOSK_FULL;Here's the link for infor on the [Oracle Direct-Path INSERT |http://download.oracle.com/docs/cd/B10501_01/server.920/a96524/c21dlins.htm#10778].
Also, if you are truly intent on using a CURSOR FOR LOOP with the BULK COLLECT, I suggest you read Steven Feuerstein's article [PL/SQL Practices: On BULK COLLECT |http://www.oracle.com/technology/oramag/oracle/08-mar/o28plsql.html].
Hope this helps.
Craig...
If my response or the response of another was helpful, please mark it accordingly -
DISTINCT on object type collection not working with GROUP BY
Hello,
I have an object type with collection defined as:
create or replace type individu_ot as object (
numero_dossier number(10),
code_utilisateur varchar2(8 char),
nom varchar2(25 char),
prenom varchar2(25 char),
map member function individu_map return number
create or replace type body individu_ot is
map member function individu_map return number
is
begin
return SELF.numero_dossier;
end individu_map;
end;
create or replace type individu_ntt is table of individu_ot
/When I use it in simple SQL without any aggregation, the distinct keyword works well and returns me the distinct entry of my object type in the collection:
SQL> select cast(collect(distinct individu_ot(indivmc.numero_dossier, indivmc.idul, indivmc.nom, indivmc.prenom)) as individu_ntt) as distinct_list
from site_section_cours sisc
inner join enseignant_section_mc ensemc
on sisc.code_session = ensemc.code_session and
sisc.numero_reference_section_cours = ensemc.numero_reference_section_cours
inner join individu_mc indivmc
on ensemc.numero_dossier_pidm = indivmc.numero_dossier
where sisc.seq_site_cours = 6
DISTINCT_LIST(NUMERO_DOSSIER,CODE_UTILISATEUR,NOM,PRENOM)
INDIVIDU_NTT(INDIVIDU_OT(15,PROF5,Amidala,Padmé))
1 row selected.However in SQL with broader selection with group by, the distinct isn't working anymore.
SQL> select *
from (
select sisc.seq_site_cours,
cast(collect(distinct individu_ot(indivmc.numero_dossier, indivmc.idul, indivmc.nom, indivmc.prenom)) as individu_ntt) as distinct_list
from site_section_cours sisc
inner join enseignant_section_mc ensemc
on sisc.code_session = ensemc.code_session and
sisc.numero_reference_section_cours = ensemc.numero_reference_section_cours
inner join individu_mc indivmc
on ensemc.numero_dossier_pidm = indivmc.numero_dossier
group by sisc.seq_site_cours
where seq_site_cours = 6
SEQ_SITE_COURS DISTINCT_LIST(NUMERO_DOSSIER,CODE_UTILISATEUR,NOM,PRENOM)
6 INDIVIDU_NTT(INDIVIDU_OT(15,PROF5,Amidala,Padmé),INDIVIDU_OT(15,PROF5,Amidala,Padmé),INDIVIDU_OT(15,PROF5,Amidala,Padmé),INDIVIDU_OT(15,PROF5,Amidala,Padmé),INDIVIDU_OT(15,PROF5,Amidala,Padmé))
1 row selected.there is case where I need to return more than one collections, with distinct entries in it.
Is there something I am missing?
Thanks
BrunoNot a bug, rather an undocumented feature.
Here are some alternatives you might want to test :
1) Using the SET operator to eliminate duplicates :
SELECT sisc.seq_site_cours,
set(
cast(
collect(individu_ot(indivmc.numero_dossier, indivmc.idul, indivmc.nom, indivmc.prenom))
as individu_ntt
) as distinct_list
FROM site_section_cours sisc
INNER JOIN enseignant_section_mc ensemc
ON sisc.code_session = ensemc.code_session
AND sisc.numero_reference_section_cours = ensemc.numero_reference_section_cours
INNER JOIN individu_mc indivmc
ON ensemc.numero_dossier_pidm = indivmc.numero_dossier
GROUP BY sisc.seq_site_cours
;2) Using MULTISET with a subquery
SELECT sisc.seq_site_cours,
CAST(
MULTISET(
SELECT distinct
indivmc.numero_dossier, indivmc.idul, indivmc.nom, indivmc.prenom
FROM enseignant_section_mc ensemc
INNER JOIN individu_mc indivmc
ON ensemc.numero_dossier_pidm = indivmc.numero_dossier
WHERE sisc.code_session = ensemc.code_session
AND sisc.numero_reference_section_cours = ensemc.numero_reference_section_cours
AS individu_ntt
) AS distinct_list
FROM site_section_cours sisc
; -
How to get JDev 10.1.2/ADF working with MS SQL Server Identity Column
Hello JDevTeam & JDevelopers,
I want to use JDev/ADF with a MS SQL Server 2005 database that contains tables employing IDENTITY Columns.
Using JDev/ADF and DBSequence with an Oracle database employing before triggers/sequences accomplishes what I am trying to do except I want to accomplish the same thing using a MSSQL Server 2005 database. Unfortunately I cannot change the database.
I have been able to select records but I am unable to insert records (due to my lack of knowledge) when using MS/SQL Server Identity Columns with JDev/ADF.
The following are the steps taken thus far.
Step1: Create table named test in the 2005 MSSQL Server (see script below).
Step2: Register 3rd Party JDBC Driver with JDeveloper; Using use Tools/Manage Libraries. Create a new entry in User Libraries with the following;
Library Name = Ms2005Jdbc
Class Path = C:\dev\Ms2005Jdbc\sqljdbc_1.0\enu\sqljdbc.jar
(note: Latest TYPE 4 JDBC driver for Microsoft SQL Server 2005 - free at http://msdn.microsoft.com/data/ref/jdbc/)
Step3:Create New Database Connection;
Connection Name = testconn1
Type = Third Party JDBC Driver
Authentication Username = sa, Password = password, Check Deploy Password
Connection
Driver Class = com.microsoft.sqlserver.jdbc.SQLServerDriver
Library = Ms2005Jdbc
Classpath = C:\dev\Ms2005Jdbc\sqljdbc_1.0\enu
URL = jdbc:sqlserver://192.168.1.151:1433;instanceName=sqlexpress;databaseName=test
Test Connection = Success!
Step5: Create a new application workspace using Web Application default template
Step6: In Model project, Create new Business Components Diagram.
Step7: Create new Entity Object. Goto to connections/testconn1, open tables and drag table test onto the diagram.
Step8: Generate Default Data Model Components by right-clicking on Entity Object. Except all the defaults.
When I test the Appmodule I select the view object and can scroll through all the records without error. If I try to insert a record, I get JBO-27014: Attribute testid in test is required.
Going back to the EntityObject I deselect the Mandatory attribute and re-run the test. Now when I try to insert it accepts the value for testname but it does not update the PK testid like it would using an "JDev/ADF/DBSequence/Oracle database/before trigger/sequence" solution.
Going back to the EntityObject and selecting refresh on insert does not solve this problem either. Changing the URL connection string and adding "SelectMethod=cursor" did not help and changing the SQl Flavor to SQLServer produced errors in the Business Components Browser. I've tried overriding isAttributeChanged() and other things as well.
I am totally stuck! Can anyone provide a solution?
Thanks for you help,
BG...
Create table named test
use [testdb]
go
set ansi_nulls on
go
set quoted_identifier on
go
create table [test](
[testid] [int] identity(0,1) not null,
[testname] [nvarchar](50) collate sql_latin1_general_cp1_ci_as not null,
constraint [pk_test] primary key nonclustered
[testid] asc
)with (pad_index = off, ignore_dup_key = off) on [primary]
) on [primary]Figured it out!
When using the MS SQL Server 2000 Database with the MS JDBC 2000 Driver you specify the SQL Flavor to SQLServer. However setting the SQL Flavor to SQLServer with MS SQL Server 2005 Database and the MS JDBC 2005 Driver will *** fail ***.
When working with the MS SQL Server 2005 Database and the MS JDBC 2005 Driver you set the SQL Flavor to SQL92 and the Type Map to Java.
If using a named instance like I am you would specify the URL = jdbc:sqlserver://<db host ip address>:<listening port>;instanceName=<your instance name>;selectMethod=cursor;databaseName=<your database name> (note: leave out the < >)
The 2005 Driver Class is different then the 2000 and is specified as com.microsoft.sqlserver.jdbc.SQLServerDriver
Note: In a default MS SQL Server 2005 installation the listening port will change *** everytime *** the host is restarted! You can override this though.
For the primary key you need to deselect the Mandatory attribute in the EntityObject editor.
Set Refresh on insert/update = no.
Set Updateable = never.
Now my Primary Keys which get their values from the Identity Column are working with ADF in a predictable way.
Simple enough but I have been away from this stuff for awhile.
BG...
Maybe you are looking for
-
Registering the Web based application as a Partner Application
Good day I went through the suggested documentation of registering a web based application as a partner application of the SSO Login Server. I installed the SSOSDK.JAR and went through the demo application (JSP Demo) which consists of the following p
-
I do not want to change my plan, but want to upgrade my device is that possible anymore?
I want to upgrade my families phones but i do not want to change my plans one bit, will the big bad cell phone company let me do that or are they going to be horrible and make me change and yes I will only have a smart phone.
-
Hi, I have a question about using the top N and bottom N conditions in a query. If I set my condition to show the bottom 1, and there are multiple rows that have 0%, then how does the query determine which row to display as the bottom 1? I ask this
-
Hello I have an Imac late 2009; last night everything was running normally and when i got on this morning my computer was turned off which I did not do and I have multiple applications crashing. random addition its been doing this but when I power it
-
File Upload Tomahawk - ClassCast DefaultFileItem and DiskFileItem
Hello, I was trying to upload a file through Tomahawk. But its giving me a ClassCastException. [Servlet Error]-[Faces Servlet]: java.lang.ClassCastException: org.apache.commons.fileupload.DefaultFileItem incompatible with org.apache.commons.fileuploa