Search notes:

SQL*Plus: COLUMN … NEW_VALUE

column  column_name  new_value  variable_name
COLUMN colname NEW_VALUE varname assigns the value of a selected colname of a select statement to the substitution variable varname.

Simple example

In the following example, two tables are created (new_value_test_from and new_value_test_to).
One record is inserted into new_value_test_from.
This record's only field is selected (and by means of new_value) assigned to the varlable var.
Then, the value of this variable is inserted into the other table, new_value_test_to.
set feedback off
set verify off

create table new_value_test_from (
  col Varchar2(20)
);

create table new_value_test_to (
  col Varchar2(20)
);

insert into new_value_test_from values ('Foo Bar Baz');

column col new_value var

select col from new_value_test_from;

prompt var: &var;
/*
   var: Foo Bar Baz*
*/

insert into new_value_test_to values ('&var');

select * from new_value_test_to;
/*
   COL
   --------------------
   Foo Bar Baz
*/

drop table new_value_test_from purge;
drop table new_value_test_to   purge;
Github repository oracle-patterns, path: /SQLPlus/new-value/one-record.sql

Multi-record example

If there are more than one rows in the record set, the variable is assigned with the value of the last record:
set feedback off
set verify off

create table new_value_test (
  col Varchar2(20)
);


insert into new_value_test values ('val one'  );
insert into new_value_test values ('val two'  );
insert into new_value_test values ('val three');

column col new_value var

select col from new_value_test;

drop table new_value_test purge;

prompt var is: &var
/*
   var is: val three
*/
Github repository oracle-patterns, path: /SQLPlus/new-value/multiple-records.sql

See also

SQL*Plus

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1741086516, '3.142.156.141', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL-Plus/new_value(117): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78