Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: A SQL Question

Re: A SQL Question

From: Igor Neyman <ineyman_at_perceptron.com>
Date: Thu, 13 Mar 2003 06:09:15 -0800
Message-ID: <F001.00568CDB.20030313060915@fatcity.com>


Kirti,

I think, you have typo (duplicate rows), when describing data inserted into table, considering PK on (col1, col2).
Shouldn't it be:

SQLWKS> create table test(
     2>  col1 varchar2(10),
     3>  col2 varchar2(10),
     4>  constraint PK_TEST primary key (col1, col2));
Statement processed.
SQLWKS>
SQLWKS> insert into test (col1, col2) values ('A', 'B'); 1 row processed.
SQLWKS> insert into test (col1, col2) values ('C', 'D'); 1 row processed.
SQLWKS> insert into test (col1, col2) values ('E', 'F'); 1 row processed.
SQLWKS> insert into test (col1, col2) values ('G', 'H'); 1 row processed.
SQLWKS> insert into test (col1, col2) values ('B', 'A'); 1 row processed.
SQLWKS> insert into test (col1, col2) values ('F', 'E'); 1 row processed.
SQLWKS> insert into test (col1, col2) values ('D', 'C'); 1 row processed.
SQLWKS> insert into test (col1, col2) values ('H', 'G'); 1 row processed.
SQLWKS> commit;
Statement processed.
SQLWKS>
SQLWKS> select * from test;
COL1 COL2
---------- ----------
A          B
C          D
E          F
G          H
B          A
F          E
D          C
H          G

8 rows selected.

SQLWKS> select * from test order by col1; COL1 COL2
---------- ----------

A          B
B          A
C          D
D          C
E          F
F          E
G          H
H          G

8 rows selected.

Igor Neyman, OCP DBA
ineyman_at_perceptron.com

> Hi SQL Developers,
>
> I have a table as follows:
>
> Col1 Col2
> ----------------
> A B
> C D
> E F
> G H
> B A
> E F
> C D
> H G
>
> With a PK on (Col1, Col2).
>
> How do I write a SQL script to get following result?
>
> Col1 Col2
> --------------------
> A B
> B A
> C D
> D C
> E F
> F E
> G H
> H G
>
> Thanks for your help.
>
> - Kirti
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> --
> Author: Deshpande, Kirti
> INET: kirti.deshpande_at_verizon.com
>
> Fat City Network Services -- 858-538-5051 http://www.fatcity.com
> San Diego, California -- Mailing list and web hosting services
> ---------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
>
>

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Igor Neyman
  INET: ineyman_at_perceptron.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Thu Mar 13 2003 - 08:09:15 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US