在 Oracle Express 中创建触发器

Creating a trigger in Oracle Express(在 Oracle Express 中创建触发器)

本文介绍了在 Oracle Express 中创建触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Oracle 11g Express 和 SQL Developer 中执行类似自动增量的操作.我对 Oracle 知之甚少,而且我也是触发器的新手.

I was trying to do something like auto-increment in Oracle 11g Express and SQL Developer. I know very little about Oracle and I am also new to triggers.

我试过运行它,但我不知道如何正确运行.

I tried running this, but I don't know how to do it properly.

CREATE TABLE theschema.thetable
(id NUMBER PRIMARY KEY,
name VARCHAR2(30));

CREATE SEQUENCE theschema.test1_sequence
START WITH 1
INCREMENT BY 1;

create or replace trigger insert_nums
before insert on theschema.thetable
for each row
begin
select test1_sequence.nextval into :new.id from dual;
end;
/

当我尝试创建触发器时,会出现一个屏幕,要求我提供一些绑定".该对话框只有一个复选框空".这是什么意思,我该如何制作一个可以正常工作的脚本?

When I try to create the trigger, I get a screen which asks me for some "binds". The dialog box has only one check box "null". What does this mean and how do I make a script that works properly?

在进行这种自动递增"时有什么预防措施吗?

Any precautions to take while doing this kind of "auto-increment" ?

推荐答案

似乎 SQL Developer 认为您正在运行一个普通的 DML(数据操作)脚本,而不是一个 DDL(数据定义).它还认为 :new.id 是一个可绑定变量.

It seems that SQL Developer thinks that you are running a plain DML (data manipulation) script, not a DDL (data definition). It also thinks that :new.id is a bindable variable.

为什么会这样,我不知道;我无法在 Oracle SQL Developer 2.1 中重现它.

Why this happens, I don't know; I can't reproduce it in Oracle SQL Developer 2.1.

尝试在 theschema 模式中打开一个新的 SQL 工作表窗口,然后按 F5(不是 F9).

Try to open a new SQL worksheet window in the theschema schema and execute a "whole" script (not a statement) by pressing F5 (not F9).

这篇关于在 Oracle Express 中创建触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 Oracle Express 中创建触发器

基础教程推荐