使用 Oracle 的工具,或者将 NetBeans IDE 连接到数据库并使用 IDE 的 SQL 编辑器。NetBeans 7.0 目前仅提供 Beta 或开发版本,可以改进到 Oracle 数据库的连接。要了解如何将 NetBeans IDE 连接到 Oracle 数据库以及如何在数据库中创建用户
使用 Oracle 的工具,或者将 NetBeans IDE 连接到数据库并使用 IDE 的 SQL 编辑器。NetBeans 7.0 目前仅提供 Beta 或开发版本,可以改进到 Oracle 数据库的连接。要了解如何将 NetBeans IDE 连接到 Oracle 数据库以及如何在数据库中创建用户
通过使用所选的工具,创建以下用户:
用户名 user
口令 phpuserpw
系统权限 CREATE TABLE
代码如下 | 复制代码 |
CREATE VIEW CREATE SEQUENCE CREATE TRIGGER |
角色 (Oracle Database 10.x) CONNECT
代码如下 | 复制代码 |
RESOURCE |
下面是一组用于创建该用户的示例 SQL 命令。这些命令假定具有 USERS 和 TEMP 表空间。
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy6350')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6350><pre class="brush:php;toolbar:false">drop user phpuser cascade;<br /><br />create user phpuser identified by phpuserpw;<br /><br />grant connect, resource to phpuser;<br /><br />alter user phpuser default tablespace users temporary tablespace temp account unlock;
要排列和存储所需的所有数据,您需要使用两个表:
wishers 表包含三个字段:
wishes 表包含四个字段:
这些表通过许愿者的 ID 相关联。除了 wishes 表中的 due_date 以外,所有字段都是必需的。
创建 Oracle 数据库架构
如果通过 NetBeans IDE 进行连接,请使用新用户的名字和口令创建一个连接。确保选择的架构具有与用户相同的名称。(请参见“连接到 Oracle 数据库”教程的建立到 Oracle DB 的连接部分。)
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy1070')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1070><pre class="brush:php;toolbar:false">create table wishers (<br /> id number not null,<br /> name varchar2(50) unique not null,<br /> password varchar2(50) not null,<br /> constraint wishers_pk primary key(id)<br />);
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy4378')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4378><pre class="brush:php;toolbar:false">create table wishes (<br /> id number not null,<br /> wisher_id number not null,<br /> description varchar2(255) not null,<br /> due_date date,<br /> constraint wishes_pk primary key(id),<br /> constraint wishes_fk1 foreign key(wisher_id) references wishers(id)<br />);
注意:您可以在此处下载一组 SQL 命令以创建 Oracle 数据库表。
添加序列和以增加 ID 值
在使用 Oracle 数据库时,您必须指定一个序列以增加值。要在表中添加新成员时增加值,请添加一个触发器。
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy2323')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2323><pre class="brush:php;toolbar:false">create sequence wishers_id_seq start with 1 increment by 1;
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy7818')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7818>create or replace trigger wishers_insert<br />before insert on wishers<br />for each row<br />begin<br /> wishers_id_seq.nextval into :new.id from dual;<br />end;<br /></td> </tr> </table>/
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy6982')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6982><pre class="brush:php;toolbar:false">create sequence wishes_id_seq start with 1 increment by 1;
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy2791')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2791>create or replace trigger wishes_insert<br />before insert on wishes<br />for each row<br />begin<br />select wishes_id_seq.nextval into :new.id from dual;<br />end;<br /></td> </tr> </table>/
注意:您可以在此处下载一组 SQL 命令以创建 Oracle 数据库表,包括序列和触发器。
输入测试数据
要测试应用程序,您需要使用数据库中的某些数据。下面的示例说明了如何添加两个许愿者和四个心愿。
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy5640')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5640><pre class="brush:php;toolbar:false">insert into wishers (name, password) values ('Tom','tomcat');
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy3063')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3063><pre class="brush:php;toolbar:false">insert into wishers (name, password) values ('Jerry', 'jerrymouse');<br />commit;
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy6589')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6589><pre class="brush:php;toolbar:false">insert into wishes (wisher_id, description, due_date) <br /> values (1, 'Sausage', to_date('2008-04-01', 'YYYY-MM-DD');<br /><br />insert into wishes (wisher_id, description) <br /> values (1, 'Icecream');<br /><br /><br />insert into wishes (wisher_id, description, due_date) values (2, 'Cheese', to_date('2008-05-01', 'YYYY-MM-DD'));<br /><br />insert into wishes (wisher_id, description)<br /> values (2, 'Candle');<br />commit;
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号