以下是一些Oracle数据库增删改查的例题:
例题1:
假设有一个名为employees
的表,结构如下:
CREATE TABLE employees ( id NUMBER PRIMARY KEY, name VARCHAR2(50), age NUMBER, department VARCHAR2(50) );
- 插入一条记录:
INSERT INTO employees (id, name, age, department) VALUES (1, 'John Doe', 30, 'HR');
- 查询所有记录:
SELECT * FROM employees;
- 查询年龄大于等于30岁的员工:
SELECT * FROM employees WHERE age >= 30;
- 更新部门为’IT’的员工信息:
UPDATE employees SET department = 'IT' WHERE department = 'HR';
- 删除id为2的员工记录:
DELETE FROM employees WHERE id = 2;
例题2:
假设有一个名为products
的表,结构如下:
CREATE TABLE products ( id NUMBER PRIMARY KEY, name VARCHAR2(100), price NUMBER, quantity NUMBER );
- 插入一条记录:
INSERT INTO products (id, name, price, quantity) VALUES (1, 'Laptop', 1000, 50);
- 查询所有产品价格:
SELECT price FROM products;
- 查询价格大于500的产品:
SELECT * FROM products WHERE price > 500;
- 更新产品数量为100:
UPDATE products SET quantity = 100 WHERE quantity = 50;
- 删除id为1的产品记录:
DELETE FROM products WHERE id = 1;
这些例题涵盖了Oracle数据库的基本增删改查操作。通过练习这些题目,可以加深对Oracle数据库的理解和掌握。