ORACLE数据库 —— SQL知识点1
在Oracle数据库中,SQL是结构化查询语言的缩写,它是使用关系型数据库的标准语言。以下是一些基本的SQL知识点和示例代码:
- 创建表:
CREATE TABLE employees (
id NUMBER PRIMARY KEY,
name VARCHAR2(50),
job_title VARCHAR2(50),
salary NUMBER(8, 2),
manager_id NUMBER,
hire_date DATE
);
- 插入数据:
INSERT INTO employees (id, name, job_title, salary, manager_id, hire_date)
VALUES (1, 'John Doe', 'Software Developer', 90000, NULL, TO_DATE('2010-01-01', 'YYYY-MM-DD'));
- 查询数据:
SELECT name, salary FROM employees WHERE job_title = 'Software Developer';
- 更新数据:
UPDATE employees SET salary = salary + 1000 WHERE name = 'John Doe';
- 删除数据:
DELETE FROM employees WHERE name = 'John Doe';
- 创建索引:
CREATE INDEX idx_employee_name ON employees(name);
- 创建视图:
CREATE VIEW active_employees AS
SELECT id, name, job_title FROM employees WHERE hire_date > SYSDATE - INTERVAL '1' YEAR;
- 使用连接(JOIN):
SELECT e.name, d.department_name
FROM employees e
JOIN departments d ON e.department_id = d.id;
- 使用分组和聚合函数:
SELECT job_title, AVG(salary) AS average_salary
FROM employees
GROUP BY job_title;
- 使用子查询:
SELECT name
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
这些是SQL的基本操作,在实际数据库操作中会经常用到。
评论已关闭