Basic Update Statements
|
Update all records
|
UPDATE <table_name>
SET <column_name> = <value>
|
CREATE TABLE test AS
SELECT object_name, object_type
FROM all_objects;
SELECT DISTINCT object_name
FROM test;
UPDATE test
SET object_name = 'OOPS';
SELECT DISTINCT object_name
FROM test;
ROLLBACK;
|
Update a specific record
|
UPDATE <table_name>
SET <column_name> = <value>
WHERE <column_name> = <value>
|
SELECT DISTINCT object_name
FROM test;
UPDATE test
SET object_name = 'LOAD'
WHERE object_name = 'DUAL';
COMMIT;
SELECT DISTINCT object_name
FROM test
|
Update based on a single queried value
|
UPDATE <table_name>
SET <column_name> = (
SELECT <column_name>
FROM <table_name
WHERE <column_name> <condition> <value>)
;
|
CREATE TABLE test AS
SELECT table_name
FROM all_tables;
ALTER TABLE test
ADD (lower_name VARCHAR2(30));
SELECT *
FROM test
WHERE table_name LIKE '%A%
';
UPDATE test t
SET lower_name = (
SELECT DISTINCT lower(table_name)
FROM all_tables a
WHERE a.table_name = t.table_name
AND a.table_name LIKE '%A%');
COMMIT;
SELECT *
FROM test;
|
Update based on a query returning multiple values
|
UPDATE <table_name> <alias>
SET (
<column_name>,<column_name> )
= (
SELECT (
<column_name>, <column_name>)
FROM <table_name>
WHERE <alias.column_name> = <alias.column_name>)
;
|
CREATE TABLE test AS
SELECT t. table_name, t. tablespace_name, s.extent_management
FROM user_tables t, user_tablespaces s
WHERE t.tablespace_name = s. tablespace_name
AND 1=2;
desc test
SELECT * FROM test;
-- does not work
UPDATE test
SET (table_name, tablespace_name) = (
SELECT table_name, tablespace_name
FROM user_tables);
-- works
INSERT INTO test
(table_name, tablespace_name)
SELECT table_name, tablespace_name
FROM user_tables;
COMMIT;
SELECT *
FROM test
WHERE table_name LIKE '%A%
';
-- does not work
UPDATE test t
SET tablespace_name, extent_management = (
SELECT tablespace_name, extent_management
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name
AND t.table_name LIKE '%A%');
-- does not works
UPDATE test t
SET (
tablespace_name, extent_management)
= (
SELECT DISTINCT u.tablespace_name, u.extent_management
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name
AND t.table_name LIKE '%A%');
rollback;
-- works
UPDATE test t
SET (
tablespace_name, extent_management)
= (
SELECT DISTINCT u.tablespace_name, u.extent_management
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name)
WHERE t.table_name LIKE '%A%';
COMMIT;
SELECT *
FROM test;
|
Update the results of a SELECT statement
|
UPDATE (<SELECT Statement>)
SET <column_name> = <value>;
|
SELECT *
FROM test
WHERE table_name LIKE '%A%
';
SELECT *
FROM test
WHERE table_name NOT LIKE '%A%
';
UPDATE (
SELECT *
FROM test
WHERE table_name NOT LIKE '%A%
')
SET extent_management = 'Unknown';
SELECT *
FROM test;
|
|
Correlated Update
|
Single column
|
UPDATE TABLE(<SELECT STATEMENT>) <alias>
SET <column_name> = (
SELECT <column_name>
FROM <table_name> <alias>
WHERE <alias.table_name> = <alias.table_name>;
|
UPDATE table1 t_alias1
SET column = (
SELECT expr
FROM table2 t_alias2
WHERE t_alias1.column = t_alias2.column);
|
Multi-column
|
UPDATE TABLE(<SELECT STATEMENT>) <alias>
SET <column_name> = <value>;
|
UPDATE table1 t_alias1
SET (col1, col2) = (
SELECT col1, col2
FROM table2 t_alias2
WHERE t_alias1.col3 = t_alias2.col3);
|
|
Nested Table Update
|
|
See Nested Tables page
|
|
Update With Returning Clause
|
Returning Clause demo
|
UPDATE (<SELECT Statement>)
SET ....;
|
conn hr/hr
var bnd1 NUMBER
var bnd2 VARCHAR2(30)
var bnd3 NUMBER
UPDATE employees
SET job_id ='SA_MAN', salary = salary + 1000,
department_id = 140
WHERE last_name = 'Jones' RETURNING
salary*0.25, last_name, department_id
INTO
:bnd1, :bnd2, :bnd3;
print bnd1
print bnd2
print bnd3
|
conn hr/hr
variable bnd1 NUMBER
UPDATE employees
SET salary = salary * 1.1
WHERE department_id = 100
RETURNING SUM(salary) INTO :bnd1;
print bnd1
|
|
Update Object Table
|
Update a table object
|
UPDATE (<SELECT Statement>)
SET ....;
|
UPDATE table1 p SET VALUE(p) =
(SELECT VALUE(q) FROM table2 q WHERE p.id = q.id)
WHERE p.id = 10;
|
|
Record Update
|
Update based on a record
|
UPDATE <table_name>
SET ROW = <record_name>;
|
CREATE TABLE t AS
SELECT table_name, tablespace_name
FROM all_tables;
SELECT DISTINCT tablespace_name
FROM t;
DECLARE
trec t%ROWTYPE;
BEGIN
trec.table_name := 'DUAL';
trec.tablespace_name := 'NEW_TBSP';
UPDATE t
SET ROW = trec
WHERE table_name = 'DUAL';
COMMIT;
END;
/
SELECT DISTINCT tablespace_name
FROM t;
|
|
Update Partitioned Table
|
Update only records in a single partition
|
UPDATE <table_name> PARTITION <partition_name>
SET <column_name> = <value>
WHERE <expression>;
|
UPDATE sales PARTITION (sales_q1_2005) s
SET s.promo_id = 494
WHERE amount_sold > 9000;
|
相关推荐
command.Parameters.Add(new OracleParameter("id", OracleDbType.Int32, ParameterDirection.Input)); command.Parameters["id"].Value = someId; ``` 在这个OracleTest项目中,你将找到一个完整的示例,演示如何...
UPDATE yourTable SET column = 'NewValue' WHERE id = 1;"; ``` 执行批处理时,我们不需要调用多次ExecuteNonQuery()方法,而是只需调用一次,即可执行所有SQL语句: ```csharp int rowsAffected = command....
- 添加参数:`command.Parameters.Add(new OracleParameter("username", OracleDbType.Varchar2, ParameterDirection.Input));` 和 `command.Parameters.Add(new OracleParameter("password", OracleDbType.Varchar...
command.CommandText = "UPDATE yourTable SET column1=:newValue WHERE id=:id"; command.Parameters.AddWithValue(":newValue", newValue); command.Parameters.AddWithValue(":id", someId); command....
4. **Oracle_Command.chm**: 可能是关于Oracle命令行工具的指南,例如SQL*Plus,它是Oracle的默认交互式SQL工具,用于执行SQL语句、脚本和PL/SQL块。通过这个工具,用户可以连接到数据库、运行查询、管理用户、...
command.Parameters.Add(new OracleParameter(":username", OracleDbType.Varchar2)).Value = username; ``` 8. **连接池**: ODP.NET支持连接池,它可以复用已打开的连接,从而提高性能。默认情况下,连接池是...
4. **执行SQL语句**:使用`Command`对象来执行SQL更新语句,如`UPDATE`,`INSERT`或`DELETE`。例如,更新数据库的代码可能如下: ```vb Dim cmd As New ADODB.Command cmd.ActiveConnection = conn cmd....
此方法用于执行不返回结果集的 Oracle 命令,如 INSERT、UPDATE 或 DELETE 操作。它接受以下几个参数: - `conn`:现有的数据库连接。 - `commandType`:命令类型,可以是存储过程、文本等。 - `commandText`:存储...
在.NET开发环境中,C#是一种常用的编程语言,而Oracle数据库是企业级的数据库管理系统,两者结合可以构建高效、稳定的数据处理应用。本篇文章将详细探讨如何使用C#通过Oracle.DataAccess.Client类库来访问Oracle...
Oracle VB6是一个结合了Oracle数据库和Visual Basic 6(VB6)编程语言的开发环境,用于构建能够高效访问和管理Oracle数据库的应用程序。在VB6中,你可以利用ADO(ActiveX Data Objects)或其他数据访问技术,如ODBC...
其中,COMMAND_TYPE值3表示SELECT,2表示INSERT,6表示UPDATE,7表示DELETE,47表示PL/SQL块。此外,OPTIMIZER_MODE指示了SQL执行模式,SQL_TEXT字段包含SQL语句文本,SHARABLE_MEM字段显示了共享池中的共享内存使用...
例如,`Command.Execute`方法用于执行非查询命令(如INSERT, UPDATE, DELETE),而`Command.ExecuteReader`用于获取查询结果。 3. **参数化查询**:使用绑定变量,你可以创建参数化的SQL命令。这可以通过在SQL语句...
cmd.CommandText = "UPDATE employees SET department = 'Finance' WHERE id = '1'" cmd.ExecuteNonQuery() ``` 5. **关闭连接**:在完成所有操作后,记得关闭数据库连接以释放资源: ```vb conn.Close Set conn = ...
它由多个组件构成,如Connection(连接)、Command(命令)、DataAdapter(数据适配器)、DataSet(数据集)和DataReader(数据读取器)等。 2. **OraDBHelper.cs**:这是一个辅助类,通常包含用于执行常见数据库...
2. **Command**:此对象用于执行SQL命令,如SELECT、INSERT、UPDATE和DELETE等。我们可以设置Command对象的`CommandText`属性为SQL语句,然后调用`Execute`方法执行命令。 3. **Recordset**:记录集对象是ADO的核心...
4. 执行SQL语句:连接建立后,可以通过Command对象执行SELECT、INSERT、UPDATE或DELETE等SQL操作。 5. 处理结果集:如果执行的是查询语句,可以获取并处理返回的结果集。 6. 关闭连接:完成数据库操作后,需要关闭...
SqlCommand updateCommand = new SqlCommand($"UPDATE yourTable SET {columnName}=@Value WHERE yourKey=@Key", sqlConnection); updateCommand.Parameters.AddWithValue("@Value", row.Cells[columnName].Value)...
- 在VBA中处理Oracle游标,如FOR UPDATE子句,以便在多用户环境中锁定记录。 5. **错误处理**: - 在VBA中使用On Error语句设置错误处理机制,捕获并处理可能出现的数据库连接或查询错误。 6. **性能优化**: -...
在本案例中,"asp写的简单oracle增删改查"指的是一个基于ASP技术实现的数据库操作程序,主要功能是对Oracle数据库进行基本的CRUD(Create、Read、Update、Delete)操作。Oracle数据库是一款强大的关系型数据库管理...
一旦连接建立,VB程序就可以通过ADO(ActiveX Data Objects)对象,如Command和Recordset,来执行SQL命令和处理返回的结果集。 为了实现成绩查询功能,我们需要设计一个查询界面,允许用户输入查询条件,如学号或...