Sql decode help
I have the following 3 tables:
Table A
Id (Number)
Id#2 (Number)
Type (Number)
Table B
Id#2 (Number)
Decription (Varchar2)
Table C
Id#2 (Number)
Decription (Varchar2)
I want to write a select statement that would return:
Id from Table A,
Description (If type in Table A = 1 then get description from Table B, if type in Table A= 2 then get description from Table C)
Can anyone please help?
Well, one of the things I've learned is "It always depends, you always need to test the defferent scenario's.."
But still I have to agree on this one with you, see the results I got:
SQL> select banner from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio
NLSRTL Version 10.2.0.4.0 - Production
Elapsed: 00:00:00.03
SQL> set autotrace traceonly
SQL> drop table a;
Table dropped.
Elapsed: 00:00:00.37
SQL> drop table b;
Table dropped.
Elapsed: 00:00:00.34
SQL> drop table c;
Table dropped.
Elapsed: 00:00:00.32
SQL> create table a as
2 select level id,
3 level id2,
4 case when rownum <= 500000 then 1 else 2 end type
5 from dual
6 connect by level <= 100000;
Table created.
Elapsed: 00:00:08.18
SQL> create table b as
2 select level id2, 'description table b' description
3 from dual
4 connect by level <= 50000;
Table created.
Elapsed: 00:00:01.06
SQL> create table c as
2 select 50000+level id2, 'description table c' description
3 from dual
4 connect by level <= 50000;
Table created.
Elapsed: 00:00:01.67
SQL> alter table a modify id primary key;
Table altered.
Elapsed: 00:00:01.06
SQL> alter table b modify id2 primary key;
Table altered.
Elapsed: 00:00:00.37
SQL> alter table c modify id2 primary key;
Table altered.
Elapsed: 00:00:00.37
SQL> begin
2 dbms_stats.gather_table_stats(user, 'A');
3 dbms_stats.gather_table_stats(user, 'B');
4 dbms_stats.gather_table_stats(user, 'C');
5 end;
6 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.68
SQL> SELECT a.id,
2 CASE
3 WHEN a.TYPE = 1 THEN
4 b.description
5 WHEN a.TYPE = 2 THEN
6 c.description
7 END description
8 FROM a,
9 b,
10 c
11 WHERE a.id2 = b.id2(+)
12 AND a.id2 = c.id2(+);
100000 rows selected.
Elapsed: 00:00:11.06
Execution Plan
Plan hash value: 1054766904
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 100K| 5859K| | 676 (1)| 00:00:09 |
|* 1 | HASH JOIN RIGHT OUTER | | 100K| 5859K| 1728K| 676 (1)| 00:00:09 |
| 2 | TABLE ACCESS FULL | C | 49082 | 1150K| | 50 (0)| 00:00:01 |
|* 3 | HASH JOIN RIGHT OUTER| | 100K| 3515K| 1800K| 313 (1)| 00:00:04 |
| 4 | TABLE ACCESS FULL | B | 51064 | 1196K| | 50 (0)| 00:00:01 |
| 5 | TABLE ACCESS FULL | A | 100K| 1171K| | 60 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("A"."ID2"="C"."ID2"(+))
3 - access("A"."ID2"="B"."ID2"(+))
Statistics
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
0 bytes sent via SQL*Net to client
0 bytes received via SQL*Net from client
0 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
100000 rows processed
SQL> select a.id,
2 case
3 when a.type = 1 then
4 (select description from b b where b.id2 = a.id2)
5 when a.type = 2 then
6 (select description from c c where c.id2 = a.id2)
7 end description
8 from a a;
100000 rows selected.
Elapsed: 00:00:11.73
Execution Plan
Plan hash value: 3680219842
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 100K| 1171K| 60 (2)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | B | 1 | 24 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0022091 | 1 | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| C | 1 | 24 | 1 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | SYS_C0022092 | 1 | | 1 (0)| 00:00:01 |
| 5 | TABLE ACCESS FULL | A | 100K| 1171K| 60 (2)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("B"."ID2"=:B1)
4 - access("C"."ID2"=:B1)
Statistics
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
0 bytes sent via SQL*Net to client
0 bytes received via SQL*Net from client
0 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
100000 rows processedMy testcase differs from yours, since I added Primary Keys to the tables.
I thought that to be more realistic, I hope you'll agree on that.
That way the plan and time for the second query changes, ofcourse ;-) .
It would be nice to know from Dausboy if our testcases were more or less representative for his situation anyway.
Similar Messages
-
Logical Operations in SQL decode function ?
Hi,
Is it possible to do Logical Operations in SQL decode function
like
'>'
'<'
'>='
'<='
'<>'
not in
in
not null
is null
eg...
select col1 ,order_by,decode ( col1 , > 10 , 0 , 1)
from tab;
select col1 ,order_by,decode ( col1 , <> 10 , 0 , 1)
from tab;
select col1 ,order_by,decode ( col1 , not in (10,11,12) , 0 , 1)
from tab;
select col1 ,order_by,decode ( col1 ,is null , 0 , 1)
from tab;
Regards,
infan
Edited by: user780731 on Apr 30, 2009 12:07 AM
Edited by: user780731 on Apr 30, 2009 12:07 AM
Edited by: user780731 on Apr 30, 2009 12:08 AM
Edited by: user780731 on Apr 30, 2009 12:08 AM
Edited by: user780731 on Apr 30, 2009 12:09 AMexample:
select col1 ,order_by,case when col1 > 10 then 0 else 1 end
from tab;
select col1 ,order_by,case when col1 <> 10 then 0 else 1 end
from tab;
select col1 ,order_by,case when col1 not in (10,11,12) then 0 else 1 end
from tab;As for testing for null, decode handles that by default anyway so you can have decode or case easily..
select col1 ,order_by,decode (col1, null , 0 , 1)
from tab;
select col1 ,order_by,case when col1 is null then 0 else 1 end
from tab; -
Hi! Does anyone know where i can download SQL*Plus Help? I need to get info on select syntax, sql built-in functions, etc..
Thanks!hi
you can proceed like this :
go to the OTN
the click on products.
null -
How to install SQL*Plus help facilities and demos.
Hi, everyone
It appears error message say "failure to login" during SQL*Plus
part of the Oracle8 full installation. I knew that system want
to install SQL*Plus help and demos through logining one of
dba account(maybe system user account). However, due to
password's reason, can not log in SQL*Plus, so installer can't
execute named pupbld.sql script, result in SQL*Plus help and
demos can not be installed.
Now, I am intend to install these stuff lonely.
Could anyone help me? thank a lot.
William
nullHi,
The pupbld.sql isn't the correct script to create the help
facility, it just creates product and user profile tables.
The help script is at $ORACLE_HOME/sqlplus/admin/help (run as
system)
cd $ORACLE_HOME/sqlplus/admin/help
sqlplus system/<password> @helptbl
sqlldr system/<password> control=plushelp.ctl
sqlldr system/<password> control=plshelp.ctl
sqlldr system/<password> control=sqlhelp.ctl
sqlplus system/<password> @helpindx
I think it is necessary to run the pupbld.sql script, without
this script everyone who logins in oracle with sqlplus will see
an error message, but... Run the script again:
$ORACLE_HOME/sqlplus/admin/pupbld.sql
Best regards,
Ari
William (guest) wrote:
: Hi, everyone
: It appears error message say "failure to login" during SQL*Plus
: part of the Oracle8 full installation. I knew that system want
: to install SQL*Plus help and demos through logining one of
: dba account(maybe system user account). However, due to
: password's reason, can not log in SQL*Plus, so installer can't
: execute named pupbld.sql script, result in SQL*Plus help and
: demos can not be installed.
: Now, I am intend to install these stuff lonely.
: Could anyone help me? thank a lot.
: William
null -
Will Oracle pl/sql certification help me get IT job
Hello guys,
I have completed my B.tech in Computer Science, I am confused a bit , Can i get a job after getting certified in Oracle Associate Pl/sql developer1005323 wrote:
Hello guys,
I have completed my B.tech in Computer Science, I am confused a bit , Can i get a job after getting certified in Oracle Associate Pl/sql developerYou may get a job after achieving Pl/sql developer OCA
You may get a job after without achieving Pl/sql developer OCA
You may fail to get a job after achieving Pl/sql developer OCA
You may fail to get a job after without achieving Pl/sql developer OCA
There are several factors involved in getting a job. And there are several ways a job may be obtained. But usually there are there stages:
- Stage Zero: A company but has a job to offer.
- And you need to be aware of it. - A friend may tell you, or an agency may tell you. And it must suit you for location and remuneration etc.
- Stage one: An interview is obtained with the company.
- Stage two: The job is offered to you rather than anyone else and you find it acceptable.
So ... to your question:
"Can i get a job after getting certified in Oracle Associate Pl/sql developer?"
Well .... there is only three possible answers ... yes, no, and maybe; and maybe is probably the only correct answer, and most people will have worked this out, which means the question may have not been the best question to have asked.
(( That said I now read the title of the thread and it says: Re: Will Oracle pl/sql certification help me get IT job)
I have been known on occasion to have been given a question by a boss.
And I have answered him:
"You have given me the wrong question
The question you should have answer me is this.
And the answer I will give you is this."
And the boss goes away happy
So you you a better question would have been:
How much will an OCA PL/SQL certification increase my chances of getting a job?
Mind you even that question won't help you get a much better answer.
For a proportion of jobs where PL/SQL is relevant that will help (for those where it is not it might be occasionally be a problem), for people with identical CV's it sometimes might help get to interview stage. But there are other factors as well. For instance if I was thinking of giving you a job on the basis of your post I might for example:
- Not be impressed with an "Hello Guys" greeting ( though this is a forum so that isn't relevant here).
- Not be impressed with you being confused.
- etc.
You probably need to get a good appreciation of the job market in your locality; and the numbers of applicants for each job. Which jobs you can apply for, what is your skillset and knowing youself as well.
Sometimes an ITIL certification may be a better differentiator for some positions in business. But it will depend on the job you can think you can get. -
(SQL*PLUS HELP) RUNNING PUPBLD OR HELPINS ASKS FOR SYSTEM_PASS
제품 : ORACLE SERVER
작성날짜 : 2002-04-22
(SQL*PLUS HELP) RUNNING PUPBLD OR HELPINS ASKS FOR SYSTEM_PASS
==============================================================
PURPOSE
이 내용은 SQL*Plus 상에서 SQL*Plus command의 help를 보기 위한 방법이다.
Problem Description
SQL*Plus command의 help를 보기 위해서 helpins를 수행하면
SYSTEM_PASS is not set이라는 에러 메시지가 발생하는 경우가 있다.
이 자료는 pupbld 또는 helpins를 수행하기 전에 SYSTEM_PASS 환경변수를
셋팅하는 방법에 대한 자료이다.
아래와 같은 에러가 발생하는 경우 조치 방법에 대해 알아본다.
SYSTEM_PASS not set.
Set and export SYSTEM_PASS, then restart help (for helpins or
profile for pupbld) installation.
Workaround
none
Solution Description
이 스크립트는 system user로 database에 connect되어 수행되어야 한다.
helpins를 수행하기 위해서는 SYSTEM_PASS 환경변수가 셋팅되어 있어야 한다.
NOTE
For security reasons, do not set this variable in your shell
startup scripts. (i.e. .login or .profile.).
Set this environment variable at the prompt.
1. Prompt에서 환경변수를 셋팅하기
For C shell:
% setenv SYSTEM_PASS system/<password>
For Korn or Bourne shells:
$ SYSTEM_PASS=system/<password> ;export SYSTEM_PASS
2. Now run "$ORACLE_HOME/bin/pupbld" or "$ORACLE_HOME/bin/helpins".
% cd $ORACLE_HOME/bin
% pupbld
or
% helpins
주의사항
$ORACLE_HOME/bin/pupbld 스크립트와 $ORACLE_HOME/bin/helpins 스크
립트를 수행하기 위해서는 반드시 SYSTEM_PASS 환경변수를 필요로 한다.
Reference Document
<Note:1037075.6>check it please whether it is a database version or just you are installing a client. Install Enterprize database on 2k system. I you are running a client software then you are to deinstall it.
-
Download Oracle SQL*Plus help related like word help
Hello all
I just wanna ask if where i can download Oracle SQL*Plus help related like word help.?
ty<p>You can access SQL*Plus help from the command line in a SQL*Plus session by typing 'help index'. If you want more information than that, take a look at the SQL*Plus Quick Reference located <b>here</b> or the SQL*Plus User's Guide and Reference located <b>here</b>. These docs are all for Oracle 10g. Other version documentation can be found <b>here</b>.</p>
Tom -
Having trouble with SQLServer 2008 (not MySQL) and my database connection in Dreamweaver CS6. My document type is set as .asp using VBScript. I can list the table information but cannot use the insert wizard to add new records. I don't get any errors after creating the insert form, but no records get inserted. I'm not a VBScript expert, but do I have to manually write some code to insert records? How do I attach it to a button?
Thanks for the quick reply. I won't be back in the office for a few days, but I'll try to post it when I get back in. It's pretty much the code generated from the Dreamweaver Insert Record wizard. I see where the submit button is created and the value is set but the action on the form is set to MM_insert, so I don't see where the submit code is actually called.
Date: Wed, 3 Oct 2012 12:06:14 -0600
From: [email protected]
To: [email protected]
Subject: SQL Server2008 help needed
Re: SQL Server2008 help needed
created by bregent in Dreamweaver General - View the full discussion
This post should be moved to the app dev forum. Please post the code from your form and the insert script pages.
Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/4746757#4746757
Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4746757#4746757
To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4746757#4746757. In the Actions box on the right, click the Stop Email Notifications link.
Start a new discussion in Dreamweaver General by email or at Adobe Community
For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746. -
Hi.,
Just confused why the below statement is not producing the correct output..its printing as Hello.
select decode(to_char(sysdate,'Day'),'Mon','Hi','Hello')
from dualBut this statement is getting me correct result..
select decode(to_char(sysdate,'dd'),'26','Hi','Hello')
from dualAny explantions?..anything to do with to_char ?
ThanksRather than using TRIM, just use the correct format mask to tell TO_CHAR that you do not want it padded with spaces...
SQL> select to_char(sysdate,'Day'), length(to_char(sysdate,'Day')) from dual;
TO_CHAR(S LENGTH(TO_CHAR(SYSDATE,'DAY'))
Monday 9
SQL> select to_char(sysdate,'fmDay'), length(to_char(sysdate,'fmDay')) from dual;
TO_CHAR(S LENGTH(TO_CHAR(SYSDATE,'FMDAY'))
Monday 6 -
i m writing an sql query to print records
select role_name,date_created,date_modified,createdbyuser_id,modifiedbyuser_id from t_role;
This returns me the the rows in table t_role.
But what i want is instead of the id of the person being printed in createdbyuser_id and modifiedbyuser_id, it shud provide me the username from another table user by checking the user_id field of table user.For this i used the fuction decode .But it oesnt work
select role_name,date_created,date_modified,(select user_name from user where user_id=createdbyuser_id),(select user_name from user where user_id=modifiededbyuser_id) from role;
kindly point out the mistake.
Shefali<<
i m writing an sql query to print records
>>
and
<<
1) tried this
select a.role_name,a.date_created, a.date_modified, b.user_name, c.user_name from role a, user b, user c where b.user_Id = a.createdbyuser_Id and c.user_Id = a.modifiedbyuser_Id;
But getting this error::
ORA-20001: Your query contains duplicate alias names, queries used for reports require unique alias names.
Error saving column settings
>>
so you are working with report writer ?
the error message is telling you all you need.
just change :
select a.role_name ,a.date_created, a.date_modified
, b.user_name, c.user_name
from role a, user b, user c
where b.user_Id = a.createdbyuser_Id
and c.user_Id = a.modifiedbyuser_Id
;to
select a.role_name ,a.date_created, a.date_modified
, b.user_name_creator, c.user_name_modifier
from role a, user b, user c
where b.user_Id = a.createdbyuser_Id
and c.user_Id = a.modifiedbyuser_Id
; -
Convert decode oracle pl/sq to ms sql and help required on logic
I have below oracle query need to converted to ms sql. I also want to add a record into journal table when a
insert portion is executed "caseidinserted" and update portion executed then "caseidupdate".
Update table1 target
set curr =
decode(
select efforts from (
select source.efforts efforts
from
SELECT a.aid,a.efforts,ab.lcs
FROM CIP a, DC ab
WHERE a id = ab.id
AND a.id = @id
) source
where target.caseid = @caseidupd
and target.aid = source.aid
) tmp, 0, tmp.efforts, curr
modi = getdate( )
where exists
select 1
from table1 tgt
where tgt.aid = target.aid
and tgt.caseid = @caseidupd
insert into table1 values(caseid, aid, modi)
select @caseidupd, source.aid, getdate()
from
SELECT a.aid,a.efforts,ab.lcs
FROM CIP a, DC ab
WHERE a id = ab.id
AND a.id = @id
) source
where not exists
select 1
from table1 target
where target.aid = source.aid
and target.caseid = @caseidupd
something like this...
INSERT (caseid,aid,modi)
select @caseidupd,'appupdated'+source.aid,getdate()
INSERT (caseid,aid,modi)
select (@caseidupd,'appinserted'+source.aid,getdate()Hello,
I am not familiar with Oracle Function. If I understand correctly, you can MERGE to perform INSERT and UPDATE operations on a table in a single statement. Please refer to the following statements:
MERGE INTO table1 AS Target
USING (select @caseidupd, source.aid, getdate()
from
SELECT a.aid,a.efforts,ab.lcs
FROM CIP a, DC ab
WHERE a id = ab.id
AND a.id = @id
) As Source (caseidupd,aid,date )
ON Target.aid = source.aid and target.caseid =source.caseidupd
WHEN MATCHED THEN
UPDATE SET Target.curr=...,--query for get values
Target.modi=getdate()
WHEN NOT MATCHED BY TARGET THEN
INSERT (caseid,aid,modi) values (caseidupd,'appupdated'+source.aid,getdate())
Reference:http://msdn.microsoft.com/en-us/library/bb510625.aspx
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support -
Hi,
I'm writing an HTMLDB application that we will be using to track the number of hours that we put into a project (all projects), and I've got a routine that returns the number of hours that are possible within a given month M-F 8 hours a day. I use this value returned to indicate how many hours have been enterered.
SELECT null link, 'Still Unrecorded' itsrdescr,trueworkdays(:P80_START,:P80_END)*8-(select sum(hoursworked) ihoursworked from workdetail wd, breakdowns b
WHERE wd.workdetailid = b.itsrnum and b.oid = upper(:P80_DEVELOPER) and dateworked between :P80_START and :P80_END) hoursworked
from dual
UNION
SELECT null link, wd.itsrdescr,sum(b.hoursworked) hoursworked
FROM workdetail wd, breakdowns b
WHERE wd.workdetailid = b.itsrnum and b.oid = upper(:P80_DEVELOPER) and dateworked between :P80_START and :P80_END
GROUP by wd.itsrdescr
ORDER by hoursworked desc
What I'm wanting is something along the lines of this:
SELECT null link, 'Still Unrecorded' itsrdescr,decode((trueworkdays(:P80_START,:P80_END)*8-(select sum(hoursworked) ihoursworked from workdetail wd, breakdowns b
WHERE wd.workdetailid = b.itsrnum and b.oid = upper(:P80_DEVELOPER) and dateworked between :P80_START and :P80_END)),<0,0,?????????) hoursworked
from dual
UNION
SELECT null link, wd.itsrdescr,sum(b.hoursworked) hoursworked
FROM workdetail wd, breakdowns b
WHERE wd.workdetailid = b.itsrnum and b.oid = upper(:P80_DEVELOPER) and dateworked between :P80_START and :P80_END
GROUP by wd.itsrdescr
ORDER by hoursworked desc
which will include a decode statement to let me know when the value getting returned into hoursworked on that first column is less than zero which throws off the chart. In this particular case, it has a value of -6 which makes all my percentages go haywire. How would one code this statement to include a decode statement to find out if that sum is returning a negative number?
Hope this made sense,
TIA,
cliffHey Tyler,
Actually.... It kinda killed the server. I'm trying to figure out a way to get the following functionality in a different way. Here is the way that the query turned out using the case statement.
SELECT null link, '<b><font color="red">Still Unrecorded</font></b>' itsrdescr,
(case
when (trueworkdays(:P80_START,:P80_END)*8-(select sum(hoursworked) ihoursworked from workdetail wd, breakdowns b
WHERE wd.workdetailid = b.itsrnum and b.oid = upper(:P80_DEVELOPER) and dateworked between :P80_START and :P80_END)) < 0 then 0
else
(trueworkdays(:P80_START,:P80_END)*8-(select sum(hoursworked) ihoursworked from workdetail wd, breakdowns b
WHERE wd.workdetailid = b.itsrnum and b.oid = upper(:P80_DEVELOPER) and dateworked between :P80_START and :P80_END))
end) hoursworked
from dual
UNION
SELECT null link, wd.itsrdescr,sum(b.hoursworked) hoursworked
FROM workdetail wd, breakdowns b
WHERE wd.workdetailid = b.itsrnum and b.oid = upper(:P80_DEVELOPER) and dateworked between :P80_START and :P80_END
GROUP by wd.itsrdescr
ORDER by hoursworked desc
Any tips on what I could do to get the above functionality without killing my server.
Thx for the input
cliff -
Hi All,
I am creating a report which is having 2 sql queries ,1 for the main columns that i need to show and 2 from total sum and count.
Report is something as given below
SET TAB OFF;
set linesize 1500;
set pagesize 50;
SET FEEDBACK OFF;
SET WRAP OFF
COLUMN today NEW_VALUE VAR1 NOPRINT;
TTITLE LEFT 'ABC Inc.' SKIP 1 -
LEFT 'Daily Report' SKIP 1 -
LEFT 'As Of ' VAR1 SKIP 2
BTITLE LEFT SKIP 'Page No : ' FORMAT 9999999999 SQL.PNO SKIP 3;
COL SR_NO HEADING 'Seq' FORMAT 999999;
COL REFNO HEADING 'Ref No' FORMAT A20;
COL ORIG_NAME HEADING ' Branch Name'
FORMAT A50;
SELECT ROWNUM SR_NO,
REF_NO REFNO,
ORIGIN_NAME BRNAME
FROM BANK
WHERE PASS_CD=101
SELECT ' Failure Count : '|| NVL(COUNT(DECODE(CODE,1,CODE,NULL)),0) ||
' Failure Total Amt : '|| NVL(SUM(DECODE(CODE,799,AMT,NULL)),0)
|| CHR(10) ||
' Successful Count : '|| NVL(COUNT(DECODE(CODE,000,CODE,NULL)),0) ||
' Successful Total Amt: '|| NVL(SUM(DECODE(CODE,000,AMT,NULL)),0)
FROM BANK;
CLEAR BREAKS;
CLEAR COLUMN;
TTITLE OFF;
When i am running this second query output is going to secong page and title is repeated again and same as 1rst page is showing page no-1
Kindly help me,i want the output on the same page at bottom.
Thanksi think its only work in ISQL* PLUS enivironment iam
not sure.It does work in SQL*Plus
is that i can use in the package??http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12048.htm -
Hi,
I need some help on tuning this sql. We run a third party application and I have to ask thrid party for any changes. I have pasted the session statistice from the run for this sql.
SELECT DECODE( RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,
' ')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' '),
RPAD(NVL(:zipout1,' '),4,' ')||RPAD(NVL(:zipin1,' '),3,' '),
'0001', RPAD(NVL(:zipout2,' '),4,'
')||RPAD(SUBSTR(NVL(:zipin2,' '),0,1),3,' '), '0002',
RPAD(NVL(:zipout3,' '),7,' '), '0003',
RPAD('ZZ999',7,' '), '0004' ) AS CHECKER
FROM NWKPCDREC
WHERE NWKPCDNETWORKID = :netid
AND NWKPCDSORTPOINT1TYPE != 'XXXXXXXX'
AND ( (RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,' ')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' ') =
RPAD(NVL(:zipout4,' '),4,' ')||RPAD(NVL(:zipin3,' '),3,' '))
OR (RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,'
')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' ') =
RPAD(NVL(:zipout5,' '),4,' ')||RPAD(SUBSTR(NVL(:zipin4,' '),0,
1),3,' ')) OR (RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,'
')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' ') =
RPAD(NVL(:zipout6,' '),7,' ')) OR
(RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,'
')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' ') = RPAD('ZZ999',7,
' ')) ) ORDER BY CHECKER
Session Statistics 09 October 2007 22:44:56 GMT+00:00
Report Target : PRD1 (Database)
Session Statistics
(Chart form was tabular, see data table below)
SID Name Value Class
37 write clones created in foreground 0 Cache
37 write clones created in background 0 Cache
37 user rollbacks 16 User
37 user commits 8674 User
37 user calls 302838 User
37 transaction tables consistent reads - undo records applied 0 Debug
37 transaction tables consistent read rollbacks 0 Debug
37 transaction rollbacks 9 Debug
37 transaction lock foreground wait time 0 Debug
37 transaction lock foreground requests 0 Debug
37 transaction lock background gets 0 Debug
37 transaction lock background get time 0 Debug
37 total file opens 12 Cache
37 table scans (short tables) 8062 SQL
37 table scans (rowid ranges) 0 SQL
37 table scans (long tables) 89 SQL
37 table scans (direct read) 0 SQL
37 table scans (cache partitions) 2 SQL
37 table scan rows gotten 487042810 SQL
37 table scan blocks gotten 7327924 SQL
37 table fetch continued row 17 SQL
37 table fetch by rowid 26130550 SQL
37 switch current to new buffer 6400 Cache
37 summed dirty queue length 0 Cache
37 sorts (rows) 138607 SQL
37 sorts (memory) 13418 SQL
37 sorts (disk) 0 SQL
37 session uga memory max 5176776 User
37 session uga memory 81136 User
37 session stored procedure space 0 User
37 session pga memory max 5559884 User
37 session pga memory 5559884 User
37 session logical reads 115050107 User
37 session cursor cache hits 0 SQL
37 session cursor cache count 0 SQL
37 session connect time 1191953042 User
37 serializable aborts 0 User
37 rows fetched via callback 1295545 SQL
37 rollbacks only - consistent read gets 0 Debug
37 rollback changes - undo records applied 114 Debug
37 remote instance undo header writes 0 Global Cache
37 remote instance undo block writes 0 Global Cache
37 redo writes 0 Redo
37 redo writer latching time 0 Redo
37 redo write time 0 Redo
37 redo wastage 0 Redo
37 redo synch writes 8683 Cache
37 redo synch time 722 Cache
37 redo size 25463692 Redo
37 redo ordering marks 0 Redo
37 redo log switch interrupts 0 Redo
37 redo log space wait time 0 Redo
37 redo log space requests 1 Redo
37 redo entries 81930 Redo
37 redo buffer allocation retries 1 Redo
37 redo blocks written 0 Redo
37 recursive cpu usage 101 User
37 recursive calls 84413 User
37 recovery blocks read 0 Cache
37 recovery array reads 0 Cache
37 recovery array read time 0 Cache
37 queries parallelized 0 Parallel Server
37 process last non-idle time 1191953042 Debug
37 prefetched blocks aged out before use 0 Cache
37 prefetched blocks 1436767 Cache
37 pinned buffers inspected 89 Cache
37 physical writes non checkpoint 3507 Cache
37 physical writes direct (lob) 0 Cache
37 physical writes direct 3507 Cache
37 physical writes 3507 Cache
37 physical reads direct (lob) 0 Cache
37 physical reads direct 2499 Cache
37 physical reads 1591668 Cache
37 parse time elapsed 336 SQL
37 parse time cpu 315 SQL
37 parse count (total) 28651 SQL
37 parse count (hard) 1178 SQL
37 opens requiring cache replacement 0 Cache
37 opens of replaced files 0 Cache
37 opened cursors current 51 User
37 opened cursors cumulative 28651 User
37 no work - consistent read gets 59086317 Debug
37 no buffer to keep pinned count 0 Other
37 next scns gotten without going to DLM 0 Parallel Server
37 native hash arithmetic fail 0 SQL
37 native hash arithmetic execute 0 SQL
37 messages sent 9730 Debug
37 messages received 0 Debug
37 logons current 1 User
37 logons cumulative 1 User
37 leaf node splits 111 Debug
37 kcmgss waited for batching 0 Parallel Server
37 kcmgss read scn without going to DLM 0 Parallel Server
37 kcmccs called get current scn 0 Parallel Server
37 instance recovery database freeze count 0 Parallel Server
37 index fast full scans (rowid ranges) 0 SQL
37 index fast full scans (full) 210 SQL
37 index fast full scans (direct read) 0 SQL
37 immediate (CURRENT) block cleanout applications 4064 Debug
37 immediate (CR) block cleanout applications 83 Debug
37 hot buffers moved to head of LRU 20004 Cache
37 global lock sync gets 0 Parallel Server
37 global lock sync converts 0 Parallel Server
37 global lock releases 0 Parallel Server
37 global lock get time 0 Parallel Server
37 global lock convert time 0 Parallel Server
37 global lock async gets 0 Parallel Server
37 global lock async converts 0 Parallel Server
37 global cache read buffer lock timeouts 0 Global Cache
37 global cache read buffer blocks served 0 Global Cache
37 global cache read buffer blocks received 0 Global Cache
37 global cache read buffer block timeouts 0 Global Cache
37 global cache read buffer block send time 0 Global Cache
37 global cache read buffer block receive time 0 Global Cache
37 global cache read buffer block build time 0 Global Cache
37 global cache prepare failures 0 Global Cache
37 global cache gets 0 Global Cache
37 global cache get time 0 Global Cache
37 global cache freelist waits 0 Global Cache
37 global cache defers 0 Global Cache
37 global cache cr timeouts 0 Global Cache
37 global cache cr requests blocked 0 Global Cache
37 global cache cr blocks served 0 Global Cache
37 global cache cr blocks received 0 Global Cache
37 global cache cr block send time 0 Global Cache
37 global cache cr block receive time 0 Global Cache
37 global cache cr block flush time 0 Global Cache
37 global cache cr block build time 0 Global Cache
37 global cache converts 0 Global Cache
37 global cache convert timeouts 0 Global Cache
37 global cache convert time 0 Global Cache
37 global cache blocks corrupt 0 Global Cache
37 free buffer requested 1597281 Cache
37 free buffer inspected 659 Cache
37 execute count 128826 SQL
37 exchange deadlocks 1 Cache
37 enqueue waits 0 Enqueue
37 enqueue timeouts 0 Enqueue
37 enqueue requests 23715 Enqueue
37 enqueue releases 23715 Enqueue
37 enqueue deadlocks 0 Enqueue
37 enqueue conversions 0 Enqueue
37 dirty buffers inspected 437 Cache
37 deferred (CURRENT) block cleanout applications 21937 Debug
37 db block gets 230801 Cache
37 db block changes 160407 Cache
37 data blocks consistent reads - undo records applied 460 Debug
37 cursor authentications 488 Debug
37 current blocks converted for CR 0 Cache
37 consistent gets 114819307 Cache
37 consistent changes 460 Cache
37 commit cleanouts successfully completed 37201 Cache
37 commit cleanouts 37210 Cache
37 commit cleanout failures: write disabled 0 Cache
37 commit cleanout failures: hot backup in progress 0 Cache
37 commit cleanout failures: cannot pin 0 Cache
37 commit cleanout failures: callback failure 3 Cache
37 commit cleanout failures: buffer being written 0 Cache
37 commit cleanout failures: block lost 6 Cache
37 cold recycle reads 0 Cache
37 cluster key scans 17 SQL
37 cluster key scan block gets 36 SQL
37 cleanouts only - consistent read gets 83 Debug
37 cleanouts and rollbacks - consistent read gets 0 Debug
37 change write time 108 Cache
37 calls to kcmgrs 0 Debug
37 calls to kcmgcs 391 Debug
37 calls to kcmgas 8816 Debug
37 calls to get snapshot scn: kcmgss 171453 Parallel Server
37 bytes sent via SQL*Net to dblink 0 User
37 bytes sent via SQL*Net to client 25363874 User
37 bytes received via SQL*Net from dblink 0 User
37 bytes received via SQL*Net from client 29829542 User
37 buffer is pinned count 540816 Other
37 buffer is not pinned count 86108905 Other
37 branch node splits 6 Debug
37 background timeouts 0 Debug
37 background checkpoints started 0 Cache
37 background checkpoints completed 0 Cache
37 Unnecesary process cleanup for SCN batching 0 Parallel Server
37 SQL*Net roundtrips to/from dblink 0 User
37 SQL*Net roundtrips to/from client 302837 User
37 Parallel operations not downgraded 0 Parallel Server
37 Parallel operations downgraded to serial 0 Parallel Server
37 Parallel operations downgraded 75 to 99 pct 0 Parallel Server
37 Parallel operations downgraded 50 to 75 pct 0 Parallel Server
37 Parallel operations downgraded 25 to 50 pct 0 Parallel Server
37 Parallel operations downgraded 1 to 25 pct 0 Parallel Server
37 PX remote messages sent 0 Parallel Server
37 PX remote messages recv'd 0 Parallel Server
37 PX local messages sent 0 Parallel Server
37 PX local messages recv'd 0 Parallel Server
37 OS Voluntary context switches 0 OS
37 OS User time used 0 OS
37 OS System time used 0 OS
37 OS Swaps 0 OS
37 OS Socket messages sent 0 OS
37 OS Socket messages received 0 OS
37 OS Signals received 0 OS
37 OS Page reclaims 0 OS
37 OS Page faults 0 OS
37 OS Maximum resident set size 0 OS
37 OS Involuntary context switches 0 OS
37 OS Integral unshared stack size 0 OS
37 OS Integral unshared data size 0 OS
37 OS Integral shared text size 0 OS
37 OS Block output operations 0 OS
37 OS Block input operations 0 OS
37 DML statements parallelized 0 Parallel Server
37 DFO trees parallelized 0 Parallel Server
37 DDL statements parallelized 0 Parallel Server
37 DBWR undo block writes 0 Cache
37 DBWR transaction table writes 0 Cache
37 DBWR summed scan depth 0 Cache
37 DBWR revisited being-written buffer 0 Cache
37 DBWR make free requests 0 Cache
37 DBWR lru scans 0 Cache
37 DBWR free buffers found 0 Cache
37 DBWR cross instance writes 0 Global Cache
37 DBWR checkpoints 0 Cache
37 DBWR checkpoint buffers written 0 Cache
37 DBWR buffers scanned 0 Cache
37 Commit SCN cached 0 Debug
37 Cached Commit SCN referenced 1 Debug
37 CR blocks created 203 Cache
37 CPU used when call started 280528 Debug
37 CPU used by this session 280528 User
Regards
Raj
--------------------------------------------------------------------------------Thank you everybody for helping me out while tuning the query. I have managed to bring down the run time from 60 minutes to 12 minutes.
I am posting the exisitng query, existing database objects ddl and the new query and new ddl to share my learning. This is my first use of forum, senior members, please letme know if I shouldn't have put all this here.
/pre original code
SELECT decode(rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' '), rpad(nvl(:zipout1, ' '), 4, ' ')
|| rpad(nvl(:zipin1, ' '), 3, ' '), '0001', rpad(nvl(:zipout2, ' '), 4,
' ') || rpad(substr(nvl(:zipin2, ' '), 0, 1), 3, ' '), '0002',
rpad(nvl(:zipout3, ' '), 7, ' '), '0003', rpad('ZZ999', 7, ' '), '0004')
AS checker, a.nwkpcdbarcode1to7 nwkpcdbarcode1to7,
a.nwkpcdbarcode15 nwkpcdbarcode15,
a.nwkpcdbarcodeseqkey nwkpcdbarcodeseqkey,
a.nwkpcdsortpoint1code nwkpcdsortpoint1code,
a.nwkpcdsortpoint1type nwkpcdsortpoint1type,
a.nwkpcdsortpoint1name nwkpcdsortpoint1name,
a.nwkpcdsortpoint1extra nwkpcdsortpoint1extra,
a.nwkpcdsortpoint2type nwkpcdsortpoint2type,
a.nwkpcdsortpoint2name nwkpcdsortpoint2name,
a.nwkpcdsortpoint3type nwkpcdsortpoint3type,
a.nwkpcdsortpoint3name nwkpcdsortpoint3name,
a.nwkpcdsortpoint4type nwkpcdsortpoint4type,
a.nwkpcdsortpoint4name nwkpcdsortpoint4name,
b.nwkprfnetworksequence nwkprfnetworksequence,
b.nwkprfnetworkid nwkprfnetworkid, b.nwkprfnetworkname nwkprfnetworkname,
b.nwkprfminweight / 100 AS nwkprfminweight, b.nwkprfmaxweight / 100 AS
nwkprfmaxweight, b.nwkprfminlengthgirth nwkprfminlengthgirth,
b.nwkprfmaxlengthgirth nwkprfmaxlengthgirth,
b.nwkprfminlength nwkprfminlength, b.nwkprfmaxlength nwkprfmaxlength,
b.nwkprfparceltypecode nwkprfparceltypecode,
b.nwkprfparceltypename nwkprfparceltypename
FROM wh1.nwkpcdrec a, wh1.nwkprefrec b
WHERE a.nwkpcdnetworkid = b.nwkprfnetworkid
AND a.nwkpcdsortpoint1type != 'XXXXXXXX'
AND (rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' ') = rpad(nvl(:zipout4, ' '), 4, ' '
) || rpad(nvl(:zipin3, ' '), 3, ' ')
OR rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' ') = rpad(nvl(:zipout5, ' '), 4, ' '
) || rpad(substr(nvl(:zipin4, ' '), 0, 1), 3, ' ')
OR rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' ') = rpad(nvl(:zipout6, ' '), 7, ' '
OR rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' ') = rpad('ZZ999', 7, ' '))
AND :weight1 >= b.nwkprfminweight
AND :weight2 <= b.nwkprfmaxweight
AND b.nwkprfminlengthgirth <= 60
AND b.nwkprfmaxlengthgirth >= 60
AND b.nwkprfminlength <= 15
AND b.nwkprfmaxlength >= 15
ORDER BY b.nwkprfnetworkid, checker
CREATE TABLE "WH1"."NWKPCDREC" ("NWKPCDFILECODE" VARCHAR2(2),
"NWKPCDRECORDTYPE" VARCHAR2(4), "NWKPCDNETWORKID" VARCHAR2(2),
"NWKPCDOUTWDPOSTCODE" VARCHAR2(4), "NWKPCDINWDPOSTCODE"
VARCHAR2(3), "NWKPCDSORTPOINT1CODE" VARCHAR2(2),
"NWKPCDSORTPOINT1TYPE" VARCHAR2(8), "NWKPCDSORTPOINT1NAME"
VARCHAR2(16), "NWKPCDSORTPOINT1EXTRA" VARCHAR2(16),
"NWKPCDSORTPOINT2TYPE" VARCHAR2(8), "NWKPCDSORTPOINT2NAME"
VARCHAR2(8), "NWKPCDSORTPOINT3TYPE" VARCHAR2(8),
"NWKPCDSORTPOINT3NAME" VARCHAR2(8), "NWKPCDSORTPOINT4TYPE"
VARCHAR2(8), "NWKPCDSORTPOINT4NAME" VARCHAR2(8), "NWKPCDPPI"
VARCHAR2(8), "NWKPCDBARCODE1TO7" VARCHAR2(7),
"NWKPCDBARCODE15" VARCHAR2(1), "NWKPCDBARCODESEQKEY"
VARCHAR2(7), "NWKPCDFILLER1" VARCHAR2(7), "NWKPCDFILLER2"
VARCHAR2(30),
CONSTRAINT "UK_NWKPCDREC" UNIQUE("NWKPCDNETWORKID",
"NWKPCDOUTWDPOSTCODE", "NWKPCDINWDPOSTCODE")
USING INDEX
TABLESPACE "WH1_INDEX"
STORAGE ( INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
PCTFREE 10 INITRANS 2 MAXTRANS 255)
TABLESPACE "WH1_DATA_LARGE" PCTFREE 10 PCTUSED 40 INITRANS 1
MAXTRANS 255
STORAGE ( INITIAL 4096K NEXT 4096K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
NOLOGGING
pre original script/
/pre modified script
CREATE TABLE "WH1"."NWKPCEREC_OLD" ("NWKPCDFILECODE" VARCHAR2(2),
"NWKPCDRECORDTYPE" VARCHAR2(4), "NWKPCDNETWORKID" VARCHAR2(2),
"NWKPCDOUTWDPOSTCODE" VARCHAR2(4), "NWKPCDINWDPOSTCODE"
VARCHAR2(3), "NWKPCDSORTPOINT1CODE" VARCHAR2(2),
"NWKPCDSORTPOINT1TYPE" VARCHAR2(8), "NWKPCDSORTPOINT1NAME"
VARCHAR2(16), "NWKPCDSORTPOINT1EXTRA" VARCHAR2(16),
"NWKPCDSORTPOINT2TYPE" VARCHAR2(8), "NWKPCDSORTPOINT2NAME"
VARCHAR2(8), "NWKPCDSORTPOINT3TYPE" VARCHAR2(8),
"NWKPCDSORTPOINT3NAME" VARCHAR2(8), "NWKPCDSORTPOINT4TYPE"
VARCHAR2(8), "NWKPCDSORTPOINT4NAME" VARCHAR2(8), "NWKPCDPPI"
VARCHAR2(8), "NWKPCDBARCODE1TO7" VARCHAR2(7),
"NWKPCDBARCODE15" VARCHAR2(1), "NWKPCDBARCODESEQKEY"
VARCHAR2(7), "NWKPCDFILLER1" VARCHAR2(7), "NWKPCDFILLER2"
VARCHAR2(30))
TABLESPACE "WH1_DATA_LARGE" PCTFREE 10 PCTUSED 40 INITRANS 1
MAXTRANS 255
STORAGE ( INITIAL 4096K NEXT 4096K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
NOLOGGING
insert into wh1.nwkpcdrec_old select * from wh1.nwkpcdrec;
drop table wh1.nwkpcdrec;
CREATE TABLE "WH1"."NWKPCDREC" ("NWKPCDFILECODE" VARCHAR2(2),
"NWKPCDRECORDTYPE" VARCHAR2(4), "NWKPCDNETWORKID" VARCHAR2(2),
"NWKPCDOUTINWDPOSTCODE" VARCHAR2(7) NOT NULL,
"NWKPCDOUTWDPOSTCODE" VARCHAR2(4), "NWKPCDINWDPOSTCODE"
VARCHAR2(3), "NWKPCDSORTPOINT1CODE" VARCHAR2(2),
"NWKPCDSORTPOINT1TYPE" VARCHAR2(8), "NWKPCDSORTPOINT1NAME"
VARCHAR2(16), "NWKPCDSORTPOINT1EXTRA" VARCHAR2(16),
"NWKPCDSORTPOINT2TYPE" VARCHAR2(8), "NWKPCDSORTPOINT2NAME"
VARCHAR2(8), "NWKPCDSORTPOINT3TYPE" VARCHAR2(8),
"NWKPCDSORTPOINT3NAME" VARCHAR2(8), "NWKPCDSORTPOINT4TYPE"
VARCHAR2(8), "NWKPCDSORTPOINT4NAME" VARCHAR2(8), "NWKPCDPPI"
VARCHAR2(8), "NWKPCDBARCODE1TO7" VARCHAR2(7),
"NWKPCDBARCODE15" VARCHAR2(1), "NWKPCDBARCODESEQKEY"
VARCHAR2(7), "NWKPCDFILLER1" VARCHAR2(7), "NWKPCDFILLER2"
VARCHAR2(30))
TABLESPACE "WH1_DATA_LARGE" PCTFREE 10 PCTUSED 40 INITRANS 1
MAXTRANS 255
STORAGE ( INITIAL 4096K NEXT 4096K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
NOLOGGING
INSERT INTO WH1.NWKPCDREC SELECT
NWKPCDFILECODE,
NWKPCDRECORDTYPE,
NWKPCDNETWORKID,
rpad(nvl(nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(nwkpcdinwdpostcode, ' '), 3, ' '),
nwkpcdoutwdpostcode,
nwkpcdinwdpostcode,
NWKPCDSORTPOINT1CODE,
NWKPCDSORTPOINT1TYPE,
NWKPCDSORTPOINT1NAME,
NWKPCDSORTPOINT1EXTRA,
NWKPCDSORTPOINT2TYPE,
NWKPCDSORTPOINT2NAME,
NWKPCDSORTPOINT3TYPE,
NWKPCDSORTPOINT3NAME,
NWKPCDSORTPOINT4TYPE,
NWKPCDSORTPOINT4NAME,
NWKPCDPPI,
NWKPCDBARCODE1TO7,
NWKPCDBARCODE15,
NWKPCDBARCODESEQKEY,
NWKPCDFILLER1,
NWKPCDFILLER2
FROM WH1.NWKPCDREC_OLD;
CREATE UNIQUE INDEX "WH1"."UK_NWKPCDREC"
ON "WH1"."NWKPCDREC" ("NWKPCDNETWORKID",
"NWKPCDOUTINWDPOSTCODE")
TABLESPACE "WH1_INDEX" PCTFREE 10 INITRANS 2 MAXTRANS
255
STORAGE ( INITIAL 8192K NEXT 8192K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
LOGGING
begin
dbms_stats.gather_table_stats(ownname=> 'WH1', tabname=> 'NWKPCDREC', partname=> NULL);
end;
begin
dbms_stats.gather_index_stats(ownname=> 'WH1', indname=> 'UK_NWKPCDREC', partname=> NULL);
end;
SELECT decode(a.nwkpcdoutinwdpostcode, rpad(nvl(:zipout1, ' '), 4, ' ') ||
rpad(nvl(:zipin1, ' '), 3, ' '), '0001', rpad(nvl(:zipout2, ' '), 4, ' '
) || rpad(substr(nvl(:zipin2, ' '), 0, 1), 3, ' '), '0002', rpad(
nvl(:zipout3, ' '), 7, ' '), '0003', rpad('ZZ999', 7, ' '), '0004') AS
checker, a.nwkpcdbarcode1to7 nwkpcdbarcode1to7,
a.nwkpcdbarcode15 nwkpcdbarcode15,
a.nwkpcdbarcodeseqkey nwkpcdbarcodeseqkey,
a.nwkpcdsortpoint1code nwkpcdsortpoint1code,
a.nwkpcdsortpoint1type nwkpcdsortpoint1type,
a.nwkpcdsortpoint1name nwkpcdsortpoint1name,
a.nwkpcdsortpoint1extra nwkpcdsortpoint1extra,
a.nwkpcdsortpoint2type nwkpcdsortpoint2type,
a.nwkpcdsortpoint2name nwkpcdsortpoint2name,
a.nwkpcdsortpoint3type nwkpcdsortpoint3type,
a.nwkpcdsortpoint3name nwkpcdsortpoint3name,
a.nwkpcdsortpoint4type nwkpcdsortpoint4type,
a.nwkpcdsortpoint4name nwkpcdsortpoint4name,
b.nwkprfnetworksequence nwkprfnetworksequence,
b.nwkprfnetworkid nwkprfnetworkid, b.nwkprfnetworkname nwkprfnetworkname,
b.nwkprfminweight / 100 AS nwkprfminweight, b.nwkprfmaxweight / 100 AS
nwkprfmaxweight, b.nwkprfminlengthgirth nwkprfminlengthgirth,
b.nwkprfmaxlengthgirth nwkprfmaxlengthgirth,
b.nwkprfminlength nwkprfminlength, b.nwkprfmaxlength nwkprfmaxlength,
b.nwkprfparceltypecode nwkprfparceltypecode,
b.nwkprfparceltypename nwkprfparceltypename
FROM wh1.nwkpcdrec a, wh1.nwkprefrec b
WHERE a.nwkpcdnetworkid = b.nwkprfnetworkid
AND a.nwkpcdoutinwdpostcode IN (rpad(nvl(:zipout4, ' '), 4, ' ') ||
rpad(nvl(:zipin3, ' '), 3, ' '), rpad(nvl(:zipout5, ' '), 4, ' ')
|| rpad(substr(nvl(:zipin4, ' '), 0, 1), 3, ' '), rpad(nvl(:zipout6,
' '), 7, ' '), rpad('ZZ999', 7, ' '))
AND a.nwkpcdsortpoint1type != 'XXXXXXXX'
AND :weight1 >= b.nwkprfminweight
AND :weight2 <= b.nwkprfmaxweight
AND b.nwkprfminlengthgirth <= 60
AND b.nwkprfmaxlengthgirth >= 60
AND b.nwkprfminlength <= 15
AND b.nwkprfmaxlength >= 15
ORDER BY b.nwkprfnetworkid, checker
pre modified script/ -
SQL Query Help - Is this possible or impossible????
Hi guys,
I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
For example,
I have 2 tables
The first table is:
1) COMPANY create table company (manufacturer varchar2(25),
date_established date,
location varchar2(25) );My sample test date is:
insert into company values ('Ford', 1902, 'USA');
insert into company values ('BMW', 1910, 'Germany');
insert into company values ('Tata', 1922, 'India');The second table is:
2) MODELS create table models (manufacturer varchar(25),
model varchar2(25),
price number(10),
year date,
current_production_status varchar2(1) ) ;My sample test data is:
insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
insert into models values ('Ford', 'Galaxy', 12000, 2008, 0);
insert into models values ('Ford', 'Escort', 10000, 1992, 1);
insert into models values ('BMW', '318', 17500, 2010, 0);
insert into models values ('BMW', '535d', 32000, 2006, 0);
insert into models values ('BMW', 'Z4', 10000, 1992, 0);
insert into models values ('Tata', 'Safari', 4000, 1999, 0);
insert into models values ('Tata', 'Sumo', 5500, 1996, 1);
insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer IN ('Ford', 'BMW', 'Tata')
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCWhat I want the query to output is this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0
Tata 1922 India Sumo 5500 1998 1If current_production_status is 1 it means this particular model has been discontinued
If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
So the query should output the one row where current_production_status is 1 for each manufacturer.
If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
My query as it is above will output all the records where current status is 1 or 0 like this
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
Tata 1922 India Sumo 5500 1998 1
Ford 1902 USA - - - 0
Ford 1902 USA - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
Tata 1922 India - - - 0
Tata 1922 India - - - 0However this is not what I want.
Any ideas how I can achieve the result I need?
Thanks!
P.S. Database version is '10.2.0.1.0'Hi Vishnu,
Karthiks query helped...
But this is the problem I am facing...
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer = 'Ford'
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCThe value of:
and com.manufacturer = 'Ford'will be dependent on front end user input....
When I run the query above I get all the rows where current_production_status is either 1 or 0.
I only require the rows where current_production_status is 1.
So if I amend it to look like this:
and mod.current_production_status = 1This works....
BUT if a user now passes in more than one manufacturer EG:
and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
So like this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
Thanks you so much!
This is really driving me insane :-(
Maybe you are looking for
-
New to Fios: Schedules Recordings and DVR Capacity
I just gave up on RCN in lieu or Verizon Fios and thus far - can't stand the dvr. 1) The capacity is no where near what RCN's was. I had days worth of TV, movies, etc saved and never ran out of space. With Verizon, it's been less than a week and I`m
-
Database Error during installation of SAP NetWeaver 7.01 ABAP Trial Version
Hi All, I was installing the SAP NetWeaver 7.01 ABAP Trial Version but during the installation i got some MaxDB error. Log.txt (Apr 28, 2010 10:13:41 PM), Install, com.sap.installshield.maxdb.maxdb_call_sdbinst, err, An error occurred and product ins
-
Picking Multiple Files using File Adapter
Hi , I have two files in the Output folder with the names: Invoicedata InvoiceControl and FTP it to the FTP server with the same file name . if i use the source file name in the sender file adapter as invoice. .In the Receiver file adapter what i the
-
Artists not appearing on my ipod
Any idea why parts of my library can only be found on my ipod classic 80gb by song title and album, but not by artist? The song information correctly displays on my itunes library on my computer, but when it syncs to the ipod sometimes the artist won
-
Hi All, We have requirment to run some calc scripts in sequence as they are dependent. If we merge all the scripts in one script then due to dependency calculations are not done or not giving proper result. Is there any way so that calculation script