Use of Case

zhaozj2021-02-16  85

E: / Oracle / ORA92 / DATABASE> SQLPLUS / NOLOG

SQL * Plus: Release 9.2.0.1.0 - Production on Friday January 25 11:22:16 2002

CopyRight (C) 1982, 2002, Oracle Corporation. All Rights Reserved.

SQL> Conn Lunar / Lunar is connected. SQL> Create Table Testcase 2 (a char (6), 3 B Number (10), 4 C Char (9), 5 D Number (10, 2), 6 E CHAR (20));

The table has been created.

SQL> INSERT INTO TESTCASE VALUES ('AA', 110, 'Hello', 100.2, 'ABC');

It has created a row.

SQL> INSERT INTO TESTCASE VALUES ('bb', 200, 'everyone is good', 120.25, 'abcde');

It has created a row.

SQL> INSERT INTO TESTCASE VALUES ('CC', 150, 'Peace', 50.9, 'XYZ');

It has created a row.

SQL> INSERT INTO TESTCASE VALUES ('DD', 170, 'Peace', 200, 'RST');

It has created a row.

SQL> INSERT INTO TESTCASE VALUES ('EE', 10, 'Ministry of Public Security ", 21,' MORNING ');

It has created a row.

SQL> commit;

Submitted.

SQL> SELECT * from Testcase;

A bc d e ------------------------------- --------- AA 110 Hello 100.2 ABCBB 200 Good 120.25 ABCDECC 150 Peace 50.9 XYZDD 170 Peace 200 RStee 10 Ministry of Public Security 21 Morning

SQL>

SELECT A, B, (Case WHEN B> 150 THEN 'greater than 150' When B = 150 THEN 'equal to 150' WHEN B <150 THEN 'less than 150' else 'Enter error' end) AS C, D, EFROM TestCase /

SQL> SELECT A, B, (Case WHEN B> 150 THEN 'greater than 150' 2 when b = 150 THEN 'is equal to 150' 3 WHEN B <150 THEN 'less than 150' 4 else 'Enter error' 5 end) AS C, D, E 6 from testcase 7 /

A bc d e -------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------ AA 110 less than 150 100.2 ABCBB 200 greater than 150 120.25 Abcdecc 150 equal to 150 50.9 XYZDD 170 greater than 150 200 RStee 10 less than 150 21 Morningsql>

SQL> ALTER TABLE TESTCASE ADD F CHAR (9);

The table has been changed.

SQL> DESC TESTCASE; is the name is empty? Type --------------------------------------- - - -------- -------------------

A char (6) b Number (10) C Char (9) D Number (10, 2) e char (20) f char (9)

SQL>

转载请注明原文地址:https://www.9cbs.com/read-13915.html

New Post(0)