oracle常用代码
时间: 2023-12-07 11:01:28 浏览: 75
Oracle常用代码包括创建表、插入数据、更新数据、删除数据、创建索引、创建视图、创建存储过程等。例如,创建表的代码如下:
```
CREATE TABLE employees(
employee_id NUMBER(6),
first_name VARCHAR2(20),
last_name VARCHAR2(25),
email VARCHAR2(25),
phone_number VARCHAR2(20),
hire_date DATE,
job_id VARCHAR2(10),
salary NUMBER(8, 2),
commission_pct NUMBER(2, 2),
manager_id NUMBER(6),
department_id NUMBER(4)
);
```
插入数据的代码如下:
```
INSERT INTO employees
(employee_id, first_name, last_name, email, hire_date, job_id, salary, department_id)
VALUES
(100, 'Steven', 'King', 'steven.king@company.com', '17-JUN-03', 'AD_PRES', 24000, 90);
```
更新数据的代码如下:
```
UPDATE employees
SET salary = 25000
WHERE employee_id = 100;
```
删除数据的代码如下:
```
DELETE FROM employees
WHERE employee_id = 100;
```
创建索引的代码如下:
```
CREATE INDEX emp_name_idx
ON employees (last_name, first_name);
```
创建视图的代码如下:
```
CREATE VIEW emp_details AS
SELECT employee_id, first_name, last_name, salary
FROM employees;
```
创建存储过程的代码如下:
```
CREATE PROCEDURE raise_salary (emp_id IN NUMBER, amount IN NUMBER) AS
BEGIN
UPDATE employees
SET salary = salary + amount
WHERE employee_id = emp_id;
END raise_salary;
```
以上是一些Oracle常用的代码示例,可以根据具体需求进行调整和扩展。
阅读全文