Tune the PL/SQL block with SQL_ID
Hi There,
I have found some recommendation in ADDM report as follows.
"" Action
Tune the PL/SQL block with SQL_ID "48trcns4mx5bk". Refer to the "Tuning
PL/SQL Applications" chapter of Oracle's "PL/SQL User's Guide and
Reference".
Related Object ""
can any one let me how to Tune the PL/SQL block with SQL_ID?
looking forward.
Db: 11.1.0.7
OS: OracleLinux5-86*64
Regards,
Mohsin
Hi,
you can't tune a PL/SQL block directly. Instead, you'll need to profile it first (i.e. see how much time SQL statements inside it consume) using dbms_profiler or some other tool. If you find that the problem is that some SQL is called too frequently because of flawed PL/SQL logic, then you'll need to address that. Otherwise, you'll need to take the top time consuming statement(s) and tune it (them).
Best regards,
Nikolay
Similar Messages
-
How to Run SQL Tuning Advisor on the SQL statement with SQL_ID?
Can you give the steps to run the SQL tuning advisor on the SQL statement with SQL_ID?
Database version: 10g Release 2Hi,
You can use either the automatic SQL tuning features that are accessible from Enterprise Manager Database Console on the "Advisor Central" page or trough SQL*PLUS using the DBMS_SQLTUNE pakage:
-- creating the tuning task
set serveroutput on
declare
l_sql_tune_task_id varchar2(100);
begin
l_sql_tune_task_id := dbms_sqltune.create_tuning_task (
sql_id => '<your_sql_id>',
scope => dbms_sqltune.scope_comprehensive,
time_limit => 60,
task_name => '<your_tuning_task_name>',
description => 'tuning task for statement your_sql_id.');
dbms_output.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
end;
-- executing the tuning task
exec dbms_sqltune.execute_tuning_task(task_name => '<your_tuning_task_name>');
-- displaying the recommendations
set long 100000;
set longchunksize 1000
set pagesize 10000
set linesize 100
select dbms_sqltune.report_tuning_task('<your_tuning_task_name>') as recommendations from dual;For more information, take a look at link provided by Jaffy.
Cheers
Legatti -
Cell Offload will Happen for pl/sql Block with variables
Hello Experts,
i am working on procedures on exadata now. i was confused with cell offload in exadata. somehow offload is not happening when i ran the sql statement in in pl/sql block with variables.
here are my findings.
when i ran insert into from select with values at toad, my query response time is very good. the total process is completed in less than a minute.
i checked offload is happening.
same sql statement is placed in plsql block with variable, procedure is taking lot of time and it is not completing. this case offload is not happening.
is it true, if i use variables in pl/sql block will not use cell offload and smart scan?
if yes, what is the work around.
Thanks
#! PavanHello Marc,
Thanks for quick response.
when i ran the query with literals in toad session i am getting response.
when i run it with pl/sql block , block is not completing at all.
here is the plsql block:
My Apologies for sending big code,with out proper format.
DECLARE
P_BUSINESS_DATE DATE;
P_BATCH_ID NUMBER;
UTC_OFFSET NUMBER;
BEGIN
P_BUSINESS_DATE := to_date('02/01/2012', 'MM/DD/YYYY');
P_BATCH_ID := 1;
UTC_OFFSET := 0;
INSERT /*+ APPEND */ INTO UPL_CLIENT_tbl
( reportdate,
LastName,
FirstName,
MiddleInitial,
AccountNumber,
Address,
City,
State,
Zip,
HomePhone,
WorkPhone,
BirthDate,
Age,
Sex,
NumberOfChildren,
Occupation,
LeadSource,
Consultant,
ProgramDirector,
CallTaker,
LeadDate,
FirstVisitDate,
LastVisitDate,
BillType,
ClientType,
PreviousClientType,
AppointmentDate,
DoctorLetterRequired,
OneYearPermStabilizationDate,
UnlimitedPermStabilizationDate,
MaritalStatus,
ReferrerName,
ReferrerCentreID,
CentreID,
PaymentDateOne,
PaymentAmountOne,
PaymentDateTwo,
PaymentAmountTwo,
PaymentDateThree,
PaymentAmountThree,
PaymentDateFour,
PaymentAmountFour,
LibraryPurchased,
BalanceDue,
FoodNSFBalance,
ProductNSFBalance,
ProgramNSFBalance,
StartWeight,
CurrentWeight,
GoalWeight,
Height,
DateGoalWeightAchieved,
DateSuccessPlusPurchased,
ReturnToActiveDate,
VersionNumber,
HalfWayDate,
LastLSCDate,
LastUpdatedDate,
VitaminWaiverSigned,
LastSupplementPurchaseDate,
LastSupplementCodePurchased,
LastTotalSupplementSupplyCycle,
LastAddtlSupplPurchaseDate,
LastAddtlSupplCodePurchased,
LastAddtlSupplSupplyCycle,
DiabetesClient,
DietControlled,
TakingOralMed,
TakingInsulin,
EmailId,
CTADate,
RWLDate,
Address2)
(SELECT /*+ full(S_CONTACT) full(REFERRER) full(Consultant) full(ProgramDirector) full(CallTaker) full(S_CONTACT_X) full(a) full(a2) full (a3) */ distinct p_business_date reportdate,
SUBSTR(S_CONTACT.LAST_NAME,1,25) AS LastName,
SUBSTR(S_CONTACT.FST_NAME,1,25) AS FirstName,
SUBSTR(S_CONTACT.MID_NAME,1,1) AS MiddleInitial,
S_CONTACT.X_JC_ACNT_NUM + 900000000 AS AccountNumber,
SUBSTR(S_ADDR_PER.ADDR,1,40) AS ADDRESS,
SUBSTR(S_ADDR_PER.CITY,1,20) AS City,
S_ADDR_PER.STATE AS State,
SUBSTR(S_ADDR_PER.ZIPCODE,1,15) AS Zip,
SUBSTR(REPLACE(S_CONTACT.HOME_PH_NUM,'-',''),1,10) AS HomePhone,
SUBSTR(REPLACE(S_CONTACT.WORK_PH_NUM,'-',''),1,10) AS WorkPhone,
S_CONTACT.BIRTH_DT AS BirthDate,
CASE WHEN FLOOR((p_business_date - S_CONTACT.BIRTH_DT)/360) < 0 THEN NULL ELSE FLOOR((p_business_date - S_CONTACT.BIRTH_DT)/360) END AS AGE,
S_CONTACT.SEX_MF AS SEX,
NULL AS NumberOfChildren,
S_CONTACT_X.ATTRIB_34 AS OCCUPATION,
CASE WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Othe' THEN 'Othr'
WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Inte' THEN 'Intr'
WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Prin' THEN 'News'
WHEN SUBSTR(S_CONTACT_X.ATTRIB_37,1,4)='Gues' THEN 'Gst'
ELSE SUBSTR(S_CONTACT_X.ATTRIB_37,1,4) END AS LeadSource,
SUBSTR(Consultant.EMP_NUM,1,10) AS CONSULTANT,
ProgramDirector.EMP_NUM AS ProgramDirector,
CallTaker.EMP_NUM CallTaker,
S_CONTACT.X_LEAD_DT AS LeadDate,
LEAST(nvl(S_CONTACT.X_LAST_CONSULTATION_DATE,O.FirstPurchaseDate ), nvl(O.FirstPurchaseDate,S_CONTACT.X_LAST_CONSULTATION_DATE+1) ) AS FirstVisitDate, --X_LAST_CONSULTATION_DATE stores the performed date or the legacy client firstvisitdate
GREATEST(nvl(S_CONTACT_XM.X_CONSULTATION_DT ,S_CONTACT_X.ATTRIB_29), nvl(S_CONTACT_X.ATTRIB_29, S_CONTACT_XM.X_CONSULTATION_DT-1) ) AS LastVisitDate,
CASE WHEN S_CONTACT.X_INSTALLMENT_BALANCE > 0 THEN 'B' ELSE NULL END AS BillType,
ct.current_client_type ClientType,
SUBSTR(ct.saved_client_type,1,1) PreviousClientType,
S_CONTACT.LAST_CREDIT_DT AS AppointmentDate,
CASE WHEN a.X_DR_LETTER_STATUS IS NOT NULL THEN 'Y' ELSE 'N' END AS DoctorLetterRequired,
NULL AS OneYearPermStabilizationDate,
DECODE(S_PROD_INT.X_PROGRAM_CLASSIFICATION,'Premium',a.START_DT ,NULL) AS UnlimitedPermStabilizationDate,
SUBSTR(S_CONTACT.MARITAL_STAT_CD,1,1) AS MaritalStatus,
SUBSTR(REFERRER.FST_NAME ||' '|| REFERRER.LAST_NAME,1,34) AS ReferrerName,
ORGEXT_REF.LOC AS ReferrerCentreID,
S_ORG_EXT.LOC AS CentreID,
NULL AS PaymentDateOne,
NULL AS PaymentAmountOne,
NULL AS PaymentDateTwo,
NULL AS PaymentAmountTwo,
NULL AS PaymentDateThree,
NULL AS PaymentAmountThree,
NULL AS PaymentDateFour,
NULL AS PaymentAmountFour,
NULL AS LibraryPurchased,
nvl(S_CONTACT.X_INSTALLMENT_BALANCE,0) + nvl(S_CONTACT.X_PREPAID_BALANCE,0) AS BalanceDue, -- Changed operation from (-) prepaid to (+) prepaid since the sign was flipped in OLTP.
NULL AS FoodNSFBalance,
NULL AS ProductNSFBalance,
NULL AS ProgramNSFBalance,
a2.X_START_WEIGHT AS StartWeight,
a2.X_CURRENT_WEIGHT AS CurrentWeight,
a2.X_GOAL_WEIGHT AS GoalWeight,
a3.X_HEIGHT AS Height,
a2.X_FAXSENT_DATETIME DateGoalWeightAchieved,
DECODE(S_PROD_INT.X_PROGRAM_CLASSIFICATION,'Premium',a.START_DT,NULL) AS DateSuccessPlusPurchased,
CASE WHEN A2.ARCHIVE_FLG = 'N' THEN a2.START_DT ELSE NULL END AS ReturnToActiveDate,
600 VersionNumber,
a2.X_FAXRECV_DATETIME AS HalfWayDate,
NULL AS LastLSCDate,
TRUNC(S_CONTACT.LAST_UPD-UTC_OFFSET/24) AS LastUpdatedDate,
NULL AS VitaminWaiverSigned,
LastSupplementPurchaseDate,
LastSupplementCodePurchased,
LastTotalSupplementSupplyCycle,
LastAddtlSupplPurchaseDate,
LastAddtlSupplCodePurchased,
LastAddtlSupplSupplyCycle,
CASE WHEN (a.X_DIABETES_NO_MEDS_FLG='Y' OR a.X_DIABETES_ORAL_MEDS_FLG = 'Y' OR a.X_DIABETES_ON_INSULIN_FLG = 'Y') THEN 'Y' ELSE 'N' END AS DiabetesClient,
DECODE(a.X_DIABETES_NO_MEDS_FLG,'Y','Y','N') AS DietControlled,
a.X_DIABETES_ORAL_MEDS_FLG AS TakingOralMed,
a.X_DIABETES_ON_INSULIN_FLG AS TakingInsulin,
S_CONTACT.EMAIL_ADDR AS EmailId,
NULL CTADATE,
NULL RWLDATE,
SUBSTR(S_ADDR_PER.ADDR_LINE_2,1,40) AS Address2
FROM S_CONTACT,
S_CONTACT REFERRER,
S_CONTACT Consultant,
S_CONTACT ProgramDirector,
S_CONTACT CallTaker,
S_CONTACT_X,
(SELECT /*+ parallel full(S_CONTACT_XM) */ PAR_ROW_ID, attrib_05, MAX(X_CONSULTATION_DT) AS X_CONSULTATION_DT FROM S_CONTACT_XM
WHERE (S_CONTACT_XM.last_upd_by < '1-14WD'
or S_CONTACT_XM.last_upd_by > '1-14WD')
AND S_CONTACT_XM.ATTRIB_05 IN (SELECT row_id FROM S_ORG_EXT WHERE S_ORG_EXT.ACCNT_TYPE_CD IN ('Corporate Centre','Franchise Centre')) LOC IN (SELECT centreid FROM UPL_LIVE_CENTRES WHERE LIVE = 'Y' AND BATCHID = p_batch_id)) where S_ORG_EXT.ACCNT_TYPE_CD IN ('Corporate Centre','Franchise Centre')) --
GROUP BY PAR_ROW_ID, attrib_05) S_CONTACT_XM,
(SELECT CONTACT_ID, ACCNT_ID,
MAX(LastSupplementPurchaseDate) AS LastSupplementPurchaseDate,
MAX(LastSupplementCodePurchased) AS LastSupplementCodePurchased,
MAX(LastTotalSupplementSupplyCycle) AS LastTotalSupplementSupplyCycle,
MAX(LastAddtlSupplPurchaseDate) AS LastAddtlSupplPurchaseDate,
MAX(LastAddtlSupplCodePurchased) AS LastAddtlSupplCodePurchased,
MAX(LastAddtlSupplSupplyCycle) AS LastAddtlSupplSupplyCycle,
MIN(FirstPurchaseDate) AS FirstPurchaseDate,
MAX(LastPurchaseDate) AS LastPurchaseDate
FROM (
SELECT /*+ parallel full(S_ORDER) full(S_ORDER_XM) */ S_ORDER.CONTACT_ID AS CONTACT_ID,S_ORDER.ACCNT_ID,
NULL AS LastSupplementPurchaseDate,
NULL AS LastSupplementCodePurchased,
NULL AS LastTotalSupplementSupplyCycle,
NULL AS LastAddtlSupplPurchaseDate,
NULL AS LastAddtlSupplCodePurchased,
NULL AS LastAddtlSupplSupplyCycle,
(S_ORDER_XM.X_BUSINESS_DATE) FirstPurchaseDate,
(S_ORDER_XM.X_BUSINESS_DATE) LastPurchaseDate
FROM S_ORDER,S_ORDER_XM
WHERE S_ORDER.ROW_ID = S_ORDER_XM.PAR_ROW_ID
AND S_ORDER.STATUS_CD IN ('Complete', 'Submitted', 'Ready')
AND TRUNC(S_ORDER_XM.X_BUSINESS_DATE - UTC_OFFSET/24) <= (p_business_date)
--GROUP BY S_ORDER.CONTACT_ID
UNION ALL
SELECT /*+ parallel full(S_ORDER) full (S_ORDER_ITEM) */ S_ORDER.CONTACT_ID AS CONTACT_ID,S_ORDER.ACCNT_ID,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '931' THEN S_ORDER.CREATED ELSE NULL END) AS LastSupplementPurchaseDate,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '931' THEN 931 ELSE NULL END) AS LastSupplementCodePurchased,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '931' THEN 7 ELSE NULL END) AS LastTotalSupplementSupplyCycle,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '920' THEN S_ORDER.CREATED ELSE NULL END) AS LastAddtlSupplPurchaseDate,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '920' THEN 920 ELSE NULL END) AS LastAddtlSupplCodePurchased,
(CASE WHEN SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) = '920' THEN 28 ELSE NULL END) AS LastAddtlSupplSupplyCycle,
NULL FirstPurchaseDate,
NULL LastPurchaseDate
FROM S_ORDER,S_ORDER_ITEM, S_PROD_INT
WHERE S_ORDER_ITEM.PROD_ID = S_PROD_INT.ROW_ID
AND S_ORDER.ROW_ID = S_ORDER_ITEM.ORDER_ID
AND S_ORDER_ITEM.qty_req <> 0
AND s_order.created_by <> '1-14WD'
AND S_ORDER_ITEM.PAR_ORDER_ITEM_ID is null
AND (S_ORDER_ITEM.PAR_ORDER_ITEM_ID is null
OR EXISTS (select 1 from S_ORDER_ITEM i2,s_prod_int p
where i2.row_id = S_ORDER_ITEM.PAR_ORDER_ITEM_ID
and SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) IN ('931','920')
and i2.prod_id = p.row_id
AND S_ORDER.status_cd in ('Complete', 'Submitted', 'Ready')
and SUBSTR(SUBSTR(S_PROD_INT.PART_NUM,1,INSTR(S_PROD_INT.PART_NUM,'-',1,1)-1),2,4) IN ('931','920')
GROUP BY CONTACT_ID,ACCNT_ID) O,
S_CONTACT_TNTX,
S_ORG_EXT,
S_ORG_EXT ORGEXT_REF,
S_ADDR_PER,
S_ASSET a,
S_PROD_INT,
S_ASSET a2,
S_ASSET a3,
UPL_CLIENT_TYPES ct,
(select /*+ parallel */ o.contact_id, o.accnt_id
from S_ORDER o, S_ORDER_XM oxm
where o.row_id = oxm.par_row_id
and trunc(oxm.X_BUSINESS_DATE - (UTC_OFFSET/24)) = trunc(p_business_date)
group by o.contact_id, o.accnt_id) oxm2
WHERE S_CONTACT.ROW_ID = S_CONTACT_X.PAR_ROW_ID
AND S_CONTACT_X.ROW_ID = S_CONTACT_XM.PAR_ROW_ID (+)
AND (S_ORG_EXT.ROW_ID = S_CONTACT.PR_DEPT_OU_ID
OR S_ORG_EXT.ROW_ID = oxm2.accnt_id
OR S_ORG_EXT.ROW_ID = S_CONTACT_XM.attrib_05)
AND ORGEXT_REF.ROW_ID(+) = REFERRER.PR_DEPT_OU_ID
AND S_CONTACT.CON_ASST_PER_ID = Consultant.ROW_ID
AND S_ORG_EXT.X_DIRECTOR_ID = ProgramDirector.ROW_ID (+)
AND S_CONTACT.CREATED_BY = CallTaker.ROW_ID
AND S_CONTACT.ROW_ID = a.PR_CON_ID (+)
AND S_CONTACT.PR_PER_ADDR_ID = S_ADDR_PER.ROW_ID (+)
AND S_CONTACT_TNTX.PAR_ROW_ID (+) = S_CONTACT.ROW_ID
AND REFERRER.ROW_ID(+) = S_CONTACT_TNTX.REFERRED_BY_ID
AND a.PROD_ID = S_PROD_INT.ROW_ID (+)
AND O.CONTACT_ID (+) = S_CONTACT.ROW_ID
AND a.STATUS_CD (+) = 'Active'
AND a.TYPE_CD (+) ='Program'
AND S_CONTACT.ROW_ID = a2.PR_CON_ID (+)
AND a2.STATUS_CD (+) = 'Active'
AND a2.TYPE_CD (+) = 'Lifecycle'
AND a3.PR_CON_ID(+) = S_CONTACT.ROW_ID
AND a3.STATUS_CD (+) = 'Active'
AND a3.TYPE_CD (+) = 'HealthSheet'
AND S_CONTACT.X_JC_ACNT_NUM = ct.CLIENT_NUMBER (+)
--AND S_ORG_EXT.LOC NOT LIKE 'F%'
AND S_ORG_EXT.ACCNT_TYPE_CD NOT IN 'Division'
--AND S_ORG_EXT.Loc in (select to_char(centreid) from UPL_LIVE_CENTRES where LIVE = 'Y')
AND (trunc(S_CONTACT.LAST_UPD - (UTC_OFFSET/24)) = trunc(p_business_date) or trunc(S_CONTACT_X.LAST_UPD - (UTC_OFFSET/24)) = trunc(p_business_date) OR (S_CONTACT_XM.X_CONSULTATION_DT = p_business_date) OR oxm2.CONTACT_ID IS NOT NULL)
AND S_CONTACT.last_upd_by not in ('1-14WD')
AND oxm2.CONTACT_ID (+) = o.CONTACT_ID
AND S_ORG_EXT.LOC <> 'CW_846'
AND (a.pr_accnt_id in (select row_id from S_ORG_EXT where S_ORG_EXT.LOC IN (Select CentreID from UPL_Live_Centres where BATCHID = p_batch_id)) or a.pr_accnt_id is null)
AND (a2.pr_accnt_id in (select row_id from S_ORG_EXT where S_ORG_EXT.LOC IN (Select CentreID from UPL_Live_Centres where BATCHID = p_batch_id)) or a2.pr_accnt_id is null)
AND (a3.pr_accnt_id in (select row_id from S_ORG_EXT where S_ORG_EXT.LOC IN (Select CentreID from UPL_Live_Centres where BATCHID = p_batch_id)) or a3.pr_accnt_id is null));
rollback;
END;
-------------------------------------------------------------------------------------------------- -
Can't create a sequence within a pl/sql block with execute immediate.
Hi All. I created a user and granted it the 'create sequence' privilege though a role. In a pl/sql block I try to create a sequence using 'execute immediate' but get a 1031-insufficient privileges error. If I grant create sequence directly to the user, the pl/sql block completes successfully. Can anyone explain this behavior? We're running 11.2 Enterprise Editon.
Thanks,
MarkIn a definer's rights stored procedure (the default), you only have access to privileges that have been granted directly, not via a role.
There are two basic reasons for that. First, roles can be enabled or disabled, default and non-default, password-protected, etc. so the set of roles a particular user actually has is session-specific. Oracle needs to know at compile time what privileges the owner of the procedure has. The only way to do that (without deferring the privilege check) is to ignore privileges granted through roles.
Second, since 99% of privilege management DBAs do involves granting and revoking roles, it's helpful that changing role privileges will never cause objects to be marked invalid and recompiled which can have side-effects on applications. DBAs only need to worry about causing problems on those rare cases where they are granting or revoking direct privileges to users.
You can create an invoker's rights stored procedure by adding the clause (AUTHID CURRENT_USER). That defer's the security check to run-time but allows the procedure to see privileges granted through roles in the current session. But that means that the caller of the procedure would need to have the CREATE SEQUENCE privilege through the role, not the owner of the procedure.
And just to make the point, dynamic object creation in PL/SQL is almost always a red flag that there is something problematic in your design. If you are creating sequences dynamically, that means that you'd have to refer to them dynamically throughout your code which means that your inserts would need to use dynamic SQL. That's not a particularly easy or safe way to develop code.
Justin -
I was trying to create a PL/SQL block where I am trying to call all the SQL Plans and then drop them one by one. Here is how I am doung -
SET SERVEROUT ON;
DECLARE
EXECSTR VARCHAR2(50);
v_plans_dropped pls_integer;
CURSOR C1 IS SELECT SQL_HANDLE FROM DBA_SQL_PLAN_BASELINES;
BEGIN
FOR I IN C1 LOOP
EXECSTR := ''''||I.SQL_HANDLE||'''';
v_plans_dropped:=dbms_spm.drop_sql_plan_baseline(sql_handle=>EXECSTR);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR while dropping SQL PLAN: ' || SQLCODE || ' : ' || SQLERRM);
END;
This is giving me error like - ERROR while dropping SQL PLAN: -38131 : ORA-38131: specified SQL handle
'SYS_SQL_1470897e7b72c982' does not exist
Whereas this SQL Plan is there in the baseline - SELECT sql_handle FROM dba_sql_plan_baselines;
SQL_HANDLE
SYS_SQL_1470897e7b72c982
SYS_SQL_75ac336a8071cb06
SYS_SQL_269cdcd4862f8685
SYS_SQL_269cdcd4862f8685
SYS_SQL_0ffdb3bddbe422e2
SYS_SQL_14d81bbae4a7cc93
SYS_SQL_5c512b58e7795ba2
SYS_SQL_33515785e80b75d0
Above PL/SQL block should be same as like deleting it one by one -
DECLARE
v_plans_dropped pls_integer;
BEGIN
v_plans_dropped:=dbms_spm.drop_sql_plan_baseline(sql_handle=>'SYS_SQL_1470897e7b72c982');
END;
If I run this then it will be sucessul but when I run under a PL/SQL block using cursor then it is giving me error ORA-38131.
Can you please tell me where I am going wrong here.
Thanks for your time!I have this PL/SQL block -
DECLARE
v_plans_dropped pls_integer;
CURSOR C1 IS SELECT SQL_HANDLE FROM DBA_SQL_PLAN_BASELINES;
BEGIN
FOR I IN C1 LOOP
v_plans_dropped:=dbms_spm.drop_sql_plan_baseline(sql_handle=>I.SQL_HANDLE);
END LOOP;
END;
Requirement - This PL/SQL block should read all the records from DBA_SQL_PLAN_BASELINES table and drop all the plans one by one.
Problem - It gives me error like this -
SQL> 2 3 4 5 6 7 8 9 DECLARE
ERROR at line 1:
ORA-38131: specified SQL handle SYS_SQL_45c1170505dda9a9 does not exist
ORA-06512: at "SYS.DBMS_SPM", line 2444
ORA-06512: at line 6
Analysis: When I ran it 4 times, it showed me that the remaining records after the pl/sql run was like -
SQL> SELECT COUNT(*) FROM DBA_SQL_PLAN_BASELINES;
After First Run -
COUNT(*)
33429
After Second Run -
COUNT(*)
33255
After Third Run -
COUNT(*)
33228
After Fourth Run -
COUNT(*)
32988
So, it deletes records but errors out in between. Is it because the PL/SQL block/cursor is not structured properly?
Thanks for your advice! -
hi, my daughter wrote wrong paswords in my ipod touch and it is blocked. It says it needs to be connected to itunes, but once its there it says the ipod is blocked with a passcode..the ipod is just blocked. what can I do?
Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
iOS: Wrong passcode results in red disabled screen
If recovery mode does not work try DFU mode.
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
For how to restore:
iTunes: Restoring iOS software
To restore from backup see:
iOS: How to back up
If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
You can redownload iTunes purchases by:
Downloading past purchases from the App Store, iBookstore, and iTunes Store -
How to define the tab space in the PL/SQL editor with Oracle Forms 4.5?
When I use the PL/SQL editor with Oracle Form Builder, I found the tab space is very long that affects my programs readability quite a lot. Then, I tried to use Textpad to type my program. It looks fine with Textpad. However, when i tried to 'cut and paste' my code back to the PL/SQL editor, all tab spaces (approx. 8-character) are detected and the program looks awful again ~~ Would any one help me to solve my mentioned problem?
Thanks for any advices!In 4.5 you cannot change this. In Forms 5.0 and above there is a registry value DE_PREFS_TABSIZE which allows you to set a value for the tabsize.
-
SCCM central site and primary site use the same SQL SERVER with two Instance.
Hi Guys,
I want deploy SCCM 2012 central site and primary site in my domain. But Only one Sql server for me. Any one can tell me how to install the central site server and primary site server with the same SQL SERVER with two instance.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Sean Xiao
TechNet Community SupportAlthough you can install like the configuration you said above, we do not recommend you do it this way. If your SQL box has problems, all the data will go away and you will not have data redundancy.
You need to configure the different SQL Port and SQL Broke service port e.g.
SQL port 4023 SQL Broke Service port 4022 for CAS instance
SQL port 4024 SQL Broke Service port 4021 for PRI instance
Juke Chou
TechNet Community Support
I agree with Johan and this configuration should not be used. But I want to clarify that the default ports for "SQL port" (actually, SQL over TCP) is 1433 and the SQL Broker Service uses 4022. The configuration above should work but the "correct" would be
to use 1433 and 4022 for the CAS and 10434 and 4023 for the Primary :)
You can read more about Network Ports used by Configuration Manager here
http://technet.microsoft.com/en-us/library/hh427328.aspx#BKMK_CommunicationPorts
/Tim
Tim Nilimaa | Blog: http://infoworks.tv | Twitter: @timnilimaa -
Creating a PL/SQL-Block with Boolean-Return and Check
Hello folks,
I have some kind of tricky problem. Actually, I want to integrate a small Task-System on my Apex 2.2 installation. Every task is intended to have a field with a anonymous PL/SQL-block in the shape of:
Declare
Begin
return true/false;
End;
It is comparable to the condition-PL/SQL-block you can set for almost ev'ry item.
It's not the problem to write this block half-automated, but how do I check it? Is there any kind of Database-Function?
Thanks for your replies.
Matthias.I believe Struct is basically used for SQL types , and your 'T_NACHRICHT' is a type of Objects so please pass the objects array to STRUCT.
For example if type is :
CREATE OR REPLACE TYPE T_NACHRICHT AS OBJECT
ID_Nachricht NUMBER,
ID_Vorgang NUMBER,
--datum TIMESTAMP(6),
Betreff VARCHAR2(400),
-- Nachricht CLOB,
ID_Antwort NUMBER,
ist_neu VARCHAR2(5),
CONSTRUCTOR FUNCTION T_NACHRICHT(
p_ID_Vorgang NUMBER,
p_Betreff VARCHAR2) RETURN SELF AS RESULT
then call the struct in below way:
STRUCT nachrichtSTRUCT = null;
StructDescriptor structDesc = StructDescriptor.createDescriptor("T_NACHRICHT", conn);
Object [] obj = {123456,123456,"ABC",123456,"ABCD"};
nachrichtSTRUCT = new STRUCT(structDesc, conn, obj); -
Execute PL/SQL block with named binds from within java code?
Hi guys,
Is there any good way to execute my PL/SQL code, for example
BEGIN :x := :x+1; END;
from my Java code? I need nothing complicated, just static code block with named binds.
I have tried the Oracle exetnded JDBC (setXXXbyName methods):
public static void main(String[] args){ try { Class.forName("oracle.jdbc.driver.OracleConnection"); Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","user","password"); String SQL="begin :x:=:x+1; end;"; OracleCallableStatement stmt; stmt=(OracleCallableStatement)conn.prepareCall(SQL); stmt.setIntAtName("x", 5); stmt.registerOutParameter("x", Types.INTEGER); stmt.execute(); System.out.println(stmt.getInt("x")); } catch (Exception x) { x.printStackTrace(); } }
And get the java.sql.SQLException: operation not allowed: Ordinal binding and Named binding cannot be combined!
Then i've tried SQLJ appoach:
public static void main(String[] args){ try { Class.forName("oracle.jdbc.driver.OracleConnection"); Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","user","password"); Oracle.connect(conn); System.out.println("Connected!"); int x=3; #sql { BEGIN :x := :x+1; END; }; System.out.println("x=" + x); } catch (Exception x) { x.printStackTrace(); } }
And x=3 had retuned... Although 4 expected.
Then, I've set parameter sqlj.bind-by-identifier=true
And result is another exception! java.sql.SQLException: Missing IN or OUT parameter at index:: 2
Can you please mark my mistakes/point to correct solution?
Thanks in advance,
AlexeyFound another solution, this time working at least...
public void testPLSQL() {
String dynamicSQL=
"declare\n" +
" v_CursorID INTEGER;\n" +
" v_BlockStr VARCHAR2(500);\n" +
" v_Dummy INTEGER;\n" +
" v_x String(18);\n" +
"BEGIN\n" +
" v_CursorID := DBMS_SQL.OPEN_CURSOR;\n" +
" v_BlockStr :=?;" +
" DBMS_SQL.PARSE(v_CursorID, v_BlockStr, DBMS_SQL.V7);\n" +
" v_x:=?;"+
" DBMS_SQL.BIND_VARIABLE(v_CursorID, ':x', v_x,18);\n" +
" v_Dummy := DBMS_SQL.EXECUTE(v_CursorID);\n" +
" DBMS_SQL.VARIABLE_VALUE(v_CursorID, ':x', v_x);\n" +
" DBMS_SQL.CLOSE_CURSOR(v_CursorID);\n" +
" ?:=v_x;"+
" COMMIT;\n" +
"EXCEPTION\n" +
" WHEN OTHERS THEN\n" +
" DBMS_SQL.CLOSE_CURSOR(v_CursorID);\n" +
" RAISE;\n" +
"END DynamicPLSQL;";
try {
Class.forName("oracle.jdbc.driver.OracleConnection");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","user", "password");
System.out.println("Profit");
String SQL="begin :x:=:x+1; end;";
OracleCallableStatement stmt;
stmt=(OracleCallableStatement)conn.prepareCall(dynamicSQL);
stmt.setString(1, SQL);
int x=3;
stmt.setInt(2, x);
stmt.registerOutParameter(3, Types.INTEGER);
stmt.execute();
x=stmt.getInt(3);
System.out.println(x);
assertEquals(4, x);
} catch (Exception ex) {
ex.printStackTrace();
assertTrue(false);
}Now the only thing I need is to code some kind of preprocessor of SQL block, to prepare the dynamicSQL lair for SQL critter...
Please please please show me something less complicated! :8} -
How to tune the following sql statements which has two unions in oracle 10g
It takes a long time to run the following sql statement in 10g. Each select brings back about 4 million rows and there will be about 12 million rows. When I run each select statements seprately in sqlplus I can see the data immedaitely but when I run it as whole with two unions in the select it just takes very very long time? I want to know how to make this run faster? Can we add hints? or is it because of any table space? Any help is appreciated.
select
D.EMPLID
,D.COMPANY
,'CY'
,D.CALENDAR_YEAR
,D.QTRCD
,D.ERNCD
,D.MONTHCD
,D.MONTHCD
,D.GRS_MTD
,D.GRS_QTD
,D.GRS_YTD
,D.HRS_MTD
,D.HRS_QTD
,D.HRS_YTD
from PS_EARNINGS_BAL D
where D.SPCL_BALANCE = 'N'
union
select
D.EMPLID
,D.COMPANY
,'FY'
,(case when D.MONTHCD > '06' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
,ltrim(to_char(to_number(D.QTRCD) + decode(sign(3-to_number(D.QTRCD)),1,2,-2),'9'))
,D.ERNCD
,ltrim(to_char(to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6),'09'))
,D.MONTHCD
,D.GRS_MTD
,D.GRS_QTD
,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
F.EMPLID = D.EMPLID and
F.COMPANY = D.COMPANY and
F.ERNCD = D.ERNCD and
F.SPCL_BALANCE = D.SPCL_BALANCE and
(case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
= (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
<= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
,D.HRS_MTD
,D.HRS_QTD
,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
F.EMPLID = D.EMPLID and
F.COMPANY = D.COMPANY and
F.ERNCD = D.ERNCD and
F.SPCL_BALANCE = D.SPCL_BALANCE and
(case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
= (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
<= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
from PS_EARNINGS_BAL D
where D.SPCL_BALANCE = 'N'
union
select
D.EMPLID
,D.COMPANY
,'FF'
,(case when D.MONTHCD > '09' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
,ltrim(to_char(to_number(D.QTRCD)+decode(sign(4-to_number(D.QTRCD)),1,1,-3),'9'))
,D.ERNCD
,ltrim(to_char(to_number(D.MONTHCD)+decode(sign(10-to_number(D.MONTHCD)),1,3,-9),'09'))
,D.MONTHCD
,D.GRS_MTD
,D.GRS_QTD
,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
F.EMPLID = D.EMPLID and
F.COMPANY = D.COMPANY and
F.ERNCD = D.ERNCD and
F.SPCL_BALANCE = D.SPCL_BALANCE and
(case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
= (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
<= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
,D.HRS_MTD
,D.HRS_QTD
,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
F.EMPLID = D.EMPLID and
F.COMPANY = D.COMPANY and
F.ERNCD = D.ERNCD and
F.SPCL_BALANCE = D.SPCL_BALANCE and
(case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
= (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
<= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
from PS_EARNINGS_BAL D
where D.SPCL_BALANCE = 'N'
Edited by: user5846372 on Mar 11, 2009 8:55 AMHi,
What i observed is that your table name and where clause is same in all the thress SELECTs whereas columns having some manipulations that is not going to be unique. I guess you can easily replace UNION with UNION ALL.
from PS_EARNINGS_BAL D
where D.SPCL_BALANCE = 'N'Note: I am not aware of your data and business requirement. Please test the result before removing. It is just a suggetion
Cheers,
Avinash -
ORA-06550 - while compiling the PL/SQL block.
I am trying a to populate a table based on the below pl/sql block
Declare
temp source.source%type;
tregion varchar2(40);
tversion varchar2(40);
tsource varchar2(100);
Cursor c1 is
Select * from Source;
Begin
Open c1;
Loop
fetch c1 into temp;
select REGION, VERSION, SOURCE into tregion, tversion, tsource from QUOTE_LETTERS_MASTER where SOURCE = temp AND REGION = 'eSource';
insert into esource values(tregion, tversion, tsource);
Exception
when no_data_found then
insert into esource values('No eSource',' ',temp.source);
exit when c1%notfound;
End Loop;
close c1;
end;yes, there are more than one rows that is returned when i do a Select Into statement.
I am trying to resolve by using a cursor C2 inside the already existing cursor C1, i will use a inner loop to get the select statement value to cursor c2 then i will assign the vlaues the variables, then once i read all the values of cursor c2 i will exit inner loop and go to outer loop to read the next value of c1 and then again go to cursor c2 and inner loop.
Do you think it will work ?
Thank you,
rakesh
I have pasted the code below.
Declare
temp1 source.source%type;
temp2 QUOTE_LETTERS_MASTER%rowtype;
Cursor c1 is
Select * from Source;
Begin
open c1;
loop
fetch c1 into temp;
cursor c2 is
select region, version, source from QUOTE_LETTERS_MASTER where SOURCE = temp AND REGION = 'eSource';
open c2;
loop
begin
fetch c2 into temp2;
insert into esource values(temp2.region, temp2.version, temp2.source);
Exception
when no_data_found then
insert into esource values('No esource',' ',temp);
exit when c2%notfound;
end loop;
close c2;
exit when c1%notfound;
end loop;
close c1;
end;
But is giving this error : - ORA-06550: line 10, column 13:
***PLS-00103: Encountered the symbol "C2" when expecting one of the following:
***:= . ( @ % ;
***1. Declare***
***2. temp1 source.source%type;
***3. temp2 QUOTE_LETTERS_MASTER%rowtype;
Edited by: rakesh119 on Apr 10, 2013 11:08 AM -
Calling a SQL script from the PL/SQL block.
Hello All,
I am using oracle 11g database.
My requirment is as follows. I have a SQL script to alter the table. But before alter the table I need to test some condition , if the condition satisfy then I have to alter the table through the SQL script. For the checking the condition I have to use the plsql block and inside I need to call the SQL script.
Can I call a SQL script from PL/SQL block, if yes then how?
I am tring to use START, RUN and @ command but it is throughing error.
Thanks
SUN[PL/SQL manual|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/functions55a.htm#77600] Ctrl-F start, finds nothing. [SQLPlus manual|http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/toc.htm] Ctrl-F start finds this. Isn't it wonderful that Oracle documents this stuff so we don't have to guess.
Can I call a SQL script from PL/SQL block, if yes then how? No.
You could call the stored procedure in a SQL*Plus script before the alter table and have it raise an exception if the condition is not met and have the script quit when there is an error. -
How join the two query block with same field
sorry sir i am posting dublicate thread
i thought you not understand my question
sir i have two query block in report with same field
i try the link object but that creat now block not creat link withen query block
please give me idea
thankDear,
Use data link object.
Click at data link object then click on the fild in query block1 and drag it into the other query block data link will be created.
try it -
Where the PL/SQL blocks is stored
Hello,
Is there any table like where the last
complied PL/SQL block is stored in a database.
Thanks and regards
shawlinI'm not sure exactly what you are asking. If you are looking for the source code (USER_SOURCE, ALL_SOURCE, DBA_SOURCE). If you are looking for the last compile date/time (USER_OBJECTS, ALL_OBJECTS, DBA_OBJECTS).
Maybe you are looking for
-
after upgrading to mountain lion, i cannot play any video at all, be it directly off a DVD, or through streaming like youtube, BBC iplayer, love film or even directly off my iTunes library. in each case, all i get is a black screen and no error messa
-
How do I create an Icon so to run my java program..
I have a program with many different classes, thing is, I now want it as an executable file, meaning I click on one icon to run the whole program and its associated classes, I am not sure if this is where the topic should be posted but would apprecia
-
Store Word Document Text in Database using form
Hai, i have one word format document .doc, my object is i want to store text from word file line by line in oracle database using form. it there anyway to achieve my object. thanx, can i create form to read word file with sound..
-
Airport Express Transmits To Airport Extreme Base Station Intermittently
I have an Airport Extreme set up as my base station wirelessly. I also have an Airport Express set up to extend the range of my network. The reason I have the air port express is that the walls of my house are very thick, so I thought that if I have
-
Hi, I want to display a message on the status bar along with the output . That is output and message should appear on the same screen together. Neither before the output nor after the the output. Best Regards,