SQL SP Suggestion
I have a SP that runs everynight to Insert and Update the content of a table based on an excel file (Excel 2010 on
Windows Server 20008 R2). Below is my SP and the image represents my table's structure and the excel file format. I just need to double check my SP with you guys to make sure I am doing this correctly and if I am on the right track. The excel file includes
3 columns both Cust_Num and Cust_Seq are primary since there would never be a case that same combination of Cust_Num and Cust_Seq exist for a customer name. For example, for Cust_Num = 1 and Cust_Num=0 there will never be another of same combination of Cust_Num
being 1 and Cust_Num being 0. However the name will usually repeat in the spreadsheet. So, would you guys please let me know if the SP is correct or not? (in the SP first the Insert statement runs and then the Update Statement):
First The Insert runs in the SP
INSERT INTO Database.dbo.Routing_CustAddress
SELECT a.[Cust Num],a.[Cust Seq],a.[Name]
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;HDR=YES;Database=C:\Data\custaddr.xls;',
'SELECT*
FROM [List_Frame_1$]') a Left join Routing_CustAddress b
on a.[Cust Num] = b.Cust_Num and a.[Cust Seq] = b.Cust_Seq where b.Cust_Num is null
***Then the Update Runs in the SP
UPDATE SPCustAddress
SET SPCustAddress.Name = CustAddress.Name
FROM ArPd_App.dbo.Routing_CustAddress SPCustAddress
INNER JOIN OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;HDR=YES;Database=C:\Data\custaddr.xls;',
'SELECT *
FROM [List_Frame_1$]')CustAddress
ON SPCustAddress.Cust_Num = CustAddress.[Cust Num]
AND SPCustAddress.Cust_Seq = CustAddress.[Cust Seq]
I have a SP that runs everynight to Insert and Update the content of a table based on an excel file (Excel 2010 on Windows Server
20008 R2). Below is my SP and the image represents my table's structure and the excel file format. I just need to double check my SP with you guys to make sure I am doing this correctly and if I am on the right track. The excel file includes 3 columns both
Cust_Num and Cust_Seq are primary since there would never be a case that same combination of Cust_Num and Cust_Seq exist for a customer name. For example, for Cust_Num = 1 and Cust_Num=0 there will never be another of same combination of Cust_Num being 1 and
Cust_Num being 0. However the name will usually repeat in the spreadsheet. So, would you guys please let me know if the SP is correct or not? (in the SP first the Insert statement runs and then the Update Statement):
**First The Insert runs in the SP
INSERT INTO Database.dbo.Routing_CustAddress
SELECT a.[Cust Num],a.[Cust Seq],a.[Name]
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;HDR=YES;Database=C:\Data\custaddr.xls;',
'SELECT*
FROM [List_Frame_1$]') a Left join Routing_CustAddress b
on a.[Cust Num] = b.Cust_Num and a.[Cust Seq] = b.Cust_Seq where b.Cust_Num is null
***Then the Update Runs in the SP
UPDATE SPCustAddress
SET SPCustAddress.Name = CustAddress.Name
FROM ArPd_App.dbo.Routing_CustAddress SPCustAddress
INNER JOIN OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;HDR=YES;Database=C:\Data\custaddr.xls;',
'SELECT *
FROM [List_Frame_1$]')CustAddress
ON SPCustAddress.Cust_Num = CustAddress.[Cust Num]
AND SPCustAddress.Cust_Seq = CustAddress.[Cust Seq]
Looks fine based on your explanation
You may use merge to do both operation in single step
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Similar Messages
-
SQL tuning suggestions.
Hi
I am not a sql programmer and developers have given me this sql to have a look. I made the following recommendations after going through the sql. Is there anything else that can be added . I did not add about stats because they are representative and up to date.
SELECT /*+ PARALLEL(q1,4) */ *
FROM
(SELECT /*+ FIRST_ROWS(20) */
br.resource_id,
br.resource_code,
x.resource_seq_num employee_resource_number,
br.organization_id,
bd.department_id,
bd.department_code,
pf.full_name employee_name,
(SELECT xxdl_eam_util_pkg.xxdl_eam_get_resource_code(pf.person_id, bd.department_id)
FROM dual)
maximum_cost_resource,
pf.person_id,
x.wip_entity_id wo_id,
(SELECT weo1.wip_entity_name
FROM wip_eam_work_orders_v weo1
WHERE weo1.wip_entity_id = x.wip_entity_id)
wo_number,
CAST(x.start_date AS
TIMESTAMP) start_date,
CAST(x.completion_date AS
TIMESTAMP) completion_date,
wor.operation_seq_num wo_operation_number,
wor.resource_seq_num wo_resource_number,
wor.usage_rate_or_amount HOURS,
BRE.effective_start_date instance_start_date,
BRE.effective_end_date instance_end_date,
BRE.instance_id,
crc.resource_rate AS
resource_cost,
(SELECT xxdl_eam_util_pkg.xxdl_eam_get_all_res_code(pf.person_id, bd.department_id)
FROM dual)
all_resources
FROM per_all_people_f pf,
wip_eam_work_orders_v weo,
wip_operations wo,
wip_operation_resources wor,
(SELECT instance_id,
wip_entity_id,
operation_seq_num,
resource_seq_num,
start_date,
completion_date
FROM wip_op_resource_instances_v) x,
bom_dept_res_instances bdri,
bom_resource_employees BRE,
bom_department_resources bdr,
bom_resources br,
cst_resource_costs crc,
bom_departments bd
WHERE br.organization_id = bd.organization_id
AND bdr.resource_id = br.resource_id
AND bdr.department_id = bd.department_id
AND BRE.resource_id = br.resource_id
AND pf.effective_start_date <=sysdate
AND pf.effective_end_date >= sysdate
AND pf.person_id = BRE.person_id
AND wo.department_id = bd.department_id
AND wor.operation_seq_num(+) = wo.operation_seq_num
AND wor.wip_entity_id(+) = wo.wip_entity_id
AND wor.organization_id(+) = wo.organization_id
AND weo.wip_entity_id = wo.wip_entity_id
AND weo.organization_id = wo.organization_id
-- AND weo.organization_id = 6921
AND DECODE(bd.disable_date,null, sysdate,bd.disable_date) >= sysdate
AND DECODE(br.disable_date,null, sysdate,br.disable_date) >= sysdate
AND DECODE(wo.disable_date,null, sysdate,wo.disable_date) >= sysdate
AND crc.resource_id(+) = BRE.resource_id
AND x.wip_entity_id = wor.wip_entity_id
AND x.operation_seq_num = wor.operation_seq_num
AND x.resource_seq_num = wor.resource_seq_num
AND x.instance_id(+) = BRE.instance_id
AND bdri.department_id = bd.department_id
AND bdri.resource_id = br.resource_id
AND weo.organization_id = 6921
AND bdri.department_id = 5004
UNION
SELECT /*+ FIRST_ROWS(20) */ DISTINCT NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
pf.full_name employee_name,
NULL,
pf.person_id,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL HOURS,
NULL,
NULL,
NULL,
NULL,
NULL
FROM per_all_people_f pf,
wip_eam_work_orders_v weo,
wip_operations wo,
wip_operation_resources wor,
bom_dept_res_instances bdri,
bom_resource_employees BRE,
bom_department_resources bdr,
bom_resources br,
cst_resource_costs crc,
bom_departments bd
WHERE br.organization_id = bd.organization_id
AND bdr.resource_id = br.resource_id
AND bdr.department_id = bd.department_id
AND BRE.resource_id = br.resource_id
AND pf.effective_start_date <=sysdate
AND pf.effective_end_date >= sysdate
AND pf.person_id = BRE.person_id
AND wo.department_id = bd.department_id
AND wor.operation_seq_num(+) = wo.operation_seq_num
AND wor.wip_entity_id(+) = wo.wip_entity_id
AND wor.organization_id(+) = wo.organization_id
AND weo.wip_entity_id = wo.wip_entity_id
AND weo.organization_id = wo.organization_id
AND DECODE(bd.disable_date,null, sysdate,bd.disable_date) >= sysdate
AND DECODE(br.disable_date,null, sysdate,br.disable_date) >= sysdate
AND DECODE(wo.disable_date,null, sysdate,wo.disable_date) >= sysdate
AND crc.resource_id(+) = BRE.resource_id
AND bdri.department_id = bd.department_id
AND bdri.resource_id = br.resource_id
AND weo.organization_id = 6921
AND bdri.department_id = 5004
AND NOT EXISTS
(SELECT instance_id,
wip_entity_id operation_seq_num,
resource_seq_num
FROM wip_op_resource_instances_v)
) q1
ORDER BY department_id,
resource_code,
employee_name,
wo_number
My suggestions:
. Try to use UNION ALL instead of UNION. If you can eliminate UNION all together and flatten the query that will be even better.
2. You are using the function in a select statement xxdl_eam_util_pkg.xxdl_eam_get_resource_code(pf.person_id, bd.department_id)This will slow the performance. Try to get rid of this. Function calls in select are expensive.
3. Dont use the parallel hint and optimize. It wont get you consistent results.
4. Use of per_all_people_F is expensive. The UNION again complicates things. per_all_people_f has to be scanned 2x times.
5. Where does the application get the values for department id? Whether user inputs a value or whether it is hard coded . Most likely user will input value and each time it may be different. If that is the case, then you may be hitting bind peeking. There is not much hope for this. Not much can be done. Whatever you do this can happen. Only way is to pin the plan if you can use literals instead of binds. But that is not possible I think.
6. AND DECODE(bd.disable_date,null, sysdate,bd.disable_date) >= sysdate
AND DECODE(br.disable_date,null, sysdate,br.disable_date) >= sysdate
AND DECODE(wo.disable_date,null, sysdate,wo.disable_date) >= sysdate
Those statements, if you can rewrite would be good. If there are indexes on any of those columns, they are more than likely not used.
7. Are the outer joins really required. If not required remove them.
8. There is a 'WITH' clause in 10g . Try to use that for your subqueries or main query where applicable. It will save some I/O.
9. Try to tune without any hints. Remove the first rows as well and see the difference.
I know that the sql is definately bad and can be rewritten but I am not able to exactly write it for them.
Any inputs or thoughts?
MSKHi,
Any suggestions for reading on Sql tuning
I am looking for a practical book with solutions .
And books showing the Sql internal workings ?Take a look on Amazon some Jonathan Lewis books.
I will also recommend you to take a look on the following blogs:
- http://jonathanlewis.wordpress.com/
- http://www.juliandyke.com/
- http://richardfoote.wordpress.com/
- http://tkyte.blogspot.com/
And also any good interview based good Oracle DBA books ?You can take a look on my blog for some common DBA interview questions.
http://oraclenz.com/category/interview-tips/
Regards,
Francisco Munoz Alvarez
www.oraclenz.com -
Any tool or shortcut to get SQL tuning suggestion???????
Hi I have to tune an application and need to go throught alot many SQL their PLAN and ti tune them.
I want to know ether is there any tool online or may be from oracle to get the tuning suggestions straighytway.my oracle version is 9206
Can i use 10g SQL tuning advisor with 9i database????
Thanks
GaganHi Gagan,
Can i use 10g SQL tuning advisor with 9i databaseNo, but you can do the same thing manually, and often do a better job:
Tune SQL with optimizer parms:
http://www.dba-oracle.com/t_sql_optimizer_parameters.htm
Find missing indexes:
1 - Search for unnecessary large-table, full-table scans
2 - Compare consistent gets to rows returned
http://www.dba-oracle.com/art_sql_tune.htm
Hope this helps. . . .
Donald K. Burleson
Oracle Press author -
LOAD DATA
INFILE /home/dir1
BADFILE abc.bad
truncate
into table tab1
fields terminated by ','
optionally enclosed by '"'
col1,
col2,
col3,
col4
here my table tab1 structure
col1 number
col2 number
col3 Varchar
col4 varchar
when i load the record like
1,1,1,2 it is also getting loaded.
but i need to load records like 1,1,a,b
what i feel.
is the control file is wrong somewhere so that it is taking the numeric datatype to character columns of the tab1 table.
can i make something in the control file so that it will accept data like (1,1,a,b) and not the (1,1,1,2) one
thanksWhat do you want it to do when it comes across a row of data in the file that is e.g.
1,1,1,2
At the moment it is assuming that the last two are character datatype and as such creating them quite correctly in your table.
Perhaps you want to be selective about your data. See this link...
http://www.orafaq.com/wiki/SQL*Loader_FAQ#Can_one_selectively_load_only_the_records_that_one_need.3F -
Need help in a SQL quick suggestion will highly appreciated
Hi
I need to dynamically generate the following query
ALTER TABLE AAA.TAB1 ADD SUPPLEMENTAL LOG GROUP t_l_g (COL1,COL2,COL3) ALWAYS;
I have like 30 tables in 100 clients and I need to generate this query for all the columns that are in a unique index within a list of tables and with in a list of users. the issue that i am facing is that the columns are comming in rows. Any help will be highly appreciated.You did not post your query so here is a general approach:
Write the query that returns the columns and pivot it to give you a concatenated list then add in the rest of the statement which is a constant except for the table_name which could come from a query.
There have been numerous posts in the past on pivoting rows into columns. You should be able to find some via a search of the archives. Version 11g even comes with a new command to pivot data.
HTH -- Mark D Powell -- -
Error while executing Multiple Stored Procedure through .sql file
Hi Guru's.
I am new to ORACLE. I am facing problem while creating Stored Procedure through .sql file.
I have one test.sql file with Stored Procedure is like,
CREATE OR REPLACE PROCEDURE skeleton1
AS
BEGIN
DBMS_Output.Put_Line('skeleton1');
END skeleton1;
CREATE OR REPLACE PROCEDURE skeleton2
AS
BEGIN
DBMS_Output.Put_Line('skeleton2');
END skeleton2;
Now when i try to execute this test.sql file through SQL PLUS it gives me Error like this
I am opening test.sql file from SQL PLUS,
SQL>
1 CREATE OR REPLACE PROCEDURE skeleton1
2 AS
3 BEGIN
4 DBMS_Output.Put_Line('skeleton1');
5 END skeleton1;
6 /
7 CREATE OR REPLACE PROCEDURE skeleton2
8 AS
9 BEGIN
10 DBMS_Output.Put_Line('skeleton2');
11* END skeleton2;
SQL> /
Warning: Procedure created with compilation errors.
SQL> show errors;
Errors for PROCEDURE SKELETON1:
LINE/COL ERROR
6/1 PLS-00103: Encountered the symbol "/"
SQL>
Please suggest how to create multiple CREATE PROCEDURE using single .sql script file....
Regards,
ShatrughanHi,
Try this
CREATE OR REPLACE PROCEDURE skeleton1
AS
BEGIN
DBMS_Output.Put_Line('skeleton1');
END ;
CREATE OR REPLACE PROCEDURE skeleton2
AS
BEGIN
DBMS_Output.Put_Line('skeleton2');
END;
/Save the file and call it.
Regards,
Bhushan -
Error while executing one pl/sql
i am facing one error while executing a pls/sql
kindly suggest the possible cause and solution for the same
declare
ERROR at line 1:
ORA-08102: index key not found, obj# 31850, dba 104863849 (2)
ORA-06512: at "ERP.DELBATCHID", line 24
ORA-06512: at line 1308102, 00000, "index key not found, obj# %s, dba %s (%s)"
// *Cause: Internal error: possible inconsistency in index
// *Action: <b>Send trace file to your customer support representative, along
// with information on reproducing the error</b> -
Calling a procedure in PLL from PL/SQL
Can I call a procedure in PLL (for Forms) from a PL/SQL (not in Forms) procedure?
If yes, can anybody tell me how?
Hyunsu KimThis is not Forms but I'll try an answer.
No.
The PLL is a client-side library. Even when the Forms application is deployed web-wise it is unlikely that it will be on the same server as the database, so database PL/SQL won't be able to execute it. Furthermore, a PLL routine is likely to contain Forms calls, which cannot be executed by the database. If you have a PLL routine that consists of nothing but database PL/SQL I suggest you move all the code into a database procedure and turn the PLL procedure into a wrapper.
Cheers, APC -
Making sql faster not in pl.sql but in sql
this sql takes a long time running from Application to oracle database
11.2.0.3.0 on win 2008 r2
in Toad it runs much faster
any suggestions to make it faster in SQL, this is dynamic code where 1500000 is bind variable passed from application side. this can be 10million 20million ...etc
there are enough indexes, constraints on the related tables below. thought of using /*+APPEND*/
cant use BULK COLLECT as its part of PL/SQL
any suggestions
INSERT INTO pds.dlg_participant
(dp_id, dp_dg_id, dp_dlg_id, dp_customer_id, dp_context, dp_inserted_timestamp, dp_moved_timestamp, dp_active, dp_internal_id)
(SELECT
pds.DLG_PARTICIPANT_SEQ.NEXTVAL,
1224,
1074,
mh_customer_id,
mh_context,
SYSDATE,
SYSDATE,
0,
7820
FROM
SELECT
Relations.MARE_ID as mh_customer_id,
'0' as mh_context,
null as mh_participant_id
FROM
(select *
from Testuser.RelationsEnriched_10M
) Relations
WHERE
((1500000 >= Relations.MARE_ID)))
AND
NOT EXISTS (SELECT
dp_id
FROM
pds.dlg_participant,
pds.dlg_group
WHERE
(dp_dg_id = dg_id) AND
(dg_dlg_id = 1074) AND
(dp_active = 0) AND
(dp_customer_id = Relations.MARE_ID)) ) mh_container
)912919 wrote:
this sql takes a long time running from Application to oracle database
11.2.0.3.0 on win 2008 r2
in Toad it runs much fasterYou did not post timings of the execution. So, how can we see or you prove that it actually runs faster in Toad than on SQL Prompt.
I will suggest you to do the following and post the details here:
@SQL Prompt
ALTER session SET TIMED_STATISTICS = TRUE;
Execute your Insert Statement;
@Toad
ALTER session SET TIMED_STATISTICS = TRUE;
Execute your Insert Statement;Post the timing details here. Also it will be highly appreciable if you can post the Explain plan or the TKPROF output.
Just in case you are not aware of getting TKPROF, read here.
any suggestions to make it faster in SQL, this is dynamic code where 1500000 is bind variable passed from application side. this can be 10million 20million ...etc
there are enough indexes, constraints on the related tables below. thought of using /*+APPEND*/
cant use BULK COLLECT as its part of PL/SQL
any suggestionsIn order to speed us the Insert Select Operations, the key for improvement in performance lies, mostly, in the Select statement. So, if you can optimize the select statment you would have achieved most of the job.
If this is a One time or A Data Load performed during an Outage or Low activity period, you can alter the table to NOLOGGING and perform INSERT APPEND and then alter table back to LOGGING. -
Hi,
I am trying to understand how to access an SQL database from CVI.
I don't understand how the sample programs shipped with the toolkit can access the database they use if it is not listed in the ODBC Data Source Administrator.
In the code, I see the line:
hdbc = DBConnect ("DSN=CVI SQL Samples");
However, there is not an entry that I can find in the ODBC Administrator for "CVI SQL Samples."
The SQL help suggests there should be a User DSN named, "CVI32_Samples", but I don't see that entry in the ODBC Administrator on my win-7 system.
I believe the sample program is accessing a database file named, "C:\Users\Public\Documents\National Instruments\CVI\Samples\sql\samples.mdb".
Exactly how is the call to DBConnect() translated to the file, "samples.MDB", if there is no entry in the ODBC Administrator?
Regards,
MarkI figured it out. There is a 32 bit ODBC administrator and a 64 bit ODBC administrator. The ODBC administrator I run through the control panel is the 64 bit ODBC administrator. To access the 32 bit administrator I need to run, "C:\Windows\SysWOW64\odbcad32.exe".
I am running the samples in 32 bit mode, so I need to use the 32 bit ODBC administrator.
Best,
Mark -
SQL Server Web Edition for SharePoint 2013
Dear Expert,
I'm not sure SQL Server Web Edition is ok for SharePoint Server 2013 or not. If I do in On-Premise or Azure.
Please suggestion.There is no specific document that specifies that Web edition is supported. However, if you look at the requirements list for SharePoint 2013 you will notice that it specifies that it must be either SQL server 2008 r2 with SP1 or SQL 2012.
It also specifies the 64 bit version. But it doesn't specify a specific edition. That and the fact that it will run on SQL Express suggests that it will run on any edition of SQL as long as its 64 bit and a late enough release.
Paul Stork SharePoint Server MVP
Principal Architect: Blue Chip Consulting Group
Blog: http://dontpapanic.com/blog
Twitter: Follow @pstork
Please remember to mark your question as "answered" if this solves your problem. -
Creating a table within a PL/SQL procedure
I recieve the following error:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
The create statement is within the executable part of an if statement. Are we allowed to have CREATE statements within if statements?"Are we allowed to have CREATE statements within if statements? "
Its nothing to do with IF, it applies throughout pl/sql to any DDL (data definition language).
When the procedure is compiled, oracle checks that all of your DML (data definition language) complies with your database structure. If you mess about with the structure within the procedure, this confuses the whole issue. You can do it with native dynamic sql as suggested by Ino, but will need to use execute immediate wherever you attempt to use your new table, otherwise it will not compile. -
Batch Processing SQL -- UA error results
Error:
UA service error (Transaction cannot include batched SQL (semicolon delimited) statements.)
SQL:
INSERT INTO TEMP_HECM_REFI_TBL select * from F17RDMS.HECM_REFI_TBL where borrower_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5);
INSERT INTO TEMP_HECM_REFI_TBL select * from F17RDMS.HECM_REFI_TBL where coborrower1_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5) AND CASE_NO NOT IN (SELECT CASE_NO FROM TEMP_HECM_REFI_TBL);
INSERT INTO TEMP_HECM_REFI_TBL select * from F17RDMS.HECM_REFI_TBL where coborrower2_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5) AND CASE_NO NOT IN (SELECT CASE_NO FROM TEMP_HECM_REFI_TBL);
INSERT INTO TEMP_HECM_REFI_TBL select * from F17RDMS.HECM_REFI_TBL where coborrower3_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5) AND CASE_NO NOT IN (SELECT CASE_NO FROM TEMP_HECM_REFI_TBL);
INSERT INTO TEMP_HECM_REFI_TBL select * from F17RDMS.HECM_REFI_TBL where coborrower4_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5) AND CASE_NO NOT IN (SELECT CASE_NO FROM TEMP_HECM_REFI_TBL);
SELECT * FROM TEMP_HECM_REFI_TBL;
I originally had a simple select:
select * from hecm_refi_tbl
where
borrower_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5) or
coborrower1_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5) or
coborrower2_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5) or
coborrower3_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5) or
coborrower4_ssn in (#ssn1,#ssn2,#ssn3,#ssn4,#ssn5)
That worked but it was a table scan... took about 30 seconds to return.
I tried a union next but that turned out to be a bust also as the RDMS we use doesn't return column names on unions (I know, right?... sheesh!)
The batch uses a temp table and works real well in a query tool, not so much when I use it in a DB adapter.
I'm thinking I may have to write a view and have the DBA install it but, before I do that I thought I would see if there is a way to quickly fix this (or if someone wit a better grasp on SQL can suggest a better single query.)
Thanks y'allYeah... me too but the DBA doesn't want to. I managed to gt the union working.
-
I understand that you must run catalog.sql after creating a new database so that data dictionaries are updated otherwise the Oracle Enterprise Manager (OEM) will not be able to view details of the new database.
So ... I've run catalog.sql but it hangs immediately. While it's hung, I cannot log into SQL*Plus from another session -- that hangs too. A little ivestigation into what catalog.sql does suggests that it is the standard.sql script (run by @@standard) that is hanging and looking into that suggests that stdspec.sql is hanging.
Any tips on how to determine the cause of the underlying hang? Note that I can log into my database and run SQL queries without any problems; I simply can't use OEM to administer it (which is why I'm running catalog.sql).
Thanks.Thanks Joel. I ran that script but it failed with:
2 (u.ebytes/a.fbytes)*100 USEDPCT
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
So I changed it slightly to this:
SQL> select u.tblspc "TBLSPC", a.fbytes "ALLOC", u.ebytes USED, a.fbytes-u.ebytes UNUSED
2 from (select tablespace_name tblspc, sum(bytes) ebytes
from sys.dba_extents
3 4 group by tablespace_name) u,
5 (select tablespace_name tblspc, sum(bytes) fbytes
6 from sys.dba_data_files
7 group by tablespace_name) a
8 where u.tblspc = a.tblspc
9 ;
and that fails (when run as sysdba or as system, both of whom I assume have privileges to select catalog) with:
from sys.dba_data_files
ERROR at line 6:
ORA-00942: table or view does not exist
I can't help but feel that something may have gone badly wrong with this Oracle installation.
Would it be a sensible option to drop all databases (by manually removing all their files) and then try to run catalog.sql on an (allegedly) empty system? -
Awr show this sql as highest cpu consuming sql .Is this sql need tunning?
Hi,
As awr reports showing this sql as the highest CPU consumer
Please consider me newbie and help me to understand this.
Thanking you ..
SQL ordered by CPU Time DB/Inst: Snaps:
-> Resources reported for PL/SQL code includes the resources used by all SQL
statements called by the code.
-> % Total DB Time is the Elapsed Time of the SQL statement divided
into the Total Database Time multiplied by 100
CPU Elapsed CPU per % Total
Time (s) Time (s) Executions Exec (s) DB Time SQL Id
2,658 2,665 1 2658.18 5.7 5aawbyzqjk8by
select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, ta
s_site ts where trp.tsa_id = tti.tsa_id and tti.status = 1 and ts.site_id = trp
.site_id and (tti.max_install != trp.pushed_rsn and ((tti.max_install = 0 and
(trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :1) or (tti.max_installComplete sql =>
select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
ts
where
trp.tsa_id = tti.tsa_id
and tti.status = 1
and ts.site_id = trp.site_id
and
tti.max_install != trp.pushed_rsn
and (
(tti.max_install = 0 and
(trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :1
) or
(tti.max_install > 0 and
(trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :2
) or
(tti.max_install = trp.pushed_rsn and
tti.max_install <> 0
) or
(trp.pushed_time !=
to_date(tti.created_date,'dd-MON-yyhh24:mi:ss') + (1/24/60) * ts.workahead_time
) and
to_date(sysdate,'dd-MON-yyhh24:mi:ss') + (1/24/60) * :3
) > trp.pushed_time
)getting the explain plan for the above sql =>
QL> SELECT plan_table_output FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('g6c8y31xr06vp',0,'ALL'));
PLAN_TABLE_OUTPUT
SQL_ID g6c8y31xr06vp, child number 0
select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
ts where trp.tsa_id = tti.tsa_id and tti.status = 1 and ts.site_id = trp.site_id and
(tti.max_install != trp.pushed_rsn and ((tti.max_install = 0 and (trp.pushed_rsn -
trp.curr_rsn) < ts.workahead_count * :1) or (tti.max_install > 0 and (trp.pushed_rsn -
trp.curr_rsn) < ts.workahead_count * :2) or (tti.max_install = trp.pushed_rsn and
tti.max_install <> 0 ) )) or (trp.pushed_time != (to_date(tti.created_date,'dd-MON-yy
hh24:mi:ss') + (1/24/60) * ts.workahead_time) and ((to_date(sysdate,'dd-MON-yy
hh24:mi:ss') + (1/24/60) * :3) > trp.pushed_time))
Plan hash value: 2862358316
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 601K(100)| |
| 1 | HASH UNIQUE | | 4 | 216 | 601K (10)| 02:00:14 |
| 2 | CONCATENATION | | | | | |
| 3 | NESTED LOOPS | | 200M| 10G| 579K (6)| 01:55:52 |
| 4 | MERGE JOIN CARTESIAN| | 2849 | 99715 | 12 (0)| 00:00:01 |
| 5 | TABLE ACCESS FULL | TAS_SITE | 7 | 70 | 3 (0)| 00:00:01 |
| 6 | BUFFER SORT | | 407 | 10175 | 9 (0)| 00:00:01 |
|* 7 | TABLE ACCESS FULL | TAS_RECEIPTS_PROCESS | 407 | 10175 | 1 (0)| 00:00:01 |
|* 8 | TABLE ACCESS FULL | TAS_TSA_INFO | 70411 | 1306K| 203 (6)| 00:00:03 |
|* 9 | HASH JOIN | | 2 | 108 | 203 (2)| 00:00:03 |
|* 10 | HASH JOIN | | 407 | 14245 | 7 (15)| 00:00:01 |
| 11 | TABLE ACCESS FULL | TAS_SITE | 7 | 70 | 3 (0)| 00:00:01 |
| 12 | TABLE ACCESS FULL | TAS_RECEIPTS_PROCESS | 407 | 10175 | 3 (0)| 00:00:01 |
|* 13 | TABLE ACCESS FULL | TAS_TSA_INFO | 21474 | 398K| 196 (2)| 00:00:03 |
Query Block Name / Object Alias (identified by operation id):
1 - SEL$1
5 - SEL$1_1 / TS@SEL$1
7 - SEL$1_1 / TRP@SEL$1
8 - SEL$1_1 / TTI@SEL$1
11 - SEL$1_2 / TS@SEL$1_2
12 - SEL$1_2 / TRP@SEL$1_2
13 - SEL$1_2 / TTI@SEL$1_2
Predicate Information (identified by operation id):
7 - filter("TRP"."PUSHED_TIME"<TO_DATE(TO_CHAR(SYSDATE@!),'dd-MON-yy
hh24:mi:ss')+.000694444444444444444444444444444444444445*:3)
8 - filter("TRP"."PUSHED_TIME"<>TO_DATE(INTERNAL_FUNCTION("TTI"."CREATED_DATE"),'dd-M
ON-yy hh24:mi:ss')+.000694444444444444444444444444444444444445*"TS"."WORKAHEAD_TIME")
9 - access("TRP"."TSA_ID"="TTI"."TSA_ID")
filter(("TTI"."MAX_INSTALL"<>"TRP"."PUSHED_RSN" AND (("TTI"."MAX_INSTALL"=0 AND
"TRP"."PUSHED_RSN"-"TRP"."CURR_RSN"<"TS"."WORKAHEAD_COUNT"*:1) OR
("TTI"."MAX_INSTALL">0 AND "TRP"."PUSHED_RSN"-"TRP"."CURR_RSN"<"TS"."WORKAHEAD_COUNT"*:2
) OR ("TTI"."MAX_INSTALL"="TRP"."PUSHED_RSN" AND "TTI"."MAX_INSTALL"<>0)) AND
(LNNVL("TRP"."PUSHED_TIME"<TO_DATE(TO_CHAR(SYSDATE@!),'dd-MON-yy
hh24:mi:ss')+.000694444444444444444444444444444444444445*:3) OR
LNNVL("TRP"."PUSHED_TIME"<>TO_DATE(INTERNAL_FUNCTION("TTI"."CREATED_DATE"),'dd-MON-yy
hh24:mi:ss')+.000694444444444444444444444444444444444445*"TS"."WORKAHEAD_TIME"))))
10 - access("TS"."SITE_ID"="TRP"."SITE_ID")
13 - filter("TTI"."STATUS"=1)
Column Projection Information (identified by operation id):
1 - "TRP"."SITE_ID"[NUMBER,22]
2 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
"TS"."WORKAHEAD_TIME"[NUMBER,22], "TRP"."TSA_ID"[NUMBER,22],
"TRP"."SITE_ID"[NUMBER,22], "TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22],
"TRP"."PUSHED_TIME"[DATE,7], "TTI"."TSA_ID"[NUMBER,22], "TTI"."STATUS"[NUMBER,22],
"TTI"."MAX_INSTALL"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7]
3 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
"TS"."WORKAHEAD_TIME"[NUMBER,22], "TRP"."TSA_ID"[NUMBER,22],
"TRP"."SITE_ID"[NUMBER,22], "TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22],
"TRP"."PUSHED_TIME"[DATE,7], "TTI"."TSA_ID"[NUMBER,22], "TTI"."STATUS"[NUMBER,22],
"TTI"."MAX_INSTALL"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7]
4 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
"TS"."WORKAHEAD_TIME"[NUMBER,22], "TRP"."TSA_ID"[NUMBER,22],
"TRP"."SITE_ID"[NUMBER,22], "TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22],
"TRP"."PUSHED_TIME"[DATE,7]
5 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
"TS"."WORKAHEAD_TIME"[NUMBER,22]
6 - (#keys=0) "TRP"."TSA_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
"TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7]
7 - "TRP"."TSA_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
"TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7]
8 - "TTI"."TSA_ID"[NUMBER,22], "TTI"."STATUS"[NUMBER,22],
"TTI"."MAX_INSTALL"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7]
9 - (#keys=1) "TRP"."TSA_ID"[NUMBER,22], "TTI"."TSA_ID"[NUMBER,22],
"TS"."SITE_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
"TS"."WORKAHEAD_TIME"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
"TRP"."PUSHED_RSN"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7],
"TRP"."CURR_RSN"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7], "TTI"."STATUS"[NUMBER,22],
"TTI"."MAX_INSTALL"[NUMBER,22]
10 - (#keys=1) "TS"."SITE_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
"TS"."WORKAHEAD_TIME"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
"TRP"."TSA_ID"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7], "TRP"."CURR_RSN"[NUMBER,22],
"TRP"."PUSHED_RSN"[NUMBER,22]
11 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
"TS"."WORKAHEAD_TIME"[NUMBER,22]
12 - "TRP"."TSA_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
"TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7]
13 - "TTI"."TSA_ID"[NUMBER,22], "TTI"."STATUS"[NUMBER,22],
"TTI"."MAX_INSTALL"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7]
105 rows selected.sizes of concerned objects=>
OWNER SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENTS BYTES_
AZD_SCHM TAS_TSA_INFO TABLE TATSU_DATA_TS 22 7,340,032
AZD_SCHM TAS_TSA_INFO_PK INDEX TATSU_DATA_TS 17 2,097,152
AZD_SCHM TAS_RECEIPTS_PROCESS TABLE TATSU_DATA_TS 1 65,536
AZD_SCHM TAS_RECEIPTS_PROCESS_IDX INDEX TATSU_INDEX_TS 1 65,536
AZD_SCHM TAS_SITE TABLE TATSU_DATA_TS 1 65,536
AZD_SCHM TAS_SITE_NAME_UNQ INDEX TATSU_INDEX_TS 1 65,536
AZD_SCHM TAS_SITE_PK INDEX TATSU_DATA_TS 1 65,536
--------------- ------------------------------ -------------------- -------------------- ------- ----------------Please suggest how to tune this above SQL
Does above sql plan looks good
Any comment and help is highely appreciated.
Thanks & Regards,
IVWivw wrote:
Complete sql =>
Please suggest how to tune this above SQL
Does above sql plan looks good
Any comment and help is highely appreciated.Your SQL is probably incorrectly using the OR operator. In its present form it means this:
select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
ts
where
trp.tsa_id = tti.tsa_id
and tti.status = 1
and ts.site_id = trp.site_id
and
tti.max_install != trp.pushed_rsn
and (
(tti.max_install = 0 and
(trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :1
) or
(tti.max_install > 0 and
(trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :2
) or
(tti.max_install = trp.pushed_rsn and
tti.max_install <> 0
union all
select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
ts
where
(trp.pushed_time !=
to_date(tti.created_date,'dd-MON-yyhh24:mi:ss') + (1/24/60) * ts.workahead_time
) and
to_date(sysdate,'dd-MON-yyhh24:mi:ss') + (1/24/60) * :3
) > trp.pushed_time
and not (above condition)So one of the two parts of the SQL are missing all the join predicates between the tables due to the OR operator at top level. The way the SQL is formatted, it might be meant to read like this:
select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
ts
where
trp.tsa_id = tti.tsa_id
and tti.status = 1
and ts.site_id = trp.site_id
and
(tti.max_install != trp.pushed_rsn
and (
(tti.max_install = 0 and
(trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :1
) or
(tti.max_install > 0 and
(trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :2
) or
(tti.max_install = trp.pushed_rsn and
tti.max_install <> 0
or (trp.pushed_time != to_date(tti.created_date,'dd-MON-yyhh24:mi:ss') + (1/24/60) * ts.workahead_time
and to_date(sysdate,'dd-MON-yyhh24:mi:ss') + (1/24/60) * :3 > trp.pushed_time
)But you need to find out what exactly it is supposed to express from a logical point of view. Very likely the present form is simply incorrect. Depending on your data correcting the usage of the OR operator might even render the DISTINCT operator redundant which is probably at present used to remove the many duplicates generated by the missing join predicates.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/
Maybe you are looking for
-
Object variable or With Block variable not set
Hi - We have saved a working input schedule to a new name and modified it to use for another company. There is a report tab to bring down the historical units from BPC, a tab to trend the history, and a tab that references the other two tabs to fore
-
ClassCastException - App Client
Hi, I'm running an application client to test a program, but I keep getting a java.lang.ClassCastException. Error message: java.lang.ClassCastException at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemotObject.java:293) a
-
I updated to Mavericks and since then my powerpoint no longer works when I want to start the slideshow mode. Help!
-
Out of pure curiosity and interest if some of you had the problem and solved it The event viewer gives three recurrent errors Unable to initialize the security package Kerberos for server side authentication. The data field contains the error number.
-
Need help on logic/ coding
Dear all, I need help on , How to compare two lists? I wrote the following code. but I'm not success. please help. declare rec_cnt number; --This for getting first record set count pd_cnt number;