联合查询的字段名称及排序考点(附加闪回知识点)

来源:互联网 发布:大数据的起源是什么 编辑:程序博客网 时间:2024/06/06 02:24


create table CUSTOMERS
(
  CUST_ID        NUMBER(5),
  CUST_LAST_NAME VARCHAR2(10),
  COUNTRY_ID     NUMBER(5)
);

insert into CUSTOMERS (CUST_ID, CUST_LAST_NAME, COUNTRY_ID)
values (1, 'jane', 10);
insert into CUSTOMERS (CUST_ID, CUST_LAST_NAME, COUNTRY_ID)
values (2, 'hanmeimei', 20);
insert into CUSTOMERS (CUST_ID, CUST_LAST_NAME, COUNTRY_ID)
values (3, 'lily', 30);
commit;

SELECT * FROM  customers;



SELECT cust_id,cust_last_name "Last Name"
FROM customers
WHERE country_id=10
UNION
SELECT cust_id cust_no,cust_last_name
FROM customers ActualTests
WHERE country_id=30
ORDER BY 2,1;


SELECT cust_id,cust_last_name "Last Name"
FROM customers
WHERE country_id=10
UNION
SELECT cust_id cust_no,cust_last_name
FROM customers ActualTests
WHERE country_id=30
ORDER BY 2,cust_id;


SELECT cust_id,cust_last_name "Last Name"
FROM customers
WHERE country_id=10
UNION
SELECT cust_id cust_no,cust_last_name
FROM customers ActualTests
WHERE country_id=30
ORDER BY "Last Name";

以上三个的结果都是:


SELECT cust_id,cust_last_name "Last Name"
FROM customers
WHERE country_id=10
UNION
SELECT cust_id cust_no,cust_last_name
FROM customers ActualTests
WHERE country_id=30
ORDER BY cust_no;


SELECT cust_id,cust_last_name "Last Name"
FROM customers
WHERE country_id=10
UNION
SELECT cust_id cust_no,cust_last_name
FROM customers ActualTests
WHERE country_id=30

ORDER BY "cust_no";

以上两个的结果都是:




DROP TABLE customers;

SELECT * FROM  customers;



FLASHBACK table customers to before drop;

SELECT * FROM  customers;


alter table customers DISABLE row movement;(系统原本是开启的,我修改成不可用以便进行测试)
UPDATE customers SET cust_last_name='lilei' WHERE cust_id=2;

COMMIT;
flashback table customers to TIMESTAMP systimestamp - interval '2' minute;


SELECT * FROM  customers;


alter table customers enable row movement; (闪回表必须要开启行移动功能!)
UPDATE customers SET cust_last_name='hanmeimei' WHERE cust_id=2;

COMMIT;
flashback table customers to TIMESTAMP systimestamp - interval '1' minute;

SELECT * FROM  customers;




DROP TABLE customers;

select * from user_recyclebin;


FLASHBACK table customers to before drop;
drop table customers purge;
FLASHBACK table customers to before drop;





0 0
原创粉丝点击