Select constant as a column : Select clause « Query Select « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL>
SQL> CREATE TABLE book(
  2    title_id   CHAR(3)      NOT NULL,
  3    title_name VARCHAR(40)  NOT NULL,
  4    type       VARCHAR(10)  NULL    ,
  5    pub_id     CHAR(3)      NOT NULL,
  6    pages      INTEGER      NULL    ,
  7    price      DECIMAL(5,2) NULL    ,
  8    sales      INTEGER      NULL    ,
  9    pubdate    DATE         NULL    ,
 10    contract   SMALLINT     NOT NULL
 11  );

Table created.

SQL>
SQL>
SQL>
SQL>
SQL> INSERT INTO book VALUES('T01','Java','history','P01',111,21.99,566,DATE '2000-08-01',1);

1 row created.

SQL> INSERT INTO book VALUES('T02','Oracle','history','P03', 114,19.95,9566,DATE '1998-04-01',1);

1 row created.

SQL> INSERT INTO book VALUES('T03','SQL','computer','P02', 122,39.95,25667,DATE '2000-09-01',1);

1 row created.

SQL> INSERT INTO book VALUES('T04','C++','psychology','P04', 511,12.99,13001,DATE '1999-05-31',1);

1 row created.

SQL> INSERT INTO book VALUES('T05','Python','psychology','P04', 101,6.95,201440,DATE '2001-01-01',1);

1 row created.

SQL> INSERT INTO book VALUES('T06','JavaScript','biography','P01', 173,19.95,11320,DATE '2000-07-31',1);

1 row created.

SQL> INSERT INTO book VALUES('T07','LINQ','biography','P03', 331,23.95,1500200,DATE '1999-10-01',1);

1 row created.

SQL> INSERT INTO book VALUES('T08','C#','children','P04', 861,10.00,4095,DATE '2001-06-01',1);

1 row created.

SQL> INSERT INTO book VALUES('T09','SQL Server','children','P04', 212,13.95,5000,DATE '2002-05-31',1);

1 row created.

SQL> INSERT INTO book VALUES('T10','AJAX','biography','P01', NULL,NULL,NULL,NULL,0);

1 row created.

SQL> INSERT INTO book VALUES('T11','VB','psychology','P04', 821,7.99,94123,DATE '2000-11-30',1);

1 row created.

SQL> INSERT INTO book VALUES('T12','Office','biography','P01', 507,12.99,100001,DATE '2000-08-31',1);

1 row created.

SQL> INSERT INTO book VALUES('T13','VBA','history','P03', 812,29.99,10467,DATE '1999-05-31',1);

1 row created.

SQL>
SQL>
SQL>
SQL> SELECT title_id,
  2         price,
  3         0.10 AS "Discount",
  4         price * (1 - 0.10) AS "New price"
  5    FROM book;

TIT      PRICE   Discount  New price
--- ---------- ---------- ----------
T01      21.99         .1     19.791
T02      19.95         .1     17.955
T03      39.95         .1     35.955
T04      12.99         .1     11.691
T05       6.95         .1      6.255
T06      19.95         .1     17.955
T07      23.95         .1     21.555
T08         10         .1          9
T09      13.95         .1     12.555
T10                    .1
T11       7.99         .1      7.191

TIT      PRICE   Discount  New price
--- ---------- ---------- ----------
T12      12.99         .1     11.691
T13      29.99         .1     26.991

13 rows selected.

SQL>
SQL> drop table book;

Table dropped.

SQL>








2.2.Select clause
2.2.1.Performing Single Table SELECT Statements
2.2.2.Select employee first and last and sort by last name
2.2.3.List single column from a table
2.2.4.Use as to specify the alias name
2.2.5.Use function in select clause
2.2.6.Use more than one aggregate functions in a select statement
2.2.7.where clause
2.2.8.Compare with number
2.2.9.Concatenate string
2.2.10.Select from a Subquery
2.2.11.Select constant as a column
2.2.12.Negate a column value
2.2.13.Math calculation in select statement
2.2.14.Search for String Across Columns
2.2.15.Don't Perform the Same Calculation Over and Over
2.2.16.NO_INDEX function in select statement