First execution of pl/sql block is slow.
Hi,
I've introduced TimesTen to improve performance of a pl/sql block in Oracle.
For that I created certain cachegroups in TimesTen to cache the oracle data.
After everything is done on TimesTen, when we run the pl/sql block on TimesTen, I observed that it is taking 35 Seconds ( against 48 secs on Oracle) for first time execution on Timesten. Subsequent execution of same pl/sql block with same parameters are taking just 6 seconds. I want to achieve the same throughput ( 6 sec) when the pl/sql block is executed for the first time. Can you please suggest what exactly I should look into.
Thanks
Amit
Thanks you so much Chris for your response.
Please find the requested info here:
1=>
C:\TimesTen\tt1122_64\bin>ttversion
TimesTen Release 11.2.2.5.0 (64 bit NT) (tt1122_64:53396) 2013-05-23T16:26:12Z
Instance admin: shuklaam
Instance home directory: C:\TimesTen\TT1122~1\
Group owner: ES\Domain Users
Daemon home directory: C:\TimesTen\TT1122~1\srv\info
PL/SQL enabled.
2, 3=>Complete DSN definition and CG definitions is available in the doc here https://docs.google.com/file/d/0BxQyEfoOqCkDWVZmSG90NUd5bGM/edit?usp=sharing
4=>I can't share the source code due to my company policies, but I'm explaining here what exactly it is doing.
1. Based on the parameters to the proc, build a cursor, and fetch records from various tables.
2. insert them into pl/sql tables.
3. Do some calculations on those records, & calculate certain amounts.
4. Insert these values into a temporary table, and display to the UI.
At the same time, I found a metalink note 1272819.1 which stats this is a known phenomena. Not sure if setting DSN attribute MemoryLock=4 will resolve the issue.
Also, I couldn't find this attribute in windows DSN definition any where. Can you please point me where exactly I need to set it.
Thanks
Amit
Similar Messages
-
Hi Masters,
I was attended one technical interview two days back. The interviewer asked me the below pl/sql output and explain the process. I said it won't give any error and answer also. He is not happy with execution process.
Please find below pl/sql block. Please explain me how control will execution the pl/sql block?
begin
v_sal numbber(5);
select sal into v_sal
from emp
where deptno=60;
exception
when no_data_found then
do something;
end;
begin
something;
something;
exception
when others then
something;
end;
Please advise...!!
Thanks in adv.
ArHere's what happens:
SQL> begin
2
3 v_sal numbber(5);
4
5 select sal into v_sal
6 from emp
7 where deptno=60;
8
9 exception
10
11 when no_data_found then
12 do something;
13
14 end;
15
16 begin
17
18 something;
19 something;
20
21 exception
22
23 when others then
24 something;
25
26 end;
27 /
v_sal numbber(5);
ERROR at line 3:
ORA-06550: line 3, column 10:
PLS-00103: Encountered the symbol "NUMBBER" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "NUMBBER" to continue.
ORA-06550: line 12, column 17:
PLS-00103: Encountered the symbol "SOMETHING" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "SOMETHING" to continue.
ORA-06550: line 16, column 5:
PLS-00103: Encountered the symbol "BEGIN" -
First execution of sql statements is slow every morning
Dears,
we are running an oracle11g database (HP-UX Itanium) and have the following problem:
Every morning the first execution of statements is very slow.
After the first execution the statements are running fine.
Does anyone have an idea where this can come from?
Is it possible that the cache (shared pool, etc.) will be deleted every night (for example when new statistics are generated or something else)?
Regards,
IljaI think you are close to answering your question.
As you know, Oracle 11g has an automated job to run performance stats every night at approx. 10:00pm (until 2:00am).
This is run by the dbms_scheduler.
This could be causing the shared_pool to be flushed because it certainly uses it a lot. I have to manually flush the shared_pool every night in one of my databases before this job runs otherwise I get an ORA-01461.
But, what I'm surprised is that you have this problem only in the morning.
It seems you would want to pin your SQL in memory and perhaps set a profile for your execution.
You don't bounce your database every night, do you? -
Pl/sql block is too slow, should procedure a better option
Hi all,
how to tune A PL/SQL block that traverse cursors and fetch millions of records then execute inserts in different tables,
using execute immediate statement.
It's too slow and takes 10 hours to populate 40 tables having millions of records,
as i have to do some modifications in data so can not do it by CTAS,
i.e. a single sql statement.
Should i make a procedure, does it help .
Please help or suggest As i am New to PL/Sql
My code look like,
declare
cursor cur_table1 is
select field1,field2,field3,field4 from table1;
begin
for i in cur_table1
loop
execute immediate 'insert into table2 (field1,field2,field3,field4) '||
'select :1,field2,field3,field4 '||
' from table1 where field3= :2'
using i.field1||'_'||to_char(sysdate,'ddmmyyyy hh12:mi:ss',i.field1;
commit;
end if;
end;
Thanks and Regards,declare
cursor cur_projects is
select PROJECTID, PROJECTNAME, DESCRIPTION, DELETED, DELETINGDATE, ACTIVE, ADMINONLY, READONLY, SECURITYCLASS, PROJECTCONTACT, DEFAULTVERSION, DEFAULTSTARTPAGE, IMAGEPATH, MAXEXAMINEERRORS, LOCKTIMEOUT, MEMORYSAVINGLEVEL, PRELOADOBJECTS, PUBLICATIONSRCPROJNAME, CREATOR, CREATED, MODIFIER, MODIFIED from projects ;
cursor cur_projectversion(p_projectid projects.projectid%TYPE) is
select PROJECTID, PROJECTVERSIONID, PROJECTVERSIONNAME, DESCRIPTION, DELETED , DELETINGDATE, ACTIVE , ADMINONLY, READONLY, decode(EFFECTIVEDATE,null,trunc(sysdate),EFFECTIVEDATE) EFFECTIVEDATE, EXPIRATIONDATE, SECURITYCLASS, PROJECTCONTACT, DEFAULTVERSION, DEFAULTSTARTPAGE, IMAGEPATH, MAXEXAMINEERRORS, LOCKTIMEOUT, MEMORYSAVINGLEVEL, PRELOADOBJECTS, PUBLICATIONSRCPROJNAME, PUBLICATIONSRCPROJVERNAME, CREATOR, CREATED, MODIFIER, MODIFIED, PROFILELOADERCLASS /*, TRACKCHANGES */
from projectversions where PROJECTID=p_projectid ;
cursor cur_objects(p_projectid projects.projectid%TYPE,p_projectversionid projectversions.projectversionid%TYPE) is
select PROJECTID , PROJECTVERSIONID, OBJECTID , OBJECTKEY , PARENTID, KIND , NAME , TITLE , OWNER , CREATED, MODIFIER , MODIFIED , READY_TO_PUBLISH, LAST_PUBLISHED_DATE , LAST_PUBLISHER , EFFECTIVE_PUBLISHING_DATE , PUBLISHER , PUBLISHING_DATE /*, to_lob(scripttext) */ from OBJECTS where PROJECTID=p_projectid and PROJECTVERSIONID=p_projectversionid /*order by objectid */;
begin
for i in cur_projects
loop
dbms_output.put_line('PROJECTID => '||i.projectid);
dbms_output.put_line('_________________________________');
execute immediate 'insert into &TARGET_USER\.projects(locktimeout, memorysavinglevel , preloadobjects, projectid, projectname, description, deleted, deletingdate, active, adminonly, readonly, securityclass, projectcontact, defaultversion, defaultstartpage, imagepath, maxexamineerrors ) values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17) '
using i.locktimeout, i.memorysavinglevel, i.preloadobjects,i.projectid ,i.projectname , i.description , i.deleted , i.deletingdate , i.active , i.adminonly , i.readonly, i.securityclass, i.projectcontact , i.defaultversion, i.defaultstartpage , i.imagepath, i.maxexamineerrors;
for k in cur_projectversion(i.projectid)
loop
for l in cur_objects(k.projectid,k.projectversionid)
loop
cnt:=cnt+1;
select count(1) into object_exists from &TARGET_USER\.objects where objectid=l.objectid and projectversionid=1 and projectid=l.projectid;
if object_exists = 0
then
if l.objectid = 1 ------Book Object , objectid = 1 and parentid = 0
then
execute immediate 'INSERT INTO &TARGET_USER\.objects(PROJECTID,PROJECTVERSIONID,OBJECTID, OBJECTKEY,PARENTID,NAME, KIND,LAST_PUBLISHED_DATE,LAST_PUBLISHER,REVISIONID,DISPLAYORDER,READONLY,DELETED) values( :1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'
using l.PROJECTID, 1, l.OBJECTID,l.OBJECTKEY, 0 , l.NAME,l.KIND, '' , '' , '', 0, 'N', 'N';
else
select count(1) into object_parentid_exists from objects where objectid=l.parentid and projectversionid=1 and projectid=l.projectid;
if object_parentid_exists = 0 ---Set Parentid as 1
then
cnt_parentid_1:=cnt_parentid_1+1;
execute immediate 'INSERT INTO &TARGET_USER\.objects(PROJECTID,PROJECTVERSIONID,OBJECTID, OBJECTKEY,PARENTID,NAME, KIND,LAST_PUBLISHED_DATE,LAST_PUBLISHER,REVISIONID,DISPLAYORDER,READONLY,DELETED) values( :1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'
using l.PROJECTID, 1, l.OBJECTID,l.OBJECTKEY, 1 , l.NAME,l.KIND, '' , '' , '', 0, 'N', 'N';
else
execute immediate 'INSERT INTO &TARGET_USER\.objects(PROJECTID,PROJECTVERSIONID,OBJECTID, OBJECTKEY, PARENTID, NAME, KIND,LAST_PUBLISHED_DATE,LAST_PUBLISHER,REVISIONID,DISPLAYORDER,READONLY,DELETED) values( :1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'
using l.PROJECTID, 1, l.OBJECTID,l.OBJECTKEY,l.PARENTID,l.NAME,l.KIND, '' , '' , '', 0, 'N', 'N';
end if;
end if ;
end if;
execute immediate 'INSERT INTO &TARGET_USER\.objectversions( PROJECTID, OBJECTID, PROJECTVERSIONID ,VERSIONNAME,OBJECTVERSIONID, REVISIONID,DESCRIPTION, TITLE , OWNER, CREATED, MODIFIER, MODIFIED, READY_TO_PUBLISH , LAST_PUBLISHED_DATE, LAST_PUBLISHER, EFFECTIVEDATE, SCRIPTTEXT, REVIEWSTATUS, READONLY, PUBLISHED, DELETED ) '||
'SELECT PROJECTID, OBJECTID, 1, owner||:1, PROJECTVERSIONID , '''', '''', TITLE, OWNER, CREATED, MODIFIER, MODIFIED, ''N'', '''' , '''', :2 , to_lob(SCRIPTTEXT), '''', ''N'', ''N'', '''' '||
'FROM OBJECTS '||
'WHERE PROJECTID= :3 and PROJECTVERSIONID= :4 and OBJECTID= :5'
using '_'||TO_CHAR(k.EFFECTIVEDATE,'DDMMYYHHMISS'),k.EFFECTIVEDATE,l.projectid,l.projectversionid,l.objectid;
end loop;
dbms_output.put_line(cnt||' OBJECTS, OBJECTVERIONS POPULATED');
dbms_output.put_line(cnt_parentid_1||' DUMPED UNDER BOOK FOLDER ');
cnt_parentid_1:=0;
cnt:=0;
............ -
My First while loop inside PL/SQL block not working , please help
Hi ,
I am new to PL/sql and struck at PL SQL blocks , please help to solve this .
declare
v_A number constant :=10 ;
j number constant := 3 ;
BEGIN
WHILE j < v_A
LOOP
DBMS_OUTPUT.PUT_LINE('Hai');
END LOOP;
END;
please help as how to resolve this .
Thanks in advance .btw it's a useful habit to use indentation to highlight the block structure. Also it's worth deciding what your convention will be for keywords (I use uppercase, lowercase is also fine as far as I'm concerned but I've set up my editor to uppercase them) and variables, database object names etc (I use lowercase), e.g:
DECLARE
v_a CONSTANT PLS_INTEGER := 10;
j CONSTANT PLS_INTEGER := 3;
i PLS_INTEGER := j;
BEGIN
WHILE i <= v_a LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i +1;
END LOOP;
END;or perhapsdeclare
v_a constant pls_integer := 10;
j constant pls_integer := 3;
i pls_integer := j;
begin
while i <= v_a loop
dbms_output.put_line(i);
i := i +1;
end loop;
end;When I see "declare" and "BEGIN" in the same block of code I worry about the standard of code I'm going to see... -
I am new to PL/SQL. I understand that I can run PL/SQL from sqlplus. But it does not work for me if I put sqlplus command in PL/SQL blocks. For example:
BEGIN
IF &1 IS NULL THEN CONNECT username/userpassword
ELSE CONNECT username/userpassword@&1
ENDIF;
END;
I wonder:
1) What can be included in PL/SQL block? Can a sqlplus command (like CONNECT) be included in PL/SQL block?
2) In sqlplus, how to check if the sql script has an command line input parameter,
like "myscript.sql <input_parameter>"?
Thank you.Just to add a few comments.
PL/SQL is a formal procedural language. The CONNECT command is not part of this language. So just as PL/SQL cannot understand C/C++ commands, nor can it understand SQL*Plus macro commands.
The & char is used in SQL*Plus as a substitution variable. SQL*Plus checks the PL/SQL or SQL code block before it sends it to Oracle. SQL*Plus substitutes all & variables first - and changes this code block. Then this changed code block is submitted by SQL*Plus to Oracle for execution.
You need to grok the basics of client-server here and how the client (SQL*Plus in this case), interacts with the server (Oracle and is PL/SQL engine in this case).
SQL*Plus does not have a "programming" language - it has a very simplistic macro language. It does not support conditional execution. It does not support loop structures. It is very primitive. And must not be confused with PL/SQL and cannot be mixed with PL/SQL (server-side) code. -
Stored Procedure Vs PL-SQL Block
Hi,
I came across an interesting problem last week. Fortunately, I was able to solve it or find an acceptable workaround for myself. But wanted to get some clarification from the experts. So posting it here.
Also, I am new to Orcle, so please excuse any shortcomings in the post.
My data model has following tables-
TABLE_PARENT (ID, other columns)
TABLE_CHILD (ID, other columns, PARENT_ID_FK)
Here, ID is the primary key column for the respective tables; PARENT_ID_FK is the foreign key referencing the ID column from the TABLE_PARENT.
I created a stored procedure programmatically (using MS Excel) to insert records in the two tables. The stored procedure has insert statements for an indefinite number of records in the parent table and for every such record, there's a corresponding record inserted in the child table. Here's the sample code.
BEGIN
/*first record*/
parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
INSERT INTO TABLE_CHILD(ID, other values,parent_id );
/*second record*/
parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
INSERT INTO TABLE_CHILD(ID, other values,parent_id );
/*third record*/
parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
INSERT INTO TABLE_CHILD(ID, other values,parent_id );
/*and so on*/
END
When I run this stored procedure, I keep getting following exception intermittently-
ORA-02291: integrity constraint violated-parent key not found tips.
My thinking is that it comes because the insert statements are executing ahead of turn of the parent_id assignment statement. And this is happening possibly because of some parallelism that is taking place during the execution of the stored procedure, or, some sort of optmization that the DB server does (though erroneously) when it compiles the stored procedure.
I tried out everything that I could think of but it didn't go away. Finally, when I executed the same set of statements as a PL-SQL block, it worked fine.
To understand it better, I am looking for clarification on the following questions.
1) Why does the exception come with stored procedure but not with PL-SQL block? Is my reasoning given above correct (parallelism or some sort of optimization coming into play)?
2) If it is due to parallelism, how to run a Oracle stored procedure with defree of prallelism set to 1?
3) If it is due to optimization done by the compiler, how to instruct the compiler to not do any such optimization. Also, in any case, isn't it an error to optimize but lose program semantics?
4) Another question related to the same piece of work I have is to use transactions in the PL-SQL block, I had to explicitly COMMIT/ROLLBACK it in the code. In whatever references I had read, it was said that by default the transaction begins with BEGIN statement and commits with END. Also, it seems to work with a Stored Proedure though. So is it that a PL_SQL block needs explicity call to COMMIT/ROLLBACK to achive transactions but stored procedures do not?
Any inputs/clarifications will be much appreciated.
Thank you
NeeleshOk, your last couple of paragraphs were helpful. Here're the details that were missing in my earlier post.
- I am on Oracle 10.2.0.
- Table definitions-
CREATE TABLE "MYUSER"."TABLE_PARENT"
*( "ID" NUMBER(19,0) NOT NULL ENABLE,*
* "NAME" VARCHAR2(30),*
* "DESCRIPTION" VARCHAR2(80),*
* "RULETYPE" NUMBER(10,0) NOT NULL ENABLE,*
* "OPERATOR" NUMBER(10,0),*
* "MININTERCEPT" FLOAT(126),*
* "PRIORITY" NUMBER(10,0),*
* "PENALTY" NUMBER(10,0),*
* "STATUS" NUMBER(10,0),*
* PRIMARY KEY ("ID")*
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE,
*) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
CREATE TABLE "MYUSER"."TABLE_CHILD"
*( "ID" NUMBER(19,0) NOT NULL ENABLE,*
* "WEIGHT" NUMBER(19,0),*
* "PARENTID_FK" NUMBER(19,0),*
* PRIMARY KEY ("ID")*
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE,
* CONSTRAINT "FK3A78BF1E6A9DCE51" FOREIGN KEY ("PARENTID_FK")*
* REFERENCES "MYUSER"."TABLE_PARENT" ("ID") ENABLE*
*) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
- The Stored procedure definition is-
CREATE OR REPLACE PROCEDURE LOAD_RULES_SP AS
ruleid NUMBER(19,0);
tempid NUMBER(19,0);
BEGIN
*/* First parent record */*
SELECT IDGENERATOR.NEXTVAL INTO ruleid FROM dual;
INSERT INTO TABLE_PARENT (ID, NAME, DESCRIPTION, RULETYPE, OPERATOR, MININTERCEPT, PRIORITY, penalty, STATUS) VALUES (ruleid, 'Rule 1',null,3,0,0,null,null,1);
*/* Corresponding child records */*
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.2, ruleid);
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.5, ruleid);
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.3, ruleid);
*/* First parent record */*
SELECT IDGENERATOR.NEXTVAL INTO ruleid FROM dual;
INSERT INTO TABLE_PARENT (ID, NAME, DESCRIPTION, RULETYPE, OPERATOR, MININTERCEPT, PRIORITY, penalty, STATUS) VALUES (ruleid, 'Rule 1',null,3,0,0,null,null,1);
*/* Corresponding child records */*
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.2, ruleid);
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.5, ruleid);
SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
VALUES (tempid, 0.3, ruleid);
*/* And so on for a few parent records more */*
END;
Can you throw some light on the exception I was seeing now? Note that when I changed from stored procedure to an anonymous block, it worked fine.
One correction in my earlier post is that as the code snippet shows, there are multiple inserts in the child table for every record inserted in the parent one. -
PERFORMANCE BAD WHEN CURSORS ARE USED WITHIN PL/SQL BLOCKS
There are poor database performance at Oracle 10g
For some cursor selects, the performance is under Oracle 10g
significant slower than under Oracle 9i.On a test system (Oracle 9) the
problem does not reproduce, on the 10g system however always.
The simple execution of the base select statement was on both
databases in roughly of the same speed. If however a cursor was defined and
those executed within a PL/SQL block (without involving the user interface),
then the time behavior was in accordance with the observed behavior
behavior on the user interface.
By adding of the hint first_rows on both machines a
similar (fast) time behavior can be achieved.
Conclusion: Something in the (Optimizer) settings of the Oracle-10
databases must be fundamentally different than that of Oracle 9. Or Oracle
10 has a real problem. The analysis and solution of this general
problem seems to me more reasonable than the solution of individual performance
problems.
can you help me, many thanksHello, thanks for the explanatory notes.
Here are the concerned Script. The only difference is the Hint (with Hint = good püerformance; without Hint = bad performance)
DECLARE
b BOOLEAN;
BEGIN
b := plogin.batch_login('**', '****', 717, FALSE);
prost.reload_context;
END;
DECLARE
l_ma_kuerzel VARCHAR2(100) DEFAULT NULL;
l_sta_id mitarbeiter_historie.sta_id%TYPE;
l_org_id organisationseinheit.org_id%TYPE;
l_pv_like mitarbeiter.ma_name%TYPE;
l_typ_id typ.typ_id%TYPE;
l_mihi_beginn VARCHAR2(40);
l_ma_ausgeschieden VARCHAR2(40);
l_ma_ldap mitarbeiter.ma_ldap%TYPE;
l_smodify_form VARCHAR2(80);
l_sform_typ VARCHAR2(80);
l_sheader VARCHAR2(200);
l_nurlsource NUMBER;
l_nurldestination prosturl.pur_id%type;
l_ma_like VARCHAR2(100) DEFAULT NULL;
l_nma_typ NUMBER;
l_bshow BOOLEAN;
l_counter NUMBER DEFAULT 0;
cursor ma_list_not_all_detail(
p_ma_like IN VARCHAR2 DEFAULT NULL,
p_ma_kuerzel IN VARCHAR2 DEFAULT NULL,
p_sta_id IN VARCHAR2 DEFAULT NULL,
p_org_id IN VARCHAR2 DEFAULT NULL,
p_typ_id IN VARCHAR2 DEFAULT NULL,
p_mihi_beginn IN VARCHAR2 DEFAULT NULL,
p_pv_like IN VARCHAR2 DEFAULT NULL,
p_ma_ausgeschieden IN VARCHAR2 DEFAULT NULL,
p_ma_ldap IN VARCHAR2 DEFAULT NULL
) IS
SELECT /*+ first_rows */
ma.ma_id ma_id
, view_fkt.display_ma(mihi.typ_id_mt
, view_fkt.cat_maname(ma.ma_name
, ma.ma_zusatz
, ma.ma_titel
, ma.ma_vorname)) name
, view_fkt.display_ma(mihi.typ_id_mt,ma.ma_kuerzel) ma_kuerzel
, typ.typ_value mt_kuerzel
, substr(org.typ_id,4,length(org.typ_id)) || ' ' || org.org_name||' ('||org.org_ktr||')' org_name
, to_char(mihi.mihi_beginn, 'dd.mm.yyyy') beginn
, decode(pv.ma_name ||' '|| pv.ma_titel ||' '|| pv.ma_vorname
, ' ',prost_cons.t_blank
, pv.ma_name||', '||pv.ma_titel||' '||pv.ma_vorname) pv_kuerzel
, mihi.sta_id sta_id
, nvl(to_char(ma.ma_ausgeschieden,'dd.mm.yyyy'), ' ') ausgeschieden
, nvl(to_char(mihi.mihi_wochenarbeitszeit,'90D00'),' ') wochenarbeitszeit
, nvl(to_char(mihi.mihi_taz_mo,'90D00'),' ') taz_mo
, nvl(to_char(mihi.mihi_taz_di,'90D00'),' ') taz_di
, nvl(to_char(mihi.mihi_taz_mi,'90D00'),' ') taz_mi
, nvl(to_char(mihi.mihi_taz_do,'90D00'),' ') taz_do
, nvl(to_char(mihi.mihi_taz_fr,'90D00'),' ') taz_fr
, nvl(to_char(mihi.mihi_taz_sa,'90D00'),' ') taz_sa
, nvl(to_char(mihi.mihi_taz_so,'90D00'),' ') taz_so
, nvl(ma.ma_ldap, ' ') ma_ldap
, mihi.mihi_beginn mihi_beginn
, mihi.mihi_order_no mihi_order_no
, mihi.mihi_order_pos mihi_order_pos
FROM organisationseinheit org
, typ typ
, mitarbeiter pv
, mitarbeiter ma
, v$mihi_id mid
, mitarbeiter_historie mihi
, v$access_orgs_th_t th
WHERE mihi.org_id = th.org_id
AND mid.mihi_id = mihi.mihi_id
AND ma.ma_id = mid.ma_id
AND ma.ma_delete = 'n'
AND ma.ma_virtualitaet = 'N'
AND (p_ma_like IS NULL
OR ma.ma_name LIKE p_ma_like)
AND (p_ma_kuerzel IS NULL
OR ma.ma_kuerzel LIKE p_ma_kuerzel)
AND (p_sta_id IS NULL
OR mihi.sta_id = p_sta_id)
AND (p_org_id IS NULL
OR org.org_id = p_org_id)
AND (p_typ_id IS NULL
OR typ.typ_id = p_typ_id)
AND mihi_beginn >= nvl(p_mihi_beginn,to_date('01.01.1960','dd.mm.yyyy'))
AND (p_pv_like IS NULL
OR pv.ma_name LIKE p_pv_like)
AND (ma.ma_ausgeschieden >= nvl(p_ma_ausgeschieden,to_date('01.01.1960','dd.mm.yyyy'))
AND ma.ma_ausgeschieden - 1 < nvl(p_ma_ausgeschieden,to_date('01.01.1960','dd.mm.yyyy'))
OR p_ma_ausgeschieden IS NULL)
AND (p_ma_ldap IS NULL
OR ma.ma_ldap LIKE p_ma_ldap)
AND pv.ma_id (+)= mihi.ma_id_pv
AND org.org_id (+)= mihi.org_id
AND typ.typ_id = mihi.typ_id_mt
ORDER BY upper(ma.ma_name), upper(ma.ma_vorname);
l_result ma_list_not_all_detail%ROWTYPE;
BEGIN
l_nMA_Typ := pmitarbeiter.cn_Incomplete_Ma;
l_ma_like := NULL;
l_ma_kuerzel := NULL;
l_sta_id := NULL;
l_org_id := 'KST0000421301';
l_typ_id := NULL;
l_mihi_beginn := NULL;
l_pv_like := NULL;
l_ma_ausgeschieden := NULL;
l_ma_ldap := NULL;
IF (l_ma_like IS NOT NULL
OR l_ma_kuerzel IS NOT NULL
OR l_sta_id IS NOT NULL
OR l_org_id IS NOT NULL
OR l_typ_id IS NOT NULL
OR l_mihi_beginn IS NOT NULL
OR l_pv_like IS NOT NULL
OR l_ma_ausgeschieden IS NOT NULL
OR l_ma_ldap IS NOT NULL) THEN
-- fuer Mitarbeiter unvollstandig wird ein andere cursor angesprochen
-- um der Mitarbeiter vollstandig zu kriegen soll ein Standort,
-- Arbeitszeitmodel, Bereich und Tagesarbeitszeiten ausgevult wirden
-- Wenn er dan gespeichert wirdt wirden die betriffende velder gespeichert
-- und wirdt das Feld Virtualiteat auf R gesetzt (war N)
l_counter := 0;
dbms_output.put_line(to_char(sysdate, 'sssss'));
FOR j IN ma_List_Not_All_Detail(
l_ma_like,
l_ma_kuerzel,
l_sta_id,
l_org_id,
l_typ_id,
l_mihi_beginn,
l_pv_like,
l_ma_ausgeschieden,
l_ma_ldap
) LOOP
l_counter := l_counter + 1;
dbms_output.put_line(l_counter);
dbms_output.put_line(j.ma_kuerzel);
END LOOP;
dbms_output.put_line(to_char(sysdate, 'sssss'));
END IF;
return;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(sqlerrm);
END;
=============
Thank you -
Use Chains, or PL/SQL Block of calls.
I currently have a half dozen cron jobs that kick off different batches of processing. Originally, these were generally a sequence of C programs that did different operations (fetch student info from student record system and load into IdM system, process directory changes, etc). Over the years, most of the program logic has been rewritten as PL/SQL packages and the cron jobs basically drop into SQL*PLUS and do things like:
prompt "Do Spbpers delta"
execute simon.employee_maint.Spbpers_Delta;
commit;
prompt "Do People.Update_From_Employees"
execute simon.People_Maint.Update_From_Employees;
commit;
prompt "Do SGBSTDN_Full"
execute Simon.Bstudent_Maint.Sgbstdn_Full;
commit;
prompt "Do SPRIDEN_Full (Student)"
execute Simon.Bstudent_Maint.Spriden_Full;
These procedures generally connect to other Oracle databases and get or push data around, and are hitting a number of different databases. The biggest of these scripts has 45 execute statements in it. (This script started in 1992.....)
Anyway, we are getting some issues with and it is time to clean things up. This is my first foray into Scheduler and I am hoping to get some philosophical guidance on how best I should restructure things. One obvious thing, is to break up the big script into a couple of smaller ones. In some cases, order matters and in other, it doesn't - although I would prefer not to have several jobs hitting the admin system at the same time.
I have been playing a bit with the scheduler, mostly via the EM web interface, and have come up with a few questions - some pretty specific, others more stylistic.
1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....Hi,
I can try to answer some of these questions
1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
False. The EM interface does have this restriction, but if you use dbms_scheduler directly there is no such restrisction. Even in the EM interface you can workaround this by using a PL/SQL block which calls the package procedure (although argument handling is a little less flexible this way).
2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
The answer to this depends on what you are doing. If the 5 steps run serially one after the other, using one pl/sql block may be easier. If you want some pieces to run in parallel, then creating a simple chain is better. A bit more effort spent setting up the chain will result in much faster execution times if you can run pieces in parallel.
3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
This has come up on the forum a few times and there are basically two different approaches. One is to use dbms_lock to ensure that only one runs at a time. This is the easiest way and the way that I recommend.
The other way is to set up a job class with a resource consumer group and put into effect a resource consumer plan that specifies that only one session from that resource consumer group can run at a time. This is easily extensible to cases where you want 2 or more running at a time from a certain job class (which dbms_lock doesn't support).
Code on how to set this up and more discussion is located here
Run Jobs One After Another
4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
Jobs and programs can be disabled. But if a job or chain tries to run a disabled program it will result in a failure (though it will be retried if you say that the job can be restarted).
[ 5) ] The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....
The Scheduler was intended to accommodate a wide range of usage from simple one-off background tasks to complex sequences of interrelated tasks. As with any other software development you should use it in the simplest way possible that does what you need it to do.
Hope this helps. Feel free to post any further questions.
-Ravi -
First execution of query is always best than all the following
I have a static query that I execute in sql*plus in the same machine as the database and all the time, the first execution is faster than the following executions and it driving me crazy! Any help is appreciated...
The database is Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
The query has a comment in the there so I can change the query to be "different" form the previous ones.
I ran it in sql*plus with set autotrace traceonly and timing on and the results are:
First execution:
SQL> @route
35 rows selected.
Elapsed: 00:00:45.49
Execution Plan
Plan hash value: 1336726102
Statistics
442 recursive calls
0 db block gets
6244491 consistent gets
0 physical reads
176 redo size
3333 bytes sent via SQL*Net to client
9006 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
46 sorts (memory)
0 sorts (disk)
35 rows processed
Second Execution:
SQL> @route
35 rows selected.
Elapsed: 00:05:04.85
Execution Plan
Plan hash value: 1336726102
Statistics
386 recursive calls
0 db block gets
1282647 consistent gets
0 physical reads
840 redo size
3333 bytes sent via SQL*Net to client
9006 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
47 sorts (memory)
0 sorts (disk)
35 rows processedSecond run:
SQL> select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));
PLAN_TABLE_OUTPUT
SQL_ID f2xgmq6bsd6g1, child number 1
SELECT /* + opt_param('_optimizer_use_feedback' 'false') zzzzz5 */
route, MIN(load_start) load_start, store, lc_id, loading_seq,
pick_zone_name, MAX(user_name) user_name, SUM(colli) colli,
SUM(colli_picked) colli_picked, round((1 - ((SUM(colli) -
SUM(colli_picked)) / (SUM(colli)))) * 100, 2) || '%' colli_ready FROM
(SELECT route, load_start, store,
lc_id, loading_seq, CASE
WHEN (nbr_pick_zones > 1) THEN 'MULTIPLE'
ELSE pick_zone_name END
pick_zone_name, (SELECT u.user_name
FROM dms_user u WHERE u.user_id = tab4.user_id
AND u.facility_id = 'E1') user_name, colli,
(colli - colli_not_picked) colli_picked FROM
(SELECT tab3.route, tab3.load_start,
tab3.store,
Plan hash value: 2089643899
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
| 0 | SELECT STATEMENT | | 1 | | 35 |00:01:51.10 | 1286K| | | |
| 1 | TABLE ACCESS BY INDEX ROWID | DMS_USER | 18 | 1 | 18 |00:00:00.01 | 37 | | | |
|* 2 | INDEX UNIQUE SCAN | DMS_USER1 | 18 | 1 | 18 |00:00:00.01 | 17 | | | |
| 3 | SORT GROUP BY | | 1 | 2 | 35 |00:01:51.10 | 1286K| 9216 | 9216 | 8192 (0)|
| 4 | VIEW | | 1 | 2 | 43 |00:01:51.09 | 1286K| | | |
| 5 | WINDOW BUFFER | | 1 | 2 | 43 |00:01:51.09 | 1286K| 6144 | 6144 | 6144 (0)|
| 6 | SORT GROUP BY | | 1 | 2 | 43 |00:01:51.09 | 1286K| 11264 | 11264 |10240 (0)|
| 7 | NESTED LOOPS OUTER | | 1 | 2 | 43 |00:01:51.09 | 1286K| | | |
| 8 | VIEW | | 1 | 2 | 43 |00:01:51.09 | 1286K| | | |
| 9 | UNION-ALL | | 1 | | 43 |00:01:51.09 | 1286K| | | |
| 10 | HASH GROUP BY | | 1 | 1 | 0 |00:00:01.04 | 33948 | 752K| 752K| |
| 11 | VIEW | VM_NWVW_1 | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
|* 12 | FILTER | | 1 | | 0 |00:00:01.04 | 33948 | | | |
| 13 | HASH GROUP BY | | 1 | 1 | 0 |00:00:01.04 | 33948 | 694K| 694K| |
| 14 | NESTED LOOPS | | 1 | | 0 |00:00:01.04 | 33948 | | | |
| 15 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
| 16 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
| 17 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
| 18 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
| 19 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
| 20 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
| 21 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
| 22 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
| 23 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
| 24 | NESTED LOOPS | | 1 | 1 | 0 |00:00:01.04 | 33948 | | | |
|* 25 | TABLE ACCESS BY INDEX ROWID| CONTAINER | 1 | 13 | 36 |00:00:00.01 | 21 | | | |
|* 26 | INDEX SKIP SCAN | CONTAINER_CARR_SERV_ROUTE | 1 | 28 | 36 |00:00:00.01 | 12 | | | |
|* 27 | TABLE ACCESS BY INDEX ROWID| PICK_DIRECTIVE | 36 | 1 | 0 |00:00:01.04 | 33927 | | | |
|* 28 | INDEX RANGE SCAN | PICK_DIRECTIVE_I1 | 36 | 1 | 569K|00:00:00.47 | 12936 | | | |
| 29 | TABLE ACCESS BY INDEX ROWID | PICK_FROM_LOC | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 30 | INDEX RANGE SCAN | PICK_FROM_LOC_ITEM | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
| 31 | TABLE ACCESS BY INDEX ROWID | LOCATION | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 32 | INDEX RANGE SCAN | LOCATION_ZONE | 0 | 1053 | 0 |00:00:00.01 | 0 | | | |
|* 33 | TABLE ACCESS BY INDEX ROWID | STOCK_ALLOCATION | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
PLAN_TABLE_OUTPUT
|* 34 | INDEX UNIQUE SCAN | STOCK_ALLOCATION1 | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 35 | TABLE ACCESS BY INDEX ROWID | NB_TMS_INBOUND | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 36 | INDEX RANGE SCAN | NB_TMS_INBOUND_PK | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
| 37 | TABLE ACCESS BY INDEX ROWID | ROUTE_DEST | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 38 | INDEX RANGE SCAN | ROUTE_DEST1 | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 39 | TABLE ACCESS BY INDEX ROWID | NB_LANE_SELECTION | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 40 | INDEX UNIQUE SCAN | NB_LANE_SELECTION_PK | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
| 41 | TABLE ACCESS BY INDEX ROWID | ZONE | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 42 | INDEX UNIQUE SCAN | ZONE1 | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 43 | TABLE ACCESS BY INDEX ROWID | LOC_TYPE | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 44 | INDEX UNIQUE SCAN | LOC_TYPE1 | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
|* 45 | INDEX UNIQUE SCAN | ITEM_MASTER1 | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
| 46 | TABLE ACCESS BY INDEX ROWID | ITEM_MASTER | 0 | 1 | 0 |00:00:00.01 | 0 | | | |
| 47 | HASH GROUP BY | | 1 | 1 | 43 |00:01:51.09 | 1252K| 759K| 759K| 1336K (0)|
| 48 | NESTED LOOPS | | 1 | | 1963 |00:13:34.35 | 1252K| | | |
| 49 | NESTED LOOPS | | 1 | 1 | 1963 |00:13:34.33 | 1250K| | | |
| 50 | NESTED LOOPS | | 1 | 1 | 1963 |00:13:34.31 | 1250K| | | |
| 51 | NESTED LOOPS | | 1 | 1 | 37M|00:02:03.09 | 822K| | | |
| 52 | MERGE JOIN CARTESIAN | | 1 | 1 | 41685 |00:00:00.20 | 9793 | | | |
| 53 | NESTED LOOPS | | 1 | | 1985 |00:00:00.13 | 9790 | | | |
| 54 | NESTED LOOPS | | 1 | 1 | 1985 |00:00:00.10 | 7060 | | | |
| 55 | NESTED LOOPS | | 1 | 14 | 1985 |00:00:00.08 | 5047 | | | |
| 56 | NESTED LOOPS | | 1 | 14 | 1985 |00:00:00.03 | 1152 | | | |
|* 57 | HASH JOIN | | 1 | 1 | 36 |00:00:00.01 | 81 | 774K| 774K| 760K (0)|
|* 58 | HASH JOIN | | 1 | 7 | 36 |00:00:00.01 | 67 | 779K| 779K| 391K (0)|
|* 59 | HASH JOIN | | 1 | 36 | 36 |00:00:00.01 | 51 | 835K| 835K| 654K (0)|
|* 60 | TABLE ACCESS BY INDEX ROWID | CONTAINER | 1 | 36 | 36 |00:00:00.01 | 21 | | | |
|* 61 | INDEX SKIP SCAN | CONTAINER_CARR_SERV_ROUTE | 1 | 28 | 36 |00:00:00.01 | 12 | | | |
|* 62 | TABLE ACCESS FULL | NB_TMS_INBOUND | 1 | 144 | 144 |00:00:00.01 | 30 | | | |
|* 63 | TABLE ACCESS FULL | NB_LANE_SELECTION | 1 | 64 | 64 |00:00:00.01 | 16 | | | |
|* 64 | TABLE ACCESS FULL | ROUTE_DEST | 1 | 2003 | 2149 |00:00:00.01 | 14 | | | |
| 65 | TABLE ACCESS BY INDEX ROWID | CONTAINER_ITEM | 36 | 38 | 1985 |00:00:00.02 | 1071 | | | |
|* 66 | INDEX RANGE SCAN | CONTAINER_ITEM1 | 36 | 38 | 1985 |00:00:00.01 | 94 | | | |
| 67 | TABLE ACCESS BY INDEX ROWID | ITEM_MASTER | 1985 | 1 | 1985 |00:00:00.04 | 3895 | | | |
|* 68 | INDEX UNIQUE SCAN | ITEM_MASTER1 | 1985 | 1 | 1985 |00:00:00.02 | 1910 | | | |
|* 69 | INDEX UNIQUE SCAN | STOCK_ALLOCATION1 | 1985 | 1 | 1985 |00:00:00.02 | 2013 | | | |
|* 70 | TABLE ACCESS BY INDEX ROWID | STOCK_ALLOCATION | 1985 | 1 | 1985 |00:00:00.02 | 2730 | | | |
| 71 | BUFFER SORT | | 1985 | 21 | 41685 |00:00:00.04 | 3 | 2048 | 2048 | 2048 (0)|
| 72 | TABLE ACCESS BY INDEX ROWID | ZONE | 1 | 21 | 21 |00:00:00.01 | 3 | | | |
|* 73 | INDEX RANGE SCAN | ZONE_ZG_IDX | 1 | 21 | 21 |00:00:00.01 | 1 | | | |
| 74 | TABLE ACCESS BY INDEX ROWID | LOCATION | 41685 | 382 | 37M|00:01:40.75 | 812K| | | |
|* 75 | INDEX RANGE SCAN | LOCATION_ZONE | 41685 | 1053 | 37M|00:00:30.18 | 256K| | | |
|* 76 | VIEW PUSHED PREDICATE | | 37M| 1 | 1963 |00:10:49.31 | 428K| | | |
|* 77 | FILTER | | 37M| | 37M|00:09:39.35 | 428K| | | |
| 78 | SORT AGGREGATE | | 37M| 1 | 37M|00:08:18.42 | 428K| | | |
|* 79 | FILTER | | 37M| | 37M|00:05:23.60 | 428K| | | |
| 80 | TABLE ACCESS BY INDEX ROWID | PICK_FROM_LOC | 37M| 1 | 37M|00:03:59.31 | 428K| | | |
|* 81 | INDEX RANGE SCAN | PICK_FROM_LOC_ITEM | 37M| 1 | 37M|00:02:16.12 | 272K| | | |
|* 82 | INDEX UNIQUE SCAN | LOC_TYPE1 | 1963 | 1 | 1963 |00:00:00.01 | 4 | | | |
|* 83 | TABLE ACCESS BY INDEX ROWID | LOC_TYPE | 1963 | 1 | 1963 |00:00:00.01 | 1963 | | | |
|* 84 | VIEW PUSHED PREDICATE | | 43 | 1 | 43 |00:00:00.01 | 236 | | | |
|* 85 | WINDOW SORT PUSHED RANK | | 43 | 1 | 86 |00:00:00.01 | 236 | 2048 | 2048 | 2048 (0)|
|* 86 | TABLE ACCESS BY INDEX ROWID | CONTAINER_HISTORY | 43 | 1 | 160 |00:00:00.01 | 236 | | | |
|* 87 | INDEX RANGE SCAN | CHST_IDX | 43 | 2 | 246 |00:00:00.01 | 90 | | | |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
2 - access("U"."FACILITY_ID"='E1' AND "U"."USER_ID"=:B1)
12 - filter(("L"."LOCATION_ID"=MAX("PL"."LOCATION_ID") AND "PD"."PICK_FROM_CONTAINER_ID"=MAX("PL"."LOCATION_ID")))
25 - filter((INTERNAL_FUNCTION("C"."CONTAINER_STATUS") AND "C"."DEST_ID" IS NOT NULL))
26 - access("C"."FACILITY_ID"='E1' AND "C"."ROUTE"='556')
filter("C"."ROUTE"='556')
27 - filter("C"."CONTAINER_ID"="PD"."PICK_TO_CONTAINER_ID")
28 - access("PD"."FACILITY_ID"='E1')
30 - access("PL"."FACILITY_ID"='E1' AND "PL"."ITEM_ID"="PD"."ITEM_ID")
32 - access("L"."FACILITY_ID"='E1' AND "PD"."ZONE"="L"."ZONE")
33 - filter(("SA"."ORDER_DETAIL_UDA1"='2012-10-26' AND "SA"."SA_ROUTE" IS NOT NULL))
34 - access("SA"."FACILITY_ID"='E1' AND "SA"."DISTRO_NBR"="PD"."DISTRO_NBR" AND "SA"."DEST_ID"="C"."DEST_ID" AND "SA"."ITEM_ID"="PD"."ITEM_ID")
35 - filter(("C"."ROUTE"="A"."ROUTE" AND "SA"."SA_ROUTE"="A"."ROUTE"))
36 - access("A"."FACILITY_ID"='E1' AND "C"."DEST_ID"="A"."DEST_ID")
filter((TO_CHAR(INTERNAL_FUNCTION("A"."BUSINESS_DATE"),'YYYY-MM-DD')='2012-10-26' AND
"SA"."ORDER_DETAIL_UDA1"=TO_CHAR(INTERNAL_FUNCTION("A"."BUSINESS_DATE"),'YYYY-MM-DD')))
38 - access("RD"."FACILITY_ID"='E1' AND "C"."ROUTE"="RD"."ROUTE" AND "C"."DEST_ID"="RD"."DEST_ID")
39 - filter("RD"."SHIP_DATE"=TRUNC(INTERNAL_FUNCTION("LS"."LOAD_START")))
40 - access("LS"."FACILITY_ID"='E1' AND "LS"."BUSINESS_DATE"="A"."BUSINESS_DATE" AND "LS"."ROUTE"="A"."ROUTE")
42 - access("Z"."FACILITY_ID"='E1' AND "L"."ZONE"="Z"."ZONE")
43 - filter(("C"."LOCATION_ID" IS NULL OR "LT"."DOOR_LOCATION_FLAG"='N'))
44 - access("LT"."FACILITY_ID"='E1' AND "L"."LOCATION_TYPE"="LT"."LOCATION_TYPE")
45 - access("I"."FACILITY_ID"='E1' AND "PL"."ITEM_ID"="I"."ITEM_ID")
57 - access("C"."FACILITY_ID"="RD"."FACILITY_ID" AND "C"."ROUTE"="RD"."ROUTE" AND "C"."DEST_ID"="RD"."DEST_ID" AND
"RD"."SHIP_DATE"=TRUNC(INTERNAL_FUNCTION("LS"."LOAD_START")))
58 - access("LS"."FACILITY_ID"="A"."FACILITY_ID" AND "LS"."ROUTE"="A"."ROUTE" AND "LS"."BUSINESS_DATE"="A"."BUSINESS_DATE")
59 - access("C"."DEST_ID"="A"."DEST_ID" AND "C"."ROUTE"="A"."ROUTE")
60 - filter(("C"."USER_ID" IS NOT NULL AND INTERNAL_FUNCTION("C"."CONTAINER_STATUS") AND "C"."DEST_ID" IS NOT NULL))
61 - access("C"."FACILITY_ID"='E1' AND "C"."ROUTE"='556')
filter("C"."ROUTE"='556')
62 - filter(("A"."BUSINESS_DATE"=TO_DATE(' 2012-10-26 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "A"."FACILITY_ID"='E1'))
63 - filter(("LS"."BUSINESS_DATE"=TO_DATE(' 2012-10-26 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "LS"."FACILITY_ID"='E1'))
64 - filter("RD"."FACILITY_ID"='E1')
66 - access("CI"."FACILITY_ID"='E1' AND "CI"."CONTAINER_ID"="C"."CONTAINER_ID")
68 - access("I"."FACILITY_ID"='E1' AND "CI"."ITEM_ID"="I"."ITEM_ID")
69 - access("SA"."FACILITY_ID"='E1' AND "SA"."DISTRO_NBR"="CI"."DISTRO_NBR" AND "SA"."DEST_ID"="A"."DEST_ID" AND "SA"."ITEM_ID"="CI"."ITEM_ID")
70 - filter(("SA"."ORDER_DETAIL_UDA1"='2012-10-26' AND "SA"."SA_ROUTE" IS NOT NULL AND "SA"."SA_ROUTE"="A"."ROUTE"))
73 - access("Z"."FACILITY_ID"='E1')
75 - access("L"."FACILITY_ID"='E1' AND "L"."ZONE"="Z"."ZONE")
76 - filter(("L"."LOCATION_ID"="P"."LOCATION_ID" AND "C"."PICK_TYPE"=DECODE(TO_CHAR(NVL("P"."CASEPACK",0)),'0','U','CF')))
77 - filter(COUNT(*)>0)
79 - filter(('E1'="CI"."FACILITY_ID" AND 'E1'="L"."FACILITY_ID"))
81 - access("PL"."FACILITY_ID"='E1' AND "PL"."ITEM_ID"="CI"."ITEM_ID")
82 - access("LT"."FACILITY_ID"='E1' AND "L"."LOCATION_TYPE"="LT"."LOCATION_TYPE")
83 - filter(("C"."LOCATION_ID" IS NULL OR "LT"."DOOR_LOCATION_FLAG"='N'))
84 - filter("LAST_USER"=1)
85 - filter(ROW_NUMBER() OVER ( PARTITION BY "CH"."FACILITY_ID","CH"."CONTAINER_ID" ORDER BY INTERNAL_FUNCTION("CH"."ACTION_TS") DESC )<=1)
86 - filter((INTERNAL_FUNCTION("CH"."CONTAINER_STATUS") AND "CH"."USER_ID"<>'WMS_OWNER'))
87 - access("CH"."FACILITY_ID"="TAB1"."FACILITY_ID" AND "CH"."CONTAINER_ID"="TAB1"."LC_ID" AND "CH"."TABLE_NAME"='C' AND "CH"."ACTION_TYPE"='M')
Note
- cardinality feedback used for this statement
169 rows selected. -
A SQL tuning issue-sql runs much slower in test than in production?
Hi Buddies,
I am working on a sql tuning issue. A sql runs much slower in test than in production.
I compared the two explain plans in test and production
seems in test, CBO refuses to use index SUBLEDGER_ENTRY_I2.
we rebuile it and re-gether that index statistcs. run, still slow..
I compared the init.ora parameters like hash_area_size, sort_area_size in test, they are same as production.
I wonder if any expert friend can show some light.
in production,
SQL> set autotrace traceonly
SQL> SELECT rpt_horizon_subledger_entry_vw.onst_offst_cd,
2 rpt_horizon_subledger_entry_vw.bkng_prd,
3 rpt_horizon_subledger_entry_vw.systm_afflt_cd,
4 rpt_horizon_subledger_entry_vw.jrnl_id,
5 rpt_horizon_subledger_entry_vw.ntrl_accnt_cd,
6 rpt_horizon_subledger_entry_vw.gnrl_ldgr_chrt_of_accnt_nm,
7 rpt_horizon_subledger_entry_vw.lgl_entty_brnch_cd,
8 rpt_horizon_subledger_entry_vw.crprt_melob_cd AS corp_mlb_cd,
rpt_horizon_subledger_entry_vw.onst_offst_cd, SUM (amt) AS amount
9 10 FROM rpt_horizon_subledger_entry_vw
11 WHERE rpt_horizon_subledger_entry_vw.bkng_prd = '092008'
12 AND rpt_horizon_subledger_entry_vw.jrnl_id = 'RCS0002100'
13 AND rpt_horizon_subledger_entry_vw.systm_afflt_cd = 'SAFF01'
14 GROUP BY rpt_horizon_subledger_entry_vw.onst_offst_cd,
15 rpt_horizon_subledger_entry_vw.bkng_prd,
16 rpt_horizon_subledger_entry_vw.systm_afflt_cd,
17 rpt_horizon_subledger_entry_vw.jrnl_id,
18 rpt_horizon_subledger_entry_vw.ntrl_accnt_cd,
19 rpt_horizon_subledger_entry_vw.gnrl_ldgr_chrt_of_accnt_nm,
20 rpt_horizon_subledger_entry_vw.lgl_entty_brnch_cd,
21 rpt_horizon_subledger_entry_vw.crprt_melob_cd,
22 rpt_horizon_subledger_entry_vw.onst_offst_cd;
491 rows selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=130605 Card=218764 B
ytes=16407300)
1 0 SORT (GROUP BY) (Cost=130605 Card=218764 Bytes=16407300)
2 1 VIEW OF 'RPT_HORIZON_SUBLEDGER_ENTRY_VW' (Cost=129217 Ca
rd=218764 Bytes=16407300)
3 2 SORT (UNIQUE) (Cost=129217 Card=218764 Bytes=35877296)
4 3 UNION-ALL
5 4 HASH JOIN (Cost=61901 Card=109382 Bytes=17719884)
6 5 TABLE ACCESS (FULL) OF 'GNRL_LDGR_CHRT_OF_ACCNT'
(Cost=2 Card=111 Bytes=3774)
7 5 HASH JOIN (Cost=61897 Card=109382 Bytes=14000896
8 7 TABLE ACCESS (FULL) OF 'SUBLEDGER_CHART_OF_ACC
OUNT' (Cost=2 Card=57 Bytes=1881)
9 7 HASH JOIN (Cost=61893 Card=109382 Bytes=103912
90)
10 9 TABLE ACCESS (FULL) OF 'HORIZON_LINE' (Cost=
34 Card=4282 Bytes=132742)
11 9 HASH JOIN (Cost=61833 Card=109390 Bytes=7000
960)
12 11 TABLE ACCESS (BY INDEX ROWID) OF 'SUBLEDGE
R_ENTRY' (Cost=42958 Card=82076 Bytes=3611344)
13 12 INDEX (RANGE SCAN) OF 'SUBLEDGER_ENTRY_I
2' (NON-UNIQUE) (Cost=1069 Card=328303)
14 11 TABLE ACCESS (FULL) OF 'HORIZON_SUBLEDGER_
LINK' (Cost=14314 Card=9235474 Bytes=184709480)
15 4 HASH JOIN (Cost=61907 Card=109382 Bytes=18157412)
16 15 TABLE ACCESS (FULL) OF 'GNRL_LDGR_CHRT_OF_ACCNT'
(Cost=2 Card=111 Bytes=3774)
17 15 HASH JOIN (Cost=61903 Card=109382 Bytes=14438424
18 17 TABLE ACCESS (FULL) OF 'SUBLEDGER_CHART_OF_ACC
OUNT' (Cost=2 Card=57 Bytes=1881)
19 17 HASH JOIN (Cost=61899 Card=109382 Bytes=108288
18)
20 19 TABLE ACCESS (FULL) OF 'HORIZON_LINE' (Cost=
34 Card=4282 Bytes=132742)
21 19 HASH JOIN (Cost=61838 Card=109390 Bytes=7438
520)
22 21 TABLE ACCESS (BY INDEX ROWID) OF 'SUBLEDGE
R_ENTRY' (Cost=42958 Card=82076 Bytes=3939648)
23 22 INDEX (RANGE SCAN) OF 'SUBLEDGER_ENTRY_I
2' (NON-UNIQUE) (Cost=1069 Card=328303)
24 21 TABLE ACCESS (FULL) OF 'HORIZON_SUBLEDGER_
LINK' (Cost=14314 Card=9235474 Bytes=184709480)
Statistics
25 recursive calls
18 db block gets
343266 consistent gets
370353 physical reads
0 redo size
15051 bytes sent via SQL*Net to client
1007 bytes received via SQL*Net from client
34 SQL*Net roundtrips to/from client
1 sorts (memory)
1 sorts (disk)
491 rows processed
in test
SQL> set autotrace traceonly
SQL> SELECT rpt_horizon_subledger_entry_vw.onst_offst_cd,
2 rpt_horizon_subledger_entry_vw.bkng_prd,
3 rpt_horizon_subledger_entry_vw.systm_afflt_cd,
4 rpt_horizon_subledger_entry_vw.jrnl_id,
5 rpt_horizon_subledger_entry_vw.ntrl_accnt_cd,
rpt_horizon_subledger_entry_vw.gnrl_ldgr_chrt_of_accnt_nm,
6 7 rpt_horizon_subledger_entry_vw.lgl_entty_brnch_cd,
8 rpt_horizon_subledger_entry_vw.crprt_melob_cd AS corp_mlb_cd,
9 rpt_horizon_subledger_entry_vw.onst_offst_cd, SUM (amt) AS amount
10 FROM rpt_horizon_subledger_entry_vw
11 WHERE rpt_horizon_subledger_entry_vw.bkng_prd = '092008'
12 AND rpt_horizon_subledger_entry_vw.jrnl_id = 'RCS0002100'
AND rpt_horizon_subledger_entry_vw.systm_afflt_cd = 'SAFF01'
13 14 GROUP BY rpt_horizon_subledger_entry_vw.onst_offst_cd,
15 rpt_horizon_subledger_entry_vw.bkng_prd,
16 rpt_horizon_subledger_entry_vw.systm_afflt_cd,
17 rpt_horizon_subledger_entry_vw.jrnl_id,
18 rpt_horizon_subledger_entry_vw.ntrl_accnt_cd,
rpt_horizon_subledger_entry_vw.gnrl_ldgr_chrt_of_accnt_nm,
rpt_horizon_subledger_entry_vw.lgl_entty_brnch_cd,
rpt_horizon_subledger_entry_vw.crprt_melob_cd,
rpt_horizon_subledger_entry_vw.onst_offst_cd; 19 20 21 22
no rows selected
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=92944 Card=708 Bytes
=53100)
1 0 SORT (GROUP BY) (Cost=92944 Card=708 Bytes=53100)
2 1 VIEW OF 'RPT_HORIZON_SUBLEDGER_ENTRY_VW' (Cost=92937 Car
d=708 Bytes=53100)
3 2 SORT (UNIQUE) (Cost=92937 Card=708 Bytes=124962)
4 3 UNION-ALL
5 4 HASH JOIN (Cost=46456 Card=354 Bytes=60180)
6 5 TABLE ACCESS (FULL) OF 'SUBLEDGER_CHART_OF_ACCOU
NT' (Cost=2 Card=57 Bytes=1881)
7 5 NESTED LOOPS (Cost=46453 Card=354 Bytes=48498)
8 7 HASH JOIN (Cost=11065 Card=17694 Bytes=1362438
9 8 HASH JOIN (Cost=27 Card=87 Bytes=5133)
10 9 TABLE ACCESS (FULL) OF 'HORIZON_LINE' (Cos
t=24 Card=87 Bytes=2175)
11 9 TABLE ACCESS (FULL) OF 'GNRL_LDGR_CHRT_OF_
ACCNT' (Cost=2 Card=111 Bytes=3774)
12 8 TABLE ACCESS (FULL) OF 'HORIZON_SUBLEDGER_LI
NK' (Cost=11037 Card=142561 Bytes=2566098)
13 7 TABLE ACCESS (BY INDEX ROWID) OF 'SUBLEDGER_EN
TRY' (Cost=2 Card=1 Bytes=60)
14 13 INDEX (UNIQUE SCAN) OF 'SUBLEDGER_ENTRY_PK'
(UNIQUE) (Cost=1 Card=1)
15 4 HASH JOIN (Cost=46456 Card=354 Bytes=64782)
16 15 TABLE ACCESS (FULL) OF 'SUBLEDGER_CHART_OF_ACCOU
NT' (Cost=2 Card=57 Bytes=1881)
17 15 NESTED LOOPS (Cost=46453 Card=354 Bytes=53100)
18 17 HASH JOIN (Cost=11065 Card=17694 Bytes=1362438
19 18 HASH JOIN (Cost=27 Card=87 Bytes=5133)
20 19 TABLE ACCESS (FULL) OF 'HORIZON_LINE' (Cos
t=24 Card=87 Bytes=2175)
21 19 TABLE ACCESS (FULL) OF 'GNRL_LDGR_CHRT_OF_
ACCNT' (Cost=2 Card=111 Bytes=3774)
22 18 TABLE ACCESS (FULL) OF 'HORIZON_SUBLEDGER_LI
NK' (Cost=11037 Card=142561 Bytes=2566098)
23 17 TABLE ACCESS (BY INDEX ROWID) OF 'SUBLEDGER_EN
TRY' (Cost=2 Card=1 Bytes=73)
24 23 INDEX (UNIQUE SCAN) OF 'SUBLEDGER_ENTRY_PK'
(UNIQUE) (Cost=1 Card=1)
Statistics
1134 recursive calls
0 db block gets
38903505 consistent gets
598254 physical reads
60 redo size
901 bytes sent via SQL*Net to client
461 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
34 sorts (memory)
0 sorts (disk)
0 rows processed
Thanks a lot in advance
JerryHi
Basically there are two kinds of tables
- fact
- lookup
The number of records in a lookup table is usually small.
The number of records in a fact table is usually huge.
However, in test systems the number of records in a fact table is often also small.
This results in different execution plans.
I notice again you don't post version and platform info, and you didn't make sure your explain is properly idented
Please read the FAQ to make sure it is properly idented.
Also using the word 'buddies' is as far as I am concerned nearing disrespect and rudeness.
Sybrand Bakker
Senior Oracle DBA -
How to test for différent Select into a single PL/SQL block ?
Hi,
I am relatively new to PL/SQL and I am trying to do multiple selects int a single PL/SQL block. I am confronted to the fact that if a single select returns no data, I have to go to the WHEN DATA_NOT_FOUND exception.
Or, I would like to test for different selects.
In an authentification script, I am searching in a table for a USER ID (USERID) and an application ID, to check if a user is registered under this USERID for this APPLICATION.
There are different possibilities : 4 possibilities :
- USERID Existing or not Existing and
- Aplication ID found or not found for this particular USERID.
I would like to test for thes 4 possibilities to get the status of this partiular user regardin this application.
The problem is that if one select returns no row, I go to the exception data not found.
In the example below you see that if no row returned, go to the exception
DECLARE
P_USERID VARCHAR2(400) DEFAULT NULL;
P_APPLICATION_ID NUMBER DEFAULT NULL;
P_REGISTERED VARCHAR2(400) DEFAULT NULL;
BEGIN
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;
:P39_TYPE_UTILISATEUR := 'USER_REGISTERED';
EXCEPTION
WHEN NO_DATA_FOUND THEN
:P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND';
END;I would like to do first this statement :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID Then to do this one if the user is found :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;etc...
I basically don't want to go to the not found exception before having tested the 4 possibilities.
Do you have a suggestion ?
Thank you for your kind help !
ChristianSurely there are only 3 conditions to check?
1. The user exists and has that app
2. The user exists and doesn't have that app
3. The user doesn't exist
You could do this in one sql statement like:
with mimic_data_table as (select 1 userid, 1 appid from dual union all
select 1 userid, 2 appid from dual union all
select 2 userid, 1 appid from dual),
-- end of mimicking your table
params_table as (select :p_userid userid, :p_appid appid from dual)
select pt.userid,
pt.appid,
decode(min(case when dt.userid = pt.userid and dt.appid = pt.appid then 1
when dt.userid = pt.userid then 2
else 3
end), 1, 'User and app exist',
2, 'User exists but not for this app',
3, 'User doesn''t exist') user_app_check
from mimic_data_table dt,
params_table pt
where pt.userid = dt.userid (+)
group by pt.userid, pt.appid;
:p_userid = 1
:p_appid = 2
USERID APPID USER_APP_CHECK
1 2 User and app exist
:p_userid = 1
:p_appid = 3
USERID APPID USER_APP_CHECK
1 3 User exists but not for this app
:p_userid = 3
:p_appid = 2
USERID APPID USER_APP_CHECK
3 2 User doesn't exist -
What is the wrong in this PL/SQL block
Hi a...
Can you please tell what is the wrong in this pl/sql block.
declare
TYPE TYP_NT_NUM IS TABLE OF NUMBER ;
v_tab TYP_NT_NUM := TYP_NT_NUM();
TYPE uname is VARRAY(30) of varchar2(100) ;
usr uname := uname ( 'u1','u2','u3','u4' );
TYPE pwd is VARRAY(30) of varchar2(100) ;
psw pwd := pwd('p1','p2','p3','p4');
x number(10):=0;
Cursor fcid IS Select distinct FC_ID From FCMASTER ;
Begin
Open fcid ;
--for ii in usr.first .. usr.last loop
Loop
Fetch fcid Into x ;
Exit When fcid%NOTFOUND ;
v_tab(fcid%ROWCOUNT) := x ;
End loop ;
For iii IN v_tab.FIRST .. v_tab.LAST Loop
dbms_output.put_line(v_tab(iii).FC_ID) ;
End loop ;
End loop; End of outer loop
End;
The error is
Error
[row:28,col:36] ORA-06550: line 28, column 36:
PLS-00487: Invalid reference to variable 'NUMBER'
ORA-06550: line 28, column 4:
PL/SQL: Statement ignored
Thanks in advance,
Palv_tab(iii).FC_ID
declare
type typ_nt_num is table of number;
v_tab typ_nt_num;
begin
select distinct object_id bulk collect into v_tab from all_objects where rownum <= 10;
for i in 1 .. v_tab.count loop
dbms_output.put_line(v_tab(i)) ;
end loop ;
end;
/ -
Can some one please tell me what is the problem in the below pl/sql block
Hi, I have problem with the following pl/sql block, I need this with bulk operation.
-- Assume the following scenario, we are validating dept (master) and emp(child) which are my temporary tables and updating the status back to
-- dept ( for all the validation errors, even if we have any validation at child it has to update the header record with error message),
-- upon successful validation insert the data into dept3, and emp3 interms of batches
-- I have give the sample example with dept and emp, but i have around 10 million records which has around 30-40 validations,
-- I would like to process them in terms of batches using bulk collection as this would do fast processing
-- Can some one please tell me how to insert them in terms of bulk with every set of 1000 records in each batch in this example,for every set of 1000 records
-- i need update batch id with unique number in dept table
-- with current data i can have 50 batches , I need to pass, deptno as parameter to my emp cursor.
-- can some one please tell me how to make this validation and insertion more efficient. so that while inserting the data for every batch it should insert batch id
-- Tried with LIMIT clause as well but not working
-- I am correcting the code as per your comments Request you to please suggest me so that I can correct , I am new to PL/sql, started learning now.
step - 1:
CREATE TABLE DEPT
(DEPTNO NUMBER(6) primary key,
DNAME VARCHAR2(25),
LOC VARCHAR2(23),
batch_id number );
INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK', null);
INSERT INTO DEPT VALUES (20, 'RESEARCH', 'DALLAS', null);
INSERT INTO DEPT VALUES (30, 'SALES', 'CHICAGO', null);
INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON', null);
step - 2:
declare
begin
for i in 1..50000 loop
insert into dept values(40+i, 'OPERATIONS'||i,'BOSTON'||i, null);
end loop;
commit;
exception
when others then
dbms_output.put_line('Exception occured:'||SQLERRM);
end;
step - 3:
create sequence emp_seq start with 1 increment by 1;
step - 4:
CREATE TABLE EMP
(EMPNO NUMBER(15) NOT NULL primary key,
ENAME VARCHAR2(20),
JOB VARCHAR2(20),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7, 2),
COMM NUMBER(7, 2),
DEPTNO NUMBER(6));
INSERT INTO EMP VALUES
(7369, 'SMITH', 'CLERK', 7902,
TO_DATE('17-DEC-1980', 'DD-MON-YYYY'), 800, NULL, 20);
INSERT INTO EMP VALUES
(7499, 'ALLEN', 'SALESMAN', 7698,
TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600, 300, 30);
INSERT INTO EMP VALUES
(7521, 'WARD', 'SALESMAN', 7698,
TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30);
INSERT INTO EMP VALUES
(7566, 'JONES', 'MANAGER', 7839,
TO_DATE('2-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20);
INSERT INTO EMP VALUES
(7654, 'MARTIN', 'SALESMAN', 7698,
TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);
INSERT INTO EMP VALUES
(7698, 'BLAKE', 'MANAGER', 7839,
TO_DATE('1-MAY-1981', 'DD-MON-YYYY'), 2850, NULL, 30);
INSERT INTO EMP VALUES
(7782, 'CLARK', 'MANAGER', 7839,
TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10);
INSERT INTO EMP VALUES
(7788, 'SCOTT', 'ANALYST', 7566,
TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
INSERT INTO EMP VALUES
(7839, 'KING', 'PRESIDENT', NULL,
TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);
INSERT INTO EMP VALUES
(7844, 'TURNER', 'SALESMAN', 7698,
TO_DATE('8-SEP-1981', 'DD-MON-YYYY'), 1500, NULL, 30);
INSERT INTO EMP VALUES
(7876, 'ADAMS', 'CLERK', 7788,
TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);
INSERT INTO EMP VALUES
(7900, 'JAMES', 'CLERK', 7698,
TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 950, NULL, 30);
INSERT INTO EMP VALUES
(7902, 'FORD', 'ANALYST', 7566,
TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 3000, NULL, 20);
INSERT INTO EMP VALUES
(7934, 'MILLER', 'CLERK', 7782,
TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);
commit;
step :- 5
declare
cursor c1 is select * from dept;
k number:=0;
m number:=0;
begin
for i in c1 loop
k:=k+1;
--dbms_output.put_line('k:'||k);
--dbms_output.put_line('i.deptno:'||i.deptno);
m:=0;
for j in 1..5 loop
m:=m+1;
--dbms_output.put_line('m:'||m);
--dbms_output.put_line('i.deptno:'||i.deptno);
insert into emp values
(9000+emp_seq.nextval, 'SMITH'||'_'||emp_seq.currval, 'CLERK'||'_'||emp_seq.currval, 7902,
TO_DATE('17-DEC-1980', 'DD-MON-YYYY'), 800, NULL, i.deptno);
end loop;
end loop;
commit;
exception
when others then
dbms_output.put_line('Exception occured:'||sqlerrm);
end;
step :-6
create table dept3 as select * from dept where 1=2;
create table emp3 as select * from emp where 1=2;
alter table dept add object_id number;
alter table dept add status varchar(20);
alter table dept add err_msg varchar2(200);
alter table emp add object_id number;
-- I have not included the alter statements in the inital creation because i dont want them to insert into dept3 and emp3
CREATE OR REPLACE
PACKAGE test_b
AS
g_batch_id NUMBER;
PROCEDURE emp_ins(
p_EMPNO NUMBER,
p_ENAME VARCHAR2,
p_JOB VARCHAR2,
p_MGR NUMBER,
p_HIREDATE DATE,
p_SAL NUMBER,
p_COMM NUMBER,
p_DEPTNO NUMBER);
PROCEDURE dept_ins(
p_DEPTNO NUMBER,
p_dname VARCHAR2 ,
p_LOC VARCHAR2,
p_batch NUMBER);
PROCEDURE validate_prc;
PROCEDURE main;
TYPE dept_t
IS
TABLE OF dept%ROWTYPE;
hdr_tbl dept_t;
TYPE emp_t
IS
TABLE OF emp%ROWTYPE;
line_tbl emp_t;
TYPE dept_i_t
IS
TABLE OF dept3%ROWTYPE;
hdr_ins_tbl dept_i_t;
TYPE emp_i_t
IS
TABLE OF emp3%ROWTYPE;
line_ins_tbl emp_i_t;
END;
-- pacakge body
CREATE OR REPLACE
PACKAGE body test_b
AS
PROCEDURE emp_ins(
p_EMPNO NUMBER,
p_ENAME VARCHAR2,
p_JOB VARCHAR2,
p_MGR NUMBER,
p_HIREDATE DATE,
p_SAL NUMBER,
p_COMM NUMBER,
p_DEPTNO NUMBER)
IS
BEGIN
INSERT
INTO EMP3
EMPNO ,
ENAME ,
JOB ,
MGR ,
HIREDATE ,
SAL ,
COMM ,
DEPTNO
VALUES
P_EMPNO ,
P_ENAME ,
P_JOB ,
P_MGR ,
P_HIREDATE ,
P_SAL ,
P_COMM ,
P_DEPTNO
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('EXCEPTION AT EMP INSERT'||SQLERRM);
END;
PROCEDURE dept_ins
p_DEPTNO NUMBER,
p_dname VARCHAR2 ,
p_LOC VARCHAR2,
p_batch NUMBER
IS
BEGIN
INSERT
INTO DEPT3
DEPTNO ,
DNAME ,
LOC ,
batch_id
VALUES
p_DEPTNO ,
p_DNAME ,
p_LOC ,
p_batch
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('EXCEPTION AT DEPT INSERT'||SQLERRM);
END ;
PROCEDURE validate_prc
IS
CURSOR c1
IS
SELECT * FROM dept WHERE status IS NULL ;--AND rownum <25;
CURSOR c2(p_dept NUMBER )
IS
SELECT * FROM emp WHERE deptno=p_dept;
e_validation EXCEPTION;
BEGIN
OPEN c1;
LOOP
FETCH c1 BULK COLLECT INTO hdr_tbl limit 5000;
SELECT emp_seq.nextval INTO g_batch_id FROM dual;
EXIT
WHEN hdr_tbl.count = 0;
dbms_output.put_line('batch'||g_batch_id);
END LOOP;
CLOSE c1;
dbms_output.put_line('C1 closed');
--------- Loading data into the inv line table type -------------------------------
FOR i IN 1 .. hdr_tbl.count
LOOP
dbms_output.put_line('started validation');
-- do header level validations
IF hdr_tbl(i).dname IS NULL THEN
hdr_tbl(i).status := 'ERROR';
hdr_tbl(i).err_msg :=',DNAME is null';
END IF;
OPEN c2(hdr_tbl(i).deptno);
LOOP
FETCH c2 BULK COLLECT INTO line_tbl;
-- EXIT WHEN c2%NOTFOUND;
END LOOP;
CLOSE c2;
FOR j IN 1 .. line_tbl.count
LOOP
-- do line validations
IF line_tbl(j).ename IS NULL THEN
hdr_tbl(i).status := 'ERROR';
hdr_tbl(i).err_msg :=',ENAME is null';
END IF;
BEGIN
FORALL j IN line_tbl.FIRST .. line_tbl.LAST
SAVE EXCEPTIONS
UPDATE EMP
SET object_id =3
-- I have multiple columns to update based on validations
WHERE deptno =hdr_tbl(i).deptno------------
AND empno =line_tbl (j).empno;
COMMIT;
line_tbl.DELETE;
dbms_output.put_line( 'Successfully updated emp temp table.');
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
dbms_output.put_line( 'Error while updating line temp table. ' || sqlerrm );
FOR j IN 1 .. sql%BULK_EXCEPTIONS.COUNT
LOOP
DBMS_OUTPUT.put_line(' occurred during line temp table updation ' || sql%BULK_EXCEPTIONS(i).ERROR_INDEX );
END LOOP;
raise e_validation;
END;
END LOOP; -- j
--CLOSE c2;
IF hdr_tbl(i).err_msg IS NULL THEN
hdr_tbl (i).status := 'VALID';
hdr_tbl (i).err_msg := NULL;
END IF;
-- even if I have line validation failed I have to update header status and erorr msg
BEGIN
FORALL i IN hdr_tbl.FIRST .. hdr_tbl.LAST
SAVE EXCEPTIONS
UPDATE DEPT
SET object_id =4,
status = hdr_tbl (i).status,
err_msg = hdr_tbl (i).err_msg
-- batch_id =
-- I have multiple columns to update based on validations
WHERE deptno = hdr_tbl (i).deptno
AND status IS NULL; ------------
COMMIT;
hdr_tbl.DELETE;
dbms_output.put_line( 'Successfully updated dept temp table.');
--close c1;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
dbms_output.put_line( 'Error while updating hdr temp table. ' || sqlerrm );
FOR i IN 1 .. sql%BULK_EXCEPTIONS.COUNT
LOOP
DBMS_OUTPUT.put_line(' occurred during line temp table updation ' || sql%BULK_EXCEPTIONS(i).ERROR_INDEX );
END LOOP;
raise e_validation;
END;
END LOOP; --i
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('EXCEPTION AT validate'||SQLERRM);
END ;
PROCEDURE main
IS
CURSOR dept_ins_cur
IS
SELECT * FROM dept WHERE status='VALID';
CURSOR emp_ins_cur(p_deptno NUMBER)
IS
SELECT * FROM emp WHERE deptno= p_deptno;
BEGIN
validate_prc;
OPEN dept_ins_cur;
LOOP
FETCH dept_ins_cur BULK COLLECT INTO hdr_ins_tbl limit 1000
EXIT
WHEN dept_ins_cur%NOTFOUND;
END LOOP;
CLOSE dept_ins_cur;
--------- Loading data into the inv line table type -------------------------------
FOR i IN 1 .. hdr_tbl.count
loop
dept_ins(hdr_ins_tbl(i).deptno ,
hdr_ins_tbl(i).DNAME ,
hdr_ins_tbl(i).LOC , emp_seq.nextval);
commit;
OPEN emp_ins_cur(hdr_ins_tbl(i).deptno);
LOOP
FETCH emp_ins_cur BULK COLLECT INTO line_ins_tbl;
--EXIT WHEN emp_ins_cur%NOTFOUND;
END LOOP;
CLOSE emp_ins_cur;
for j in 1..line_ins_tbl.count loop
emp_ins(line_ins_tbl(j).EMPNO ,
line_ins_tbl(j).ENAME ,
line_ins_tbl(j).JOB ,
line_ins_tbl(j).MGR ,
line_ins_tbl(j).HIREDATE ,
line_ins_tbl(j).SAL ,
line_ins_tbl(j).comm ,
line_ins_tbl(j).DEPTNO );
end loop;
end loop;
commit;
BEGIN
forall i IN hdr_ins_tbl.first .. hdr_ins_tbl.last
SAVE exceptions
UPDATE dept
SET status = 'INSERTED',
err_msg = null
WHERE deptno=hdr_ins_tbl (i).deptno
AND status = 'VALID';
COMMIT;
hdr_ins_tbl.delete;
dbms_output.put_line( 'inserting into temp tables.');
EXCEPTION
WHEN OTHERS THEN
rollback;
end;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('exception in main' ||SQLERRM);
END ;
END;
Thanks in advance...
Message was edited by: 888025Hi, I have problem with the following pl/sql block
Well, as Hoek already said, that is the understatement of the century.
I can't be absolutely certain but I think that set of DDL and code that you posted has just about every possible error and design issue that there is! It would make an excellent addition to BluShadow's FAQs an an example of what NOT to do.
I don't think it is even possible to 'fix the basics first' as Hoek suggested. IMHO the first step needs to be to create a functional requirements document (FRD) that explains in detail WHAT needs to be done. That doc should also contain info about how any errors/recovery/restart is to be handled. It is premature to try to implement ANY solution without first knowing what is needed functionally.
Once the FRD is done you should do a walk-through based on your current architecture and sample data to make sure that the document really covers ALL of the steps that need to be performed and that it adequately explains how to deal with any processing or data issues that might arise.
The next document you need is the TRD - Technical Requirements Doc that covers the different technical implementions of the FRD that can be done and the advantages/disadvantages of each.
Then you can start working on a prototype.
1. The DDL you posted isn't coherent - there are CREATE table statements and then later ALTER statements that add additional columns. There doesn't appear to be any reason for not including ALL of the columns in the CREATE table statement.
2. You are using PL/SQL types instead of SQL types. That makes it impossible to use those types in SQL statements and makes it much more difficult to test since it is much easier to test a query in SQL (e.g. using sql*plus) that to embed the query in PL/SQL.
3. You are defining the same type twice but giving it different names.
TYPE dept_t
IS
TABLE OF dept%ROWTYPE
INDEX BY binary_integer;
TYPE dept_i_t
IS
TABLE OF dept%ROWTYPE
INDEX BY binary_integer;
Those are both based on the same DEPT table! Why the duplication?
Also you are using associative arrays instead of just using nested tables. Get rid of the INDEX BY clause.
4. You have some serious architectural and data model issues
-- Assume the following scenario, we are validating dept (master) and emp(child) which are my temporary tables and updating the status back to
-- dept ( for all the validation errors, even if we have any validation at child it has to update the header record with error message),
Why would you do that? You say 'it has to update the header record ...'. Says who? That is just one indication that you are trying to implement a 'solution' before you have adequately defined the 'problem'.
Typically you would NOT alter any of the data tables; any validation errors/issues would get inserted into a table specifically designed to hold/log those issues. That table would contain key field values to correlate with the source of the error.
Those 'master' and 'child' entities are two SEPARATE things. Issues with a 'master' row have NOTHING to do with any possible child rows.
And issues with a 'child' row have NOTHING to do with any possible master rows. The ONLY connection between 'child' and 'master' is the foreign key that correlates them.
So you don't necessarily have to validate the 'child' rows in sync with their 'master' row. In many cases you would have a procedure that performs validation of the entire set of 'master' rows and log those issues/problems. You would use a different procedure to validate the entire set of 'child' rows and log their issues.
Those validation procedures can often work with ALL of the data using SQL statements instead of bulk processing.
5. You are using loop constructs that are not valid for the type of processing you are using
LOOP
FETCH c1 BULK COLLECT INTO hdr_tbl;
EXIT
WHEN c1%NOTFOUND;
END LOOP;
There can be NO exit since the bulk collect with either get EVERYTHING or NOTHING. Possibly that is just a holdover from your attempt to use the LIMIT clause but you removed that clause from the FETCH; I don't know.
There is so much wrong with what you posted it is really rather pointless to try to 'fix' it.
I suggest you start over and clarify and DOCUMENT the actual requirements without prejudice about the solution that someone seems to want to force on you. -
Does anyone else notice the more you use SQL Worksheet, the
slower it gets? The first time I start it up, it'll run a
compile on an object super-fast. After running a dozen or more
compiles and test scripts, I notice it's getting slower.
Eventually, it's so slow I just kill SQL Worksheet and start it
right back up. Then it's back to warp speed again!
I'm on a Win2K machine, running Oracle 8.0.6, with version 1.6.0
of SQL Worksheet.
I have 2.1 install disc for Oracle Enterprise Manager, but I'm
uncertain if I can update what I've got (given the release of
Oracle I'm on). Any help here would be appreciated, too.The box does not reboot itself at 7am every day at the behest of BT that is not normal behaviour.
I think you really ought to fo a hard reset and clear everything off your hard drive and see if it solves your problem.
If it does not then you are I think looking at a slowly dying box which needs to be replaced.
Factory Reset
Switch off the Vision+ box at the mains socket
Hold down the front panel OK and down arrow buttons
Switch on the power to the Vision+ box
Allow the box to start up (about 15 seconds)
Release the OK and down arrow buttons
The Vision+ box will then contact the servers to get a new copy of its firmware
This will take around 30 minutes
Life | 1967 Plus Radio | 1000 Classical Hits | Kafka's World
Someone Solved Your Question?
Please let other members know by clicking on ’Mark as Accepted Solution’
Helpful Post?
If a post has been helpful, say thanks by clicking the ratings star.
Maybe you are looking for
-
Mixing Ram Sizes in Triple-Channel
I would like to install 10 GB of RAM in the following configuration on my 2009 Mac Pro (flashed to 5,1): Slot 1: 4GB Slot 2: 4GB Slot 3: 2GB All 3 dimms are Apple OEM Hynix brand. All are 1333MHz. Will this arrangement take advantage of the tripl
-
Bought apps not reflected as "Downloaded" on account
I have two iTunes Store accounts. (One in the US, one in SG) I have purchased a considerable number of apps in the SG Store before i started using the US Store (full-time now) The Context: iTunes used to display as "Downloaded" all the apps I have pu
-
Uninstall SAP HANA server tool
Hi Experts, I want steps on how to uninstall SAP hana server tools. I didn't find any way to do that so I deleted the folder but with that when I try to install server components I get error failed ,roll back. Urgent help on how to uninstall SAP HANA
-
Export procedure for intrastat purposes
Dear all, In Tcode Z*** is showing sales documents for which export procedure for intrastat purposes is no longer automatically determined in some case.Please let me know the possible reasons. Regards, Praveen
-
Mainstage as Instrument simultaneous with Logic as a sequencer
I'm new to both Logic 8 and Mainstage and am looking to utilize Mainstage as part of my live rig. I have the audio interface and I think I can get thru setting something up, but I'm hoping to take this a step further. We're gearing up to play with se