Oracle(持续更新)
Oracle数据库是一种流行的关系型数据库管理系统,被广泛应用于大型企业中。以下是一些常见的Oracle数据库操作和查询示例:
- 创建表:
CREATE TABLE Employees (
ID NUMBER PRIMARY KEY,
FirstName VARCHAR2(50),
LastName VARCHAR2(50),
BirthDate DATE,
Email VARCHAR2(100)
);
- 插入数据:
INSERT INTO Employees (ID, FirstName, LastName, BirthDate, Email)
VALUES (1, 'John', 'Doe', TO_DATE('1980-05-21', 'YYYY-MM-DD'), 'john.doe@example.com');
- 更新数据:
UPDATE Employees SET Email = 'newemail@example.com' WHERE ID = 1;
- 删除数据:
DELETE FROM Employees WHERE ID = 1;
- 查询数据:
SELECT * FROM Employees;
- 创建索引:
CREATE INDEX idx_lastname ON Employees(LastName);
- 创建视图:
CREATE VIEW EmployeesView AS
SELECT ID, FirstName, LastName FROM Employees;
- 创建存储过程:
CREATE OR REPLACE PROCEDURE UpdateEmployeeEmail(p_id IN NUMBER, p_email IN VARCHAR2) AS
BEGIN
UPDATE Employees SET Email = p_email WHERE ID = p_id;
END;
- 调用存储过程:
BEGIN
UpdateEmployeeEmail(1, 'updatedemail@example.com');
END;
- 创建触发器:
CREATE OR REPLACE TRIGGER Employees_Audit
AFTER INSERT OR UPDATE OR DELETE ON Employees
FOR EACH ROW
DECLARE
v_user VARCHAR2(100);
BEGIN
IF INSERTING THEN
v_user := 'INSERTED';
ELSIF UPDATING THEN
v_user := 'UPDATED';
ELSE
v_user := 'DELETED';
END IF;
INSERT INTO Employees_Audit (ID, Action) VALUES (:NEW.ID, v_user);
END;
这些操作和查询都是Oracle数据库操作的基础,可以根据实际需求进行修改和扩展。
评论已关闭