Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6596711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:06:41+00:00 2026-05-25T18:06:41+00:00

Given a table T(x, y, z, t, u, v, …) is it possible in

  • 0

Given a table T(x, y, z, t, u, v, ...) is it possible in Oracle to write this query without listing all columns (be it in the SELECT or in the INSERT part)?

INSERT INTO T (x, y, z, t, u, v, ...)
SELECT 'new', y, z, t, u, v, ...
  FROM T
 WHERE x = 'old'

The effect is that all rows for which x has the value of old are duplicated, except that now x has the value of new.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:06:42+00:00Added an answer on May 25, 2026 at 6:06 pm

    “is it possible in Oracle to write this query without listing all
    columns (be it in the SELECT or in the INSERT part)”

    No. The only way to avoid typing an explicit projection is to use all the table’s columns. You aren’t doing that, because you want to use a literal instead of column X. That means you have to list all the other columns in the SELECT projection.

    Of course, you don’t have to specify the columns in the INSERT clause.

    Over the years developers have occasionally wished for an “except” syntax, something like:

    select * except X from t
    

    but it’s never made it into the ANSI standard. In fact, I doubt if it’s even been discussed.


    “PLSQL answers are welcome then!”

    Okay, here is a proof of concept which uses the data dictionary to produce a dynamic insert statement.

    It makes the following assumptions:

    1. You only want to substitute the value of one column.
    2. The column you want to substitute is a string datatype.
    3. You want to clone all the records in the source table.

    You will need to adjust the code if any of those assumptions are wrong.

    The procedure loops round the USER_TAB_COLUMNS table, sorting the columns into the table’s projected order. It concatenates the column names into the SELECT clause of an INSERT statement, except where the name is that of the substituted column when it concatenates the provided literal instead. Finally it uses Native Dynamic SQL to run the assembled INSERT statement.

    create or replace procedure clone_minus_one 
        ( p_sub_col in user_tab_columns.column_name%type
          , p_sub_val in varchar2 )
    is
        stmt varchar2(32767) := 'insert into source_table select ';
    begin
        for lrec in ( select column_name
                             , column_position 
                      from  user_tab_columns.
                      where table_name = 'SOURCE_TABLE'
                      order by column_position )
        loop
            if lrec.column_position != 1
            then 
                stmt := stmt ||',';
            end if;
            if lrec.column_name != p_sub_col
            then
                stmt := stmt ||lrec.column_name;
            else
                stmt := stmt ||''''||p_sub_val||'''';
            end if;  
        end loop;
        stmt := stmt || ' from source_table';
        execute immediate stmt;
    end;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, I'm probably over-analyzing this problem, but... Given table A with two one-to-many relationships
I am designing a SQL query to extract all records from a given table.
For a given table 'foo', I need a query to generate a set of
Given a table structure like this: CREATE TABLE `user` ( `id` int(10) unsigned NOT
Given a table named person (in a MySQL database/schema), kind of like this one:
How to write a PL/SQL procedure that: Copies a table given by name into
Given table mytable with two columns letter and num letter|num ------+------ a |1 a
I am trying to check the table structure of given table in Query Analyzer.
I want to list down all the column details for a given table and
It is easy to find all stored procs that depends on a given table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.