Oracle中for update 在PL/SQL中使用

对于很多学习了MYSQL的小伙伴突然使用Oracle可能会有一些不熟悉.

在MYSQL中使用中,大家可以在可视化工具中直接对数据进行修改,但在Oracle中却不行,下面我们介绍在Oracle中对于数据修改操作.

数据库:Oracle

可视化工具:PL/SQL

以下面代码为例:

select * from 表 a where a.字段名 in('查询条件');

这是我们一般在MYSQL中使用sql进行查询的语句

在Oracle中我们可以使用 for update;

则以上sql 修改为:

                select * from 表 a where a.字段名 in('查询条件') for update;

F8执行

会出现我们要查询的数据

下面我们点击数据左上角位置"编辑数据"图标,即可对数据进行编辑

编辑之后点击"编辑数据"图标右侧"记入改变"图标,并点击PL/SQL左上角"提交"图标,或者F10,即可保存修改之后的数据.

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
作者:Steven Feuerstein, Bill Pribyl 出版日期:October 1, 2009 出版社:O'Reilly 页数:1226 ISBN:ISBN-10: 0596514468 ISBN-13: 978-0596514464 文件格式:PDF 文件大小:15.06 MB Review If you’re doing database application development in the Oracle environment, you’re going to have to know PL/SQL, the company’s extended query and update language. If you want your programs to exploit the special capabilities of Oracle software, you’ll need to know the language well. That’s where the third edition of Oracle PL/SQL Programming comes into play. It’s an absolutely comprehensive reference (as well as a rather extensive tutorial) on PL/SQL, ideally suited to answering your questions about how to perform some programming tasks and reminding you of the characteristics of functions, triggers, and other elements of the database programmer’s toolkit. The new edition covers calls to Java methods from within PL/SQL programs, autonomous transactions, object type inheritance, and the new Timestamp and XMLType data types. There’s also more information about server internals–the way PL/SQL programs are run–than before, better enabling readers to optimize their code for fast and safe execution. Steven Feuerstein takes care to explain, with prose and example code, the characteristics of PL/SQL elements. In explaining number conversions, for example, he explores Oracle’s different ways of formatting numbers, then details the behavior of the to_number function under different conditions (with and without a specified format model, and with National Language Support information attached). It’s a helpful approach that will have readers using the index to locate places in which Feuerstein mentions language elements of interest. –David Wall Topics covered: How to use Oracle PL/SQL in all its manifestations through Oracle9i. Fundamentals of program structure (loops, cases, exceptions, etc.) and execution get attention, as do data types, transaction management, triggers, and the object-oriented aspects of the language. There’s also coverage of calls to external Java and C programs. –This text refers to the Paperback edition. Product Description This book is the definitive reference on PL/SQL, considered throughout the database community to be the best Oracle programming book available. Like its predecessors, this fifth edition of Oracle PL/SQL Programming covers language fundamentals, advanced coding techniques, and best practices for using Oracle’s powerful procedural language. Thoroughly updated for Oracle Database 11g Release 2, this edition reveals new PL/SQL features and provides extensive code samples, ranging from simple examples to complex and complete applications, in the book and on the companion website. This indispensable reference for both novices and experienced Oracle programmers will help you: Get PL/SQL programs up and running quickly, with clear instructions for executing, tracing, testing, debugging, and managing PL/SQL code Optimize PL/SQL performance with the aid of a brand-new chapter in the fifth edition Explore datatypes, conditional and sequential control statements, loops, exception handling, security features, globalization and localization issues, and the PL/SQL architecture Understand and use new Oracle Database 11g features, including the edition-based redefinition capability, the function result cache, the new CONTINUE statement, fine-grained dependency tracking, sequences in PL/SQL expressions, supertype invocation from subtypes, and enhancements to native compilation, triggers, and dynamic SQL Use new Oracle Database 11g tools and techniques such as PL/Scope, the PL/SQL hierarchical profiler, and the SecureFiles technology for large objects Build modular PL/SQL applications using procedures, functions, triggers, and packages
好的,以下是一个 Oracle PL/SQL 的 INSTEAD OF 触发器示例: 假设我们有一个名为 `employees` 的表和一个名为 `employees_log` 的表。我们想要在 `employees` 表上进行一些操作时,自动将相应的日志信息插入到 `employees_log` 表。我们可以使用 INSTEAD OF 触发器来实现这一点。 首先,我们需要创建一个 `employees_log` 表,用于存储日志信息。可以使用以下 SQL 语句创建这个表: ```sql CREATE TABLE employees_log ( id NUMBER(10) NOT NULL, employee_id NUMBER(10) NOT NULL, action VARCHAR2(100) NOT NULL, log_date DATE NOT NULL ); ``` 然后,我们可以创建一个 INSTEAD OF 触发器来在 `employees` 表上进行操作时,自动将相应的日志信息插入到 `employees_log` 表。以下是这个触发器的示例代码: ```sql CREATE OR REPLACE TRIGGER employees_trigger INSTEAD OF INSERT OR UPDATE OR DELETE ON employees FOR EACH ROW DECLARE v_action VARCHAR2(100); BEGIN IF INSERTING THEN v_action := 'insert'; INSERT INTO employees_log (id, employee_id, action, log_date) VALUES (employees_log_seq.nextval, :new.id, v_action, SYSDATE); INSERT INTO employees (id, name, salary) VALUES (employees_seq.nextval, :new.name, :new.salary); ELSIF UPDATING THEN v_action := 'update'; INSERT INTO employees_log (id, employee_id, action, log_date) VALUES (employees_log_seq.nextval, :old.id, v_action, SYSDATE); UPDATE employees SET name = :new.name, salary = :new.salary WHERE id = :old.id; ELSIF DELETING THEN v_action := 'delete'; INSERT INTO employees_log (id, employee_id, action, log_date) VALUES (employees_log_seq.nextval, :old.id, v_action, SYSDATE); DELETE FROM employees WHERE id = :old.id; END IF; END; ``` 该触发器被定义为一个 INSTEAD OF 触发器,因此它会在 INSERT、UPDATE 或 DELETE 语句执行之前执行。它还使用了 FOR EACH ROW 子句,以便在每行上执行相应的操作。 在触发器的主体内部,我们使用了 IF-ELSIF 结构来确定正在执行的操作类型,并相应地插入、更新或删除日志信息以及 `employees` 表的记录。 这就是一个简单的 Oracle PL/SQL INSTEAD OF 触发器示例。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值