Sql rewrite help
I have a select statemnet like below.. it currently returns 3 rows. I want the the last value from this query below. so i want only "4" returned from this query. How to achieve it ? Thanks for the help.
SQL
SELECT col6
FROM TableA
WHERE col1=12
AND col2='B'
AND col3='001'
AND col4='455'
AND col5='666'
ORDER BY col1, col2, col3,col5, col4 desc
curent output
1
5
4
expected output
4
Etbin wrote:
Maybe NOT TESTED!
select col6
from (select col6,rownum rn
from (SELECT col6
FROM TableA
WHERE col1 = 12
AND col2 = 'B'
AND col3 = '001'
AND col4 = '455'
AND col5 = '666'
ORDER BY col1,col2,col3,col5,col4 desc
order by rn desc
where rownum = 1
Regards
Etbin
Hi,
Please correct me if I'm wrong, (I didn't test your solution ), but I think there could be a problem in your query which has the following form:
SELECT col6 -
FROM
SELECT col6, rownum rn -- 1st subquery
FROM
SELECT col6 -- 2nd subquery
FROM . . .
ORDER BY . . .
ORDER BY rn DESC
WHERE rownum = 1
The global query is a top-n-reporting so the order defined in "1st subquery" is conserved within the global query thanks to WHERE rownum = 1, however the order defined by the ORDER BY clause of the "2nd subquery" is not necessarily relevant inside "1st subquery" as there is no top-n structure at this level (inside 1st subquery). In otherwords rownum will not enumerate rows based on the order in the 2nd subquery that the OP defined, that is ORDER BY col1,col2,col3,col5,col4 desc,
Regards,
Dariyoosh
Similar Messages
-
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 guys
i have sample data as mentioned below... need to find the duplicate rows where cd=cd and dt1=dt1 and tm1 difference should be less than or equal to 4 hrs..
i can get the data with the query written below but my problem is that i am not allowed to use in-built sql server function... can you help me in writing the same without using in-built function...
CREATE TABLE #t (id INT,dt1 datetime, tm1 datetime,cd varchar(10))
INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:20:00.000','TC')
INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:30:00.000','TC')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 14:30:00.000','MN')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 09:07:00.000','XY')
INSERT INTO #t VALUES (101,'2013-11-27','1900-01-01 09:50:00.000','LM')
INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 15:07:00.000','XY')
select * From #t
WITH MyCTE (rn,id, dt1, tm1, cd)
AS(
select row_number() over (partition by id ORDER BY dt1, tm1) rn,* from #t
select case when ((dt1 = lead_start_Date) and (ct <='4.0') and (base_cd = lead_cd)) then 'Duplicate_Req' else '' end dt123,* from
select abs(convert(decimal(5,1),datediff(MI,lead_Start_time,tm1)/60.00)) ct, * from
SELECT base.rn b_rn,LEAd.rn l_rn,BASE.id
,BASE.dt1
,BASE.tm1
,base.cd base_cd
,LEAD.dt1 LEAD_START_DATE
,LEAD.tm1 LEAD_START_TIME
,lead.cd lead_cd
--,DATEADD(dd,-1,LEAD.dt1) EXPECTED_END_DATE
FROM MyCTE BASE
LEFT JOIN MyCTE LEAD ON BASE.id = LEAD.id
AND BASE.rn = LEAD.rn+1
) b
)cif this code will not work for you then not sure if there are any other options
Converted the CTE into an actual temp table.
CTE and barebones T-SQL code are included in the script below.
CREATE TABLE #t (id INT,dt1 datetime, tm1 datetime,cd varchar(10))
INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:20:00.000','TC')
INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:30:00.000','TC')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 14:30:00.000','MN')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 09:07:00.000','XY')
INSERT INTO #t VALUES (101,'2013-11-27','1900-01-01 09:50:00.000','LM')
INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 15:07:00.000','XY')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
select * From #t
;WITH MyCTE (rn,id, dt1, tm1, cd)
AS(
select row_number() over (partition by id ORDER BY dt1, tm1) rn,* from #t
select case when ((dt1 = lead_start_Date) and (ct <='4.0') and (base_cd = lead_cd)) then 'Duplicate_Req' else '' end dt123,* from
select abs(convert(decimal(5,1),datediff(MI,lead_Start_time,tm1)/60.00)) ct, * from
SELECT base.rn b_rn,LEAd.rn l_rn,BASE.id
,BASE.dt1
,BASE.tm1
,base.cd base_cd
,LEAD.dt1 LEAD_START_DATE
,LEAD.tm1 LEAD_START_TIME
,lead.cd lead_cd
--,DATEADD(dd,-1,LEAD.dt1) EXPECTED_END_DATE
FROM MyCTE BASE
LEFT JOIN MyCTE LEAD ON BASE.id = LEAD.id
AND BASE.rn = LEAD.rn+1
) b
)c
select * into #copy From #t order by id, cd, dt1, tm1
alter table #copy add seqno int identity(1,1)
select distinct y.id,y.cd,y.dt1,y.tm1,y.seqno,case when z.cd is not null then 'Duplicate_Req' else '' end dt123
from #copy y
left outer join
(select a.id,a.cd,a.dt1,a.tm1
From #copy a
left outer join #copy b
on a.id = b.id
and a.cd = b.cd
and a.dt1 = b.dt1
where a.seqno > b.seqno
and abs(datediff(MINUTE,b.tm1,a.tm1)) <= 240) z
on y.id = z.id
and y.cd = z.cd
and y.dt1 = z.dt1
and y.tm1 = z.tm1
order by y.dt1,y.tm1
drop table #copy
drop table #t -
I'm having trouble with an SQL query. I've created a simple logon page wherein a user will enter their user name and password. The program will look in an Access database for the user name, sort it by Date/Time modified, and check to see if their password matches the most recent password. Unfortunately, the query returns no results. I'm absolutely certain that I'm doing the query correctly (I've imported it directly from my old VB6 code). Something simple is eluding me. Any help would be appreciated.
private void LogOn() {
//make sure that the user name/password is valid, then load the main menu
try {
//open the database connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:LawOffice2000", "", "");
Statement select = con.createStatement();
String strTemp = "Select * From EMPLOYEES Where INITIALS = '" + txtUserName.getText() + "' Order By DATE Desc, TIME Desc";
ResultSet result = select.executeQuery(strTemp);
while(result.next()) {
if (txtPassword.getPassword().toString() == result.getString("Password")) {
MenuMain.main();
else {
System.out.println("Password Bad");
System.out.println(txtUserName.getText());
System.out.println(result.getString("Password"));
break; //exit loop
//close the connection
con.close(); }
catch (Exception e) {
System.out.println("LawOfficeSuite_LogOn: " + e);
return; }
}The problem is here: "txtPassword.getPassword().toString() == result.getString("Password"))"
Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same characters), use equals(), e.g. if (str1.equals(str2))...
Example:String s1 = "foo";
String s2 = new String("foo");
System.out.println("s1 == s2: " + (s1 == s2)); // false
System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out Comparison operators: equals() versus == -
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/ -
Oracle AS connect to MS SQL server - help please.
hi there
can anyone tell or show me how to connect Oracle app server to MS sql server? thanksHi Tom,
For stand-alone OC4J (any version), you need to add an appropriate entry to the "data-sources.xml" file (in the "j2ee/home/config" subdirectory) and put the JDBC driver file(s) into the "j2ee/home/lib" subdirectory. On my OC4J 9.0.3 distribution (on my Windows XP machine), there already is a "ms-sql.xml" file in the "j2ee/home/config/database-schemas" subdirectory. If you don't have one, then you may need to create one, or if you do already have one, you may need to modify it. More information can be found at these Web sites:
http://www.orionserver.com
http://www.orionsupport.com
http://www.atlassian.com
http://www.elephantwalker.com
Hope this helps you.
Good Luck,
Avi. -
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 :-( -
Hi All,
I have 2 tables like below. now i have a requirement which i need to do it in CASE OR DECODE. because i have to implement this logic IN SELECT STATEMENT for a column.
In table T1 if Lang = 1 and State = 'P' then display Lang = 'english' in table T2(which is Lang=2 in table T1) Or else display null.
Can we do this logic using CASE or DECODE? pls help
T1
Lang State
1 P
2 N
T2
Lang Dscr
1 central
2 englishSomething like this ?
SQL> ed
Wrote file afiedt.buf
1 WITH t1 AS (SELECT 1 lang, 'P' STATE FROM DUAL UNION ALL
2 SELECT 2 lang, 'N' STATE FROM DUAL
3 )
4 , t2 AS (SELECT 1 lang, 'central' dscr FROM DUAL UNION ALL
5 SELECT 2 lang, 'english' dscr FROM DUAL
6 )
7 SELECT t1.lang,t1.state,CASE
8 WHEN t1.lang=1 AND t1.state='P'
9 THEN (SELECT t2.lang FROM t2 WHERE dscr='english')
10 ELSE NULL
11 END "lang"
12* FROM t1
SQL> /
LANG S lang
1 P 2
2 N -
Parse XML in PL/SQL need help
Hi All,
I'm new to PL/SQL. I need to call a web service from within the PL/SQL and then need to parse the response XML. I was able to call the web service and now I have returned SOAP response XML in CLOB. I searched on google for way to parse this XML and create some kind of list or array or collection with all the values so that later on that collection or array can be used in displaying the data or storing the data, but I couldn't found the right information, rather I got very confused.
Please help me in parsing this XML and creating some kind collection or array for later use.
Thanks
XML is
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<getMemberResponse effectiveDate="1970-10-01" endDate="2010-12-31" xmlns="http://abc.org/schema/Member/GetMember/V1">
<responseHeader xmlns="http://abc.org/schema/common/v1">
<serviceVersion>2.0.1</serviceVersion>
<actionRequested AR="QUERY" xmlns:v1="http://abc.org/schema/Member/V1" xmlns:v11="http://abc.org/schema/common/v1" xmlns:v12="http://abc.org/schema/common/v1">
<v11:transactionName>GetMemberRequest</v11:transactionName>
</actionRequested>
<requestResults>
<resultStatus>Success</resultStatus>
<resultCodes>
<resultCode TYPE="HIPAA">00000</resultCode>
<resultCode TYPE="LEGACY">00000</resultCode>
<resultCode TYPE="SDI">00000</resultCode>
</resultCodes>
<resultMessage>Success</resultMessage>
</requestResults>
<accounting xmlns:v1="http://abc.org/schema/Member/V1" xmlns:v11="http://abc.org/schema/datatypes/v1" xmlns:v12="http://abc.org/schema/common/v1">
<transactionId>ec3542e7-3191-430c-bd69-69dd5d18bf75</transactionId>
<v12:timeStamp>2011-05-23T11:52:22</v12:timeStamp>
</accounting>
</responseHeader>
<requestID>ec3542e7-3191-430c-bd69-69dd5d18bf75</requestID>
<memberDetails xmlns:v1="http://abc.org/schema/Member/V1" xmlns:v11="http://abc.org/schema/datatypes/v1" xmlns:v12="http://abc.org/schema/common/v1">
<v1:ids>
<v1:id memberIdType="SSN">00000000</v1:id>
<v1:id memberIdType="PARTYID">111111</v1:id>
<v1:id memberIdType="PARTYNUMBER">222222</v1:id>
</v1:ids>
<v1:demographics>
<v1:memberDemographicType effDate="2010-05-09" maintType="UPDATE">
<v1:name>
<v1:nameDetails>
<v11:firstName>Keith</v11:firstName>
<v11:middleName>M</v11:middleName>
<v11:lastNames>
<v11:lastName>
<v11:name>Thompson</v11:name>
</v11:lastName>
</v11:lastNames>
<v11:formattedName>Keith M Thompson</v11:formattedName>
</v1:nameDetails>
<v1:createDate>2010-05-09T14:23:17</v1:createDate>
<v1:updateDate>2010-08-08T02:40:24</v1:updateDate>
</v1:name>
<v1:birthDate>1954-12-24</v1:birthDate>
<v1:genderTypeCode>Male</v1:genderTypeCode>
<v1:createDate>2010-05-09T14:23:17</v1:createDate>
<v1:updateDate>2010-08-08T02:40:24</v1:updateDate>
</v1:memberDemographicType>
</v1:demographics>
<v1:originalContractEffDate>2010-04-01</v1:originalContractEffDate>
<v1:addresses>
<v1:address maintType="QUERY">
<v1:location addresseeType="MEMBER" effDate="1901-01-01" endDate="9999-12-31" locationUseType="HOME" primaryPerType="Y">
<v11:addressLines>
<v11:addressLine>BAY VIEW AVENUE</v11:addressLine>
</v11:addressLines>
<v11:cityName>PLYMOUTH</v11:cityName>
<v11:stateCode>TX</v11:stateCode>
<v11:postalCode>58654</v11:postalCode>
</v1:location>
<v1:createDate>2011-05-23T11:52:22</v1:createDate>
<v1:updateDate>2011-05-23T11:52:22</v1:updateDate>
</v1:address>
<v1:address maintType="QUERY">
<v1:location addresseeType="SUBSCRIBER" effDate="1901-01-01" endDate="9999-12-31" locationUseType="HOME" primaryPerType="Y">
<v11:addressLines>
<v11:addressLine>AY VIEW AVENUE</v11:addressLine>
</v11:addressLines>
<v11:cityName>PLYMOUTH</v11:cityName>
<v11:stateCode>TX</v11:stateCode>
<v11:postalCode>58654</v11:postalCode>
</v1:location>
<v1:createDate>2011-05-23T11:52:22</v1:createDate>
<v1:updateDate>2011-05-23T11:52:22</v1:updateDate>
</v1:address>
</v1:addresses>
<v1:policies>
<v1:policy effDate="2010-04-01" maintType="ADD" type="MEMBER">
<v1:ids>
<v1:id type="MEMBERID">CPIT000456</v1:id>
<v1:id type="POLICY">CPIT</v1:id>
</v1:ids>
<v1:contractType>F</v1:contractType>
<v1:dependentType>01</v1:dependentType>
<v1:offerings>
<v1:offering offeredBy="abc" offeringIdType="INSURANCE_TYPE" selected="Y">
<v1:offeringId>IV</v1:offeringId>
</v1:offering>
<v1:offering effDate="2010-04-01" maintType="ADD" offeredBy="abc" offeringIdType="BOC" selected="Y">
<v1:offeringId>GK</v1:offeringId>
<v1:recordInfo>
<v1:internalRecId>82326287</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-09T14:23:17</v1:createDate>
<v1:updateDate>2010-05-09T14:23:17</v1:updateDate>
</v1:offering>
</v1:offerings>
<v1:customer>
<v1:relation type="EMPLOYMENT">
<v1:customer>
<v1:id idType="ACCOUNTID">C11204</v1:id>
<v1:id idType="DIVISION">0208290000</v1:id>
<v1:customerName>BC Group</v1:customerName>
</v1:customer>
</v1:relation>
</v1:customer>
<v1:physicianRelations>
<v1:physicianRelation effDate="2010-04-01" endDate="9999-12-31" type="PCP">
<v1:ids>
<v1:id type="NPI">0</v1:id>
<v1:id type="AFFILIATIONID">1313 0025</v1:id>
<v1:id type="PROVIDERID">1313</v1:id>
<v1:id type="TIN">0</v1:id>
</v1:ids>
<v1:recordInfo>
<v1:internalRecId>98151812</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-10-23T01:10:13</v1:createDate>
<v1:updateDate>2010-10-23T01:10:13</v1:updateDate>
</v1:physicianRelation>
</v1:physicianRelations>
<v1:maintainReasonCode>AC</v1:maintainReasonCode>
<v1:recordInfo>
<v1:internalRecId>82326286</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-09T14:23:17</v1:createDate>
<v1:updateDate>2010-05-09T14:23:17</v1:updateDate>
</v1:policy>
<v1:policy effDate="2010-04-01" maintType="QUERY" type="SUBSCRIBER">
<v1:ids>
<v1:id type="POLICY">CPIT</v1:id>
</v1:ids>
<v1:hashCode>82326284</v1:hashCode>
<v1:contractType>F</v1:contractType>
<v1:maritalStatus>UNKNOWN</v1:maritalStatus>
<v1:offerings>
<v1:offering effDate="2010-04-01" maintType="QUERY" offeredBy="abc" offeringIdType="INSURANCE_TYPE" selected="Y">
<v1:offeringId>IV</v1:offeringId>
<v1:recordInfo>
<v1:internalRecId>82326285</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-09T14:23:17</v1:createDate>
<v1:updateDate>2011-01-20T04:53:52</v1:updateDate>
</v1:offering>
</v1:offerings>
<v1:customer>
<v1:relation type="EMPLOYMENT">
<v1:customer>
<v1:id idType="ACCOUNTID">C11204</v1:id>
<v1:id idType="DIVISION">0208290000</v1:id>
<v1:customerName>BC Group</v1:customerName>
</v1:customer>
</v1:relation>
</v1:customer>
<v1:maintainReasonCode>AC</v1:maintainReasonCode>
<v1:recordInfo>
<v1:internalRecId>82326284</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-09T14:23:17</v1:createDate>
<v1:updateDate>2011-01-20T04:53:52</v1:updateDate>
</v1:policy>
</v1:policies>
<v1:recordInfo>
<v1:internalRecId>8364745</v1:internalRecId>
<v1:objectVersionNo>1</v1:objectVersionNo>
</v1:recordInfo>
<v1:restrictedMemberIndicator>N</v1:restrictedMemberIndicator>
<v1:createDate>2010-05-09T14:23:17</v1:createDate>
<v1:updateDate>2010-08-08T02:40:24</v1:updateDate>
</memberDetails>
</getMemberResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>Hi A_Non,
Thanks so much for giving me the hint about that "text()" in XPath.
I have new question for you with same XML I'm parsing right now.
I have extracted a part(Policies) of whole XML and put it in one XMLTYPE variable. Below is that part XML.
My question is I need to look only into that policy which is active right now. In the <policy> tag there are two attributes "effDate" and "endDate". "effDate" tag will always be there for every policy and for all inactive policies also "endDate" will be there always. Problem is with the active ones, "endDate" may or may not be there. If "endDate" is there so it will be greater than or equal to sysdate and if it is not there that means it is open ended. I need to fetch only that policy which is active right now and if there is no tag as such that means member is not active as of today.
If "endDate" attribute is there then I think below XPath will work, but I'm not sure about how to handle when "endDate" attribute is not there.
/d:policies/d:policy[@type="MEMBER" and number(translate(@effDate,"-",""))<=number(translate("'||l_currDate||'","-","")) and number(translate(@endDate,"-",""))>=number(translate("'||l_currDate||'","-",""))]I have Oracle 10.1.0.4, in this in XPath comparison operators are not working so I'm using XPath functions.
Here is the XML
<v1:policies>
<v1:policy effDate="1999-05-01" endDate="1999-12-31" maintType="ADD" type="MEMBER">
<v1:ids>
<v1:id type="MEMBERID">SDF000414600</v1:id>
<v1:id type="POLICY">SDF0004146</v1:id>
</v1:ids>
<v1:contractType>F</v1:contractType>
<v1:dependentType>01</v1:dependentType>
<v1:offerings>
<v1:offering offeredBy="ABC" offeringIdType="INSURANCE_TYPE" selected="Y">
<v1:offeringId>IH</v1:offeringId>
</v1:offering>
<v1:offering effDate="1999-05-01" endDate="1999-12-31" maintType="ADD" offeredBy="ABC" offeringIdType="BOC" selected="Y">
<v1:offeringId>HA</v1:offeringId>
<v1:recordInfo>
<v1:internalRecId>39077481</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-01T01:27:04</v1:createDate>
<v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
</v1:offering>
</v1:offerings>
<v1:customer>
<v1:relation type="EMPLOYMENT">
<v1:customer>
<v1:id idType="ACCOUNTID">AS35423</v1:id>
<v1:id idType="DIVISION">0621730000</v1:id>
<v1:customerName>Medical Associates</v1:customerName>
</v1:customer>
</v1:relation>
</v1:customer>
<v1:physicianRelations>
<v1:physicianRelation effDate="1999-05-01" endDate="1999-12-31" type="PCP">
<v1:ids>
<v1:id type="NPI">0</v1:id>
<v1:id type="AFFILIATIONID">66759 0014</v1:id>
<v1:id type="PROVIDERID">231231</v1:id>
<v1:id type="TIN">0</v1:id>
</v1:ids>
<v1:recordInfo>
<v1:internalRecId>87796651</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-10-22T21:56:44</v1:createDate>
<v1:updateDate>2010-10-22T21:56:44</v1:updateDate>
</v1:physicianRelation>
</v1:physicianRelations>
<v1:maintainReasonCode>MD</v1:maintainReasonCode>
<v1:recordInfo>
<v1:internalRecId>39077480</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-01T01:27:04</v1:createDate>
<v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
</v1:policy>
<v1:policy effDate="2000-01-01" endDate="2000-12-31" maintType="ADD" type="MEMBER">
<v1:ids>
<v1:id type="MEMBERID">SDF000414600</v1:id>
<v1:id type="POLICY">SDF0004146</v1:id>
</v1:ids>
<v1:contractType>F</v1:contractType>
<v1:dependentType>01</v1:dependentType>
<v1:offerings>
<v1:offering offeredBy="ABC" offeringIdType="INSURANCE_TYPE" selected="Y">
<v1:offeringId>IH</v1:offeringId>
</v1:offering>
<v1:offering effDate="2000-01-01" endDate="2000-12-31" maintType="ADD" offeredBy="ABC" offeringIdType="BOC" selected="Y">
<v1:offeringId>HA</v1:offeringId>
<v1:recordInfo>
<v1:internalRecId>39077483</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-01T01:27:04</v1:createDate>
<v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
</v1:offering>
</v1:offerings>
<v1:customer>
<v1:relation type="EMPLOYMENT">
<v1:customer>
<v1:id idType="ACCOUNTID">C35423</v1:id>
<v1:id idType="DIVISION">0621730000</v1:id>
<v1:customerName>Medical Associates</v1:customerName>
</v1:customer>
</v1:relation>
</v1:customer>
<v1:physicianRelations>
<v1:physicianRelation effDate="2000-01-01" endDate="2000-12-31" type="PCP">
<v1:ids>
<v1:id type="NPI">0</v1:id>
<v1:id type="AFFILIATIONID">66759 0014</v1:id>
<v1:id type="PROVIDERID">3213213</v1:id>
<v1:id type="TIN">0</v1:id>
</v1:ids>
<v1:recordInfo>
<v1:internalRecId>87796652</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-10-22T21:56:44</v1:createDate>
<v1:updateDate>2010-10-22T21:56:44</v1:updateDate>
</v1:physicianRelation>
</v1:physicianRelations>
<v1:maintainReasonCode>MD</v1:maintainReasonCode>
<v1:recordInfo>
<v1:internalRecId>39077482</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-01T01:27:04</v1:createDate>
<v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
</v1:policy>
<v1:policy effDate="2001-01-01" maintType="ADD" type="MEMBER">
<v1:ids>
<v1:id type="MEMBERID">SDF000414600</v1:id>
<v1:id type="POLICY">SDF0004146</v1:id>
</v1:ids>
<v1:contractType>F</v1:contractType>
<v1:dependentType>01</v1:dependentType>
<v1:offerings>
<v1:offering offeredBy="ABC" offeringIdType="INSURANCE_TYPE" selected="Y">
<v1:offeringId>IH</v1:offeringId>
</v1:offering>
<v1:offering effDate="2001-01-01" endDate="2001-03-31" maintType="ADD" offeredBy="ABC" offeringIdType="BOC" selected="Y">
<v1:offeringId>HC</v1:offeringId>
<v1:recordInfo>
<v1:internalRecId>39077485</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-01T01:27:04</v1:createDate>
<v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
</v1:offering>
</v1:offerings>
<v1:customer>
<v1:relation type="EMPLOYMENT">
<v1:customer>
<v1:id idType="ACCOUNTID">C35423</v1:id>
<v1:id idType="DIVISION">0621730000</v1:id>
<v1:customerName>Medical Associates</v1:customerName>
</v1:customer>
</v1:relation>
</v1:customer>
<v1:physicianRelations>
<v1:physicianRelation effDate="2001-01-01" endDate="2001-03-31" type="PCP">
<v1:ids>
<v1:id type="NPI">0</v1:id>
<v1:id type="AFFILIATIONID">66759 0014</v1:id>
<v1:id type="PROVIDERID">61232132</v1:id>
<v1:id type="TIN">0</v1:id>
</v1:ids>
<v1:recordInfo>
<v1:internalRecId>87796653</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-10-22T21:56:44</v1:createDate>
<v1:updateDate>2010-10-22T21:56:44</v1:updateDate>
</v1:physicianRelation>
</v1:physicianRelations>
<v1:maintainReasonCode>LE</v1:maintainReasonCode>
<v1:recordInfo>
<v1:internalRecId>39077484</v1:internalRecId>
</v1:recordInfo>
<v1:createDate>2010-05-01T01:27:04</v1:createDate>
<v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
</v1:policy>
</v1:policies>Thanks
Maybe you are looking for
-
How can I click Acrobat Form button from VB (Excel Macro)?
I may be asking in the wrong forum, but I'm at my wit's end and think just about anyone with VB experience would be able to tell me what I'm doing wrong. Is there a forum for interapplication/ VB/ forms questions? Suffice to say, I know very little a
-
Hi i have created a report, which has some account dimensions and it has 11 level as default hierarchy i need to show from level 04 in my report , so i have taken level 04 and rest of the levels in query and enabled the drill option, now what happens
-
I have uninstalled any cookie management extensions that were supposed to manage cookies. Any ideas?
-
Why is Merge Selected greyed out?
I am working with a file with many many sub layers and illustrator is running really slow and keeps crashing. I want to merge many of the sublayers into one layer to save space and help simplify the file, But after I select the layers the Merge Sel
-
My ipod touch has died. i tried charging but nothing. any sugestions?
my ipod touch has died. i trued charging but noyhing any sugestions?