oracle数据库脚本
时间: 2023-11-15 16:08:39 浏览: 86
以下是Oracle数据库脚本的示例:
1. 创建表:
```
CREATE TABLE employees (
employee_id NUMBER(10) PRIMARY KEY,
first_name VARCHAR2(50),
last_name VARCHAR2(50),
email VARCHAR2(100),
hire_date DATE,
job_id VARCHAR2(50),
salary NUMBER(10,2),
commission_pct NUMBER(4,2),
manager_id NUMBER(10),
department_id NUMBER(10)
);
```
2. 插入数据:
```
INSERT INTO employees (employee_id, first_name, last_name, email, hire_date, job_id, salary, commission_pct, manager_id, department_id)
VALUES (1, 'John', 'Doe', 'jdoe@example.com', TO_DATE('01-JAN-20', 'DD-MON-YY'), 'MANAGER', 5000, NULL, NULL, 1);
INSERT INTO employees (employee_id, first_name, last_name, email, hire_date, job_id, salary, commission_pct, manager_id, department_id)
VALUES (2, 'Jane', 'Smith', 'jsmith@example.com', TO_DATE('01-JAN-20', 'DD-MON-YY'), 'SALES', 3000, 0.05, 1, 1);
```
3. 更新数据:
```
UPDATE employees SET salary = 5500 WHERE employee_id = 1;
```
4. 删除数据:
```
DELETE FROM employees WHERE employee_id = 2;
```
5. 创建索引:
```
CREATE INDEX emp_email_idx ON employees(email);
```
6. 创建视图:
```
CREATE VIEW emp_details AS
SELECT employee_id, first_name, last_name, email, hire_date, job_id, salary, commission_pct, manager_id, department_id
FROM employees;
```
7. 创建存储过程:
```
CREATE OR REPLACE PROCEDURE get_employee_details (
p_employee_id IN NUMBER,
p_details OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN p_details FOR
SELECT *
FROM employees
WHERE employee_id = p_employee_id;
END;
```
以上是一些Oracle数据库脚本的示例,可以根据具体需求进行修改和定制。
阅读全文