在Oracle中插入常量值

时间:2018-10-11 06:48:49

标签: oracle11g

如何在oracle的单个语句中插入常量值?

类似于,我们可以在MSSQL Server中实现。.

CREATE TABLE grade
(
  names varchar(1),
  grade int
)
-- insert data
INSERT INTO grade
VALUES ('A',100),('B',90),('C',80),('D',70),('E',70),('F',60)

谢谢

1 个答案:

答案 0 :(得分:1)

SQL Fiddle

Oracle 11g R2架构设置

CREATE TABLE grade
(
  names varchar2(1),
  grade int
);

只需使用普通的INSERT语句:

INSERT INTO grade ( names, grade )
  SELECT 'A',100 FROM DUAL UNION ALL
  SELECT 'B', 90 FROM DUAL UNION ALL
  SELECT 'C', 80 FROM DUAL UNION ALL
  SELECT 'D', 70 FROM DUAL UNION ALL
  SELECT 'E', 60 FROM DUAL UNION ALL
  SELECT 'F', 50 FROM DUAL;

或者:

INSERT INTO grade ( names, grade ) VALUES ( 'A', 100 );
INSERT INTO grade ( names, grade ) VALUES ( 'B',  90 );
INSERT INTO grade ( names, grade ) VALUES ( 'C',  80 );
INSERT INTO grade ( names, grade ) VALUES ( 'D',  70 );
INSERT INTO grade ( names, grade ) VALUES ( 'E',  60 );
INSERT INTO grade ( names, grade ) VALUES ( 'F',  50 );

如果您希望它们不可修改,则可以将表设置为READ ONLY

ALTER TABLE grade READ ONLY;

查询1

SELECT * FROM grade

Results

| NAMES | GRADE |
|-------|-------|
|     A |   100 |
|     B |    90 |
|     C |    80 |
|     D |    70 |
|     E |    60 |
|     F |    50 |