Update with Select from a non-existant column

Hello,
If I have two tables in Oracle database:
Table_1 has column id, c1, c2
Table_2 has column id, c1, c2
If I run the following select statement, it will give error, because column c3 does not exist:
select c3 from table_2;
However, if I run the following update statement, it run successfully with error. It shows, for example, 10 rows updated:
update table_1 t1 set t1.c2 =
(select t2.c3 from table_2 t2
where t2.id = t1.id);
Could someone explain to me what happens?
Regards!

rp0428 wrote:
>
It's called a Correlated Sub-Query . It's documented, with examples, in the SQL Language manual
>
I'm familiar with correlated sub-queries. That link has NO examples using a column in the FROM list of a sub-query that is NOT in a table in the FROM list of that sub-query.
You can certainly use constants, or functions in a select list without needing a table reference but I haven't seen any documentation showing an example of selecting a column in a sub-query that doesn't exist in one of the FROM tables.There are no examples of selecting a column from the outer query in a sub-query because in 99.999% of the cases it would be the wrong thing to do, however it is possible. Clearly the sub-query can "see" columns in the outer query otherwise how would it see the values for a correlated sub-query. As Frank said, there is nothing in the documenation that precludes using an outer column in the sub-query, and this paragraph from Frank's link certainly seems to pretty generally refer to the entire sub-query:
If columns in a subquery have the same name as columns in the containing statement, then you must prefix any reference to the column of the table from the containing statement with the table name or alias. To make your statements easier to read, always qualify the columns in a subquery with the name or alias of the table, view, or materialized view.John

Similar Messages

  • Displaying a non existent column from a Table.

    Hi
    I have an SQL Query that returns back a count of all the
    entities
    select count(*)'COUNTER',
    id_entity 'ENTITY'
    from  claim 
    where id_status = 'O'
    group by id_status,id_entity 
    order by id_entity ASC
    Output
    COUNTER ENTITY
    169     AGL
    6       DBC
    28      DELI would like to put a non existent column called 'Type' with a counter
    of 0,so that the output looks like :
    COUNTER ENTITY
    0       TYP
    169     AGL
    6       DBC
    28      DELIs this possible ? What do I need to change in my select clause
    for this?
    Please help

    monalalwani, do you mean something like this?
    you have -
    1 select count(*) as counter, deptno
    2 from emp
    3* group by deptno
    UT1 > /
    COUNTER DEPTNO
    5 10
    5 20
    6 30
    -- but want counter = 0 for dept 0
    UT1 > select count(*) as counter, deptno
    2 from emp
    3 group by deptno
    4 union
    5 select 0, 00
    6 from dual
    7 /
    COUNTER DEPTNO
    0 0
    5 10
    5 20
    6 30
    HTH -- Mark D Powell --

  • One can create an index on a non-existent column in a table

    I am using Oracle 10.2.0.3 on Windows 2003. I wanted to create an index on columnb of
    Tablea. When I use statement like:
    Create index index1 on tablea (‘columnb’) …
    Oracle created index: index1. However, when I looked tat the column in user_ind_columns it had some weird colculn like SYS_NCxxxx. For sometime, I had
    No idea what was going on. My index was not being used in queries at all. Then it dawned on me that I should not put single quotes around columnb. Once I removed quotes, things worked as expected.
    But why does Oracle allow index on a non-existent column?

    we cannot create the index on nonexistent column of table We can. Its called a function-based index. Here's how we do it.
    Also read Howard's reply, right above yours.
    SQL> desc t
    Name                                      Null?    Type
    OWNER                                     NOT NULL VARCHAR2(30)
    OBJECT_NAME                               NOT NULL VARCHAR2(30)
    SUBOBJECT_NAME                                     VARCHAR2(30)
    OBJECT_ID                                 NOT NULL NUMBER
    DATA_OBJECT_ID                                     NUMBER
    OBJECT_TYPE                                        VARCHAR2(19)
    CREATED                                   NOT NULL DATE
    LAST_DDL_TIME                             NOT NULL DATE
    TIMESTAMP                                          VARCHAR2(19)
    STATUS                                             VARCHAR2(7)
    TEMPORARY                                          VARCHAR2(1)
    GENERATED                                          VARCHAR2(1)
    SECONDARY                                          VARCHAR2(1)
    SQL> create index t_idx on t( substr(object_name, 1, 5));
    Index created.
    SQL> select column_name from user_ind_columns where index_name = 'T_IDX';
    COLUMN_NAME
    SYS_NC00014$
    SQL> select index_type from user_indexes where index_name = 'T_IDX';
    INDEX_TYPE
    FUNCTION-BASED NORMAL
    SQL>

  • "Your script uses objects from a non-existent collection"

    I have a multiple page form with a barcode on each form.  I created a separate collection for each barcode.  The auto generated code looks fine and has the correct collection created, however I still get the error, Paper Forms Barcode error "Your script uses objects from a non-existent collection".
    I'm not sure what is wrong and I don't know how to fix it.  Anyone else run into this?

    You will need to create a shared folder in Dropbox, then populate that with what ever folders you need to organize the files. It appears the DropBox app,will not handle this, but you can do, it by logging in to you account via Safari. Once the folders are created, they will show up in the app. Likewise with designating the folders as shared. Anyone you wish to share with will need a Dropbox account. (using the public folder will not work since links out it are for files only, not folders. An odd restriction, but it is what it is).
    IF you have copies of the files on a PC, you will find that will be the easiest place to upload them from. If they are only in iBooks on the iPad, you will need to synch and use the file management function to copy them off. not sure if you can synch them back over to DropCopy within iTunes (never tried it).
    DEpending on your needs, a couple of apps to look into are iCab Mobile (a browser), and GoodReader (doc viewing and management app). Both integrate well with DropBox.

  • Keynote document saved in icloud not updating with data from Numbers? is icloud the problem

    keynote document saved in icloud not updating with data from Numbers? is icloud the problem.
    If both files are held locally on the computer it looks like there is no problem however if you try and do it though icloud (ie your docs are saved on icloud) you dont get the "source" oprion besides the graph etc. Is this a but or a broken function due to the new implementation of icloud.

    Hi sebnor31,
    This is Visual C# forum, but your question seems not related to Visual C# language itself. It most likely related to the bluetooth message transaction protocal or with the device itself.
    I'll move your question to [where is this forum for...] forum where the morderator may direct you to the correct forum.
    Thanks for your understanding.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can I unlock the copy protection of songs that I've acquired some years ago with an old - and non existing anymore - account? Can I link the songs to my new account or do I have to purchase them again?

    How can I unlock the copy protection of songs that I've acquired some years ago with an old - and non existing anymore - account? Can I link the songs to my new account or do I have to purchase them again?

    If you're in the US, you will be able to use iTunes Match for $25 a year to remove copy protection in a few months: http://www.apple.com/icloud/features/
    If you're not, you can't.  You can authorise iTunes with the old account in addition to your current account, so all your songs will play, but I'm not sure what will happen if you try to sync them to an iPod.

  • Update table with select from another table

    Hallo,
    I'd like to update table b with codes from a mapping table a.
    a has:
    town_id, town_code, town_name
    b has town_code, town_id, town_population, town_zip_code,...
    Table a has all the details - town_id, town_code and town_name and acts as the mapping between town_id and town_code
    In table b, town_code is null. I want to update the column b.town_code with town_code from table a where a.town_id = b.town_id.
    How will the update query look like?
    I tried
    UPDATE B SET town_code = (SELECT A.town_code FROM A,B WHERE A.town_id=B.town_id)
    and I get the error 'single-row subquery returns more than one row'
    Will appreciate your assistance

    This is what I did.
    First, I created and populated the TOWN_INFO table:
    CREATE TABLE "TOWN_INFO"
    (     "TOWN_ID" NUMBER,
         "TOWN_CODE" NUMBER,
         "E_MAIL" CHAR(15 BYTE)
    Table Created.
    insert all
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3024,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3040,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3052,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3065,'[email protected]')
    into TOWN_INFO (TOWN_ID, E_MAIL) values (3066,'[email protected]')
    select * from dual
    5 rows created.
    The following creates and populates the mapping table:
    CREATE TABLE "TOWN_MAPP"
    (     "TOWN_CODE" NUMBER,
         "TOWN_ID" VARCHAR2(255 BYTE),
         "TOWN_NAME" CHAR(6 BYTE)
    insert all
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3024,'1001','TOWN_1')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3040,'1003','TOWN_3')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3052,'1002','TOWN_2')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3065,'1004','TOWN_4')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3066,'1006','TOWN_6')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3088,'1007','TOWN_7')
    into TOWN_MAPP (TOWN_ID,TOWN_CODE, TOWN_NAME) values (3020,'1009','TOWN_9')
    select * from dual
    7 rows created.
    And now the update query:
    UPDATE TOWN_INFO
    SET TOWN_CODE=(SELECT B.TOWN_CODE FROM TOWN_MAPP B, TOWN_INFO C
    WHERE B.TOWN_ID=B.TOWN_ID)
    SET TOWN_CODE=(SELECT B.TOWN_CODE FROM TOWN_MAPP B, TOWN_INFO C
    ERROR at line 2:
    ORA-01427: single-row subquery returns more than one row
    Thanx in advance
    Edited by: user9954260 on Apr 13, 2010 7:40 AM
    Edited by: user9954260 on Apr 13, 2010 7:44 AM

  • Getting an error while selecting from table having CLOB column.

    Hi All,
    I have below table created in My oracle database version Oracle Database 11g Enterprise Edition Release 11.2.0.1.0.
    CREATE TABLE my_clob -- Dummy table created
    (DataBody CLOB);
    Current Database Character set - WE8MSWIN1250.
    On the front end of my application, I have one form through which I can save/edit data in the above table. If I'm creating one new entry in the above table then it first check with existing record to avoid the duplicate entry and the this point application create the below select statement on the above table and return the error "ORA-00932: inconsistent data types: expected - got CLOB".
    I can not change the sql statement.
    SELECT * FROM my_clob WHERE databody IS NULL OR databody ='';
    Even when I run the same statement on my DB server I’m getting the same error. Shown below
    SQL> SELECT * FROM my_clob WHERE databody IS NULL OR databody ='';
    SELECT * FROM my_clob WHERE databody IS NULL OR databody =''
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected - got CLOB
    SQL>
    Is there anything with OraOLEDB which causing this error? Please help me out to get rid of this error.
    Thanks,
    Santosh

    You cannot compare directly a CLOB column with a VARCHAR2 column. In your case you don't need to do such comparison because Oracle consider zero length strings as null values:
    SQL> create table my_clob(data int, databody clob);
    Table created.
    SQL> insert into my_clob values(1, null);
    1 row created.
    SQL> insert into my_clob values(2, '');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from my_clob where databody is null;
          DATA
    DATABODY
             1
             2About null values in Oracle, please read http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements005.htm#SQLRF30037.

  • How to display a empty (non-existing) column and info in LAST row

    Hello!
    I´m trying to create the code that diplays all authors (author.name), empty COLUMN, NR_OF_BOOK_PER_AUTHOR.
    I want the LAST ROW to display: (column1) the word 'Sum:', (column2) nr of authors, (column3) total sum of all books
    Headache: How do I display the EMPTY column and how do I get the LAST ROW to display column1) 'Sum:', (column2) nr of authors, (column3) total sum of all books
    It should look like this:
    AUTHOR EMPTY NR_OF_BOOKS_PER_AUTHOR
    I can list all authors and NR_OF_BOOKS_PER_AUTHOR using this code:
    SELECT A.NAME, COUNT(B.ROWID)
    FROM AUTHOR A, BOOK B
    WHERE B.AUTHOR_ID = A.ID
    GROUP BY A.NAME
    ORDER BY COUNT(B.ROWID)
    I can count the numbers of authors (should be displayed in last row column2) using:
    SELECT COUNT(name)
    FROM author
    and I can list the total amount of books (should be displayed in last row column3) using:
    SELECT COUNT(title)
    FROM book
    But I come up short with how to display the EMPTY column and the last row containing (column1) the word 'Sum:', (column2) nr of authors, (column3) total sum of all books
    Any suggestions?
    Best regards,
    Daniel

    I want the LAST ROW to display: (column1) the word 'Sum:', (column2) nr of authors, (column3) total sum of all booksHave a look at GROUP BY with CUBE or ROLLUP.
    Cheers, APC

  • PROBLEM WITH Select * from table_name with JDBC

    Hello,
    I am using thin driver. The problem that i am having is as
    follows.
    when i execute select * from any_table_name from within java
    code i only get FIRST row back. I am using Employee.java example.
    Is there something else i should do?
    Alex
    null

    Hi Alex,
    I am writing a client application with Java. Everything works
    really well, but - same problem as you had (I know, you solved it
    - that's why I'm writing :) - reading only first column. Actually
    it works fine on its own, but when embedded in my java app -
    that's when I get the first column displayed.
    Also executing "select * from emp;" gives me a sequence of
    numbers (displayed in columns) 20, 30, 30 etc, which are in fact
    present as one of the columns when running this query without
    java.
    I appreciate your help!
    Malgosia
    Alex Korneyev (guest) wrote:
    : Hello,
    : I am using thin driver. The problem that i am having is as
    : follows.
    : when i execute select * from any_table_name from within java
    : code i only get FIRST row back. I am using Employee.java
    example.
    : Is there something else i should do?
    : Alex
    null

  • Procedure with select from mysql db link problem

    Hi,
    first of all Oracle is new to me so if there are better ways to do this every suggestion would help.
    My problem is simple i cant use select from dblink inside a procedure.
    In Oralce SQL Developer 1.5.5:
    Im using oracle 11g and mysql 5.5.13 with mysql odbc 5.1
    in both db the user is root
    CREATE PUBLIC DATABASE LINK "MYSQL"
    CONNECT TO "root" IDENTIFIED BY "****"
    AUTHENTICATED BY "root" IDENTIFIED BY "****"
    USING 'mysql';
    select * from t1@mysql;
    run; -> result OK
    select "MAXID" from t1@mysql where "TNAME"='first';
    run; -> result OK
    create or replace
    PROCEDURE T1_IDS_PROC AS
    maxi number;
    BEGIN
    select "MAXID" into maxi from t1@mysql where "TNAME"='first';
    END T1_IDS_PROC;
    compile -> not working:
    Fehler(7,3): PL/SQL: SQL Statement ignored
    Fehler(7,47): PL/SQL: ORA-00904: "TNAME": unknown identifier
    How to solve this?

    Thanks for replay,
    yes the owner of the procedure can acces the remote table.
    I can use
    select count(*) into i from t1@mysql
    inside the procedure, but if i use specific columns inside the select i cant compile.
    Why i need double quote?
    I dont know if i need them but i read some tutorial for dblink to mysql and there was explanied
    Oracle use upercase names and Mysql is case sensitive for odbc 5.1 so i have to double qoute mysql names.
    But with or without double qoute it dont work inside procedures ;(

  • Update with Select top n statement

    Hi All,
    Can I use update statemet like this..
    Update table1
    set Name=(select top (100) t2.name from table2 t2 where table1.ID=t2.ID)
    Please let me know ASAP its very urgent
    Thanks in Advance
    RH
    sql

    Hi sql9 !
    You might need below query;
    CREATE TABLE Table1 (ID INT,Name VARCHAR(10))
    CREATE TABLE Table2 (ID INT,Name VARCHAR(10))
    --TRUNCATE TABLE Table1
    --TRUNCATE TABLE Table2
    INSERT INTO Table1
    SELECT 1,'ABC' UNION ALL
    SELECT 2,'DEF' UNION ALL
    SELECT 3,'GHI'
    INSERT INTO Table2
    SELECT 1,'JKL' UNION ALL
    SELECT 1,'MNO' UNION ALL
    SELECT 2,'PQR' UNION ALL
    SELECT 2,'STU' UNION ALL
    SELECT 3,'VWX' UNION ALL
    SELECT 3,'YZ'
    UPDATE Table1 SET Name = (SELECT TOP 1 T2.Name FROM Table2 T2 WHERE Table1.ID = T2.ID)
    SELECT * FROM Table1
    --ID Name
    --1 JKL
    --2 PQR
    --3 VWX
    --You can simply re-write your SQL with below query and you don't have to specify TOP Clause inside subquery
    UPDATE T1 SET T1.Name = T2.Name
    FROM Table1 T1
    INNER JOIN Table2 T2 ON T2.ID = T1.ID
    SELECT * FROM Table1
    --ID Name
    --1 JKL
    --2 PQR
    --3 VWX
    Note : In your first query TOP 100 returning more than 1 value from subquery which is not allowed.
    Please let me know if this doesn’t work for you. Hope I have answered you correctly.
    Thanks,
    Hasham

  • I was told that my new imac with Lion could burn dvds..so I bought it..now have finished editing a wedding in iMovie full of HD stills mixed with video from a non HD  SonyDCR-SX63.. just saw the scary question.. "Where is your iDVD?  How do I make a DVD?

    How to I burn to a DVD my project edited on mynew  imac with Lion in imovie? I used some HD stills and some video from a non HD sony DCR-SX63..was ready to burn a DVD then saw the haunting question "Where is iDVD?" Please help..this wedding edit is long ovedue.

    How to I burn to a DVD my project edited on my new  imac
    If you are still within your 15 day return period.  Call Apple they will sent out iDVD at no charge.  (There are no realistic substitutes.)
    Nicely explain that you may return the computer without iDVD.  You MUST speak to a senior advisor to get a free copy. The first tier people cannot do it.
    408-996-1010
    800-692-7753
    If that doesn't work you can purchase iLife 11  (includes iDVD) on disk.
    IDVD is a wonderful piece of software and well worth the low cost of $40.
    http://www.amazon.com/Apple-MC623Z-A-iLife-VERSION/dp/B003XKRZES/ref=sr_1_1?ie=U
    http://dealmac.com/lw/artclick.html?1,527850,1872219

  • Inventory Management :Delta IP of BF runs with selection from Init IP of BF

    I have an init IP for BF DS which i ran with selection on posting date.
    I have another IP for delta for BF without any selection criteria.
    But, when i run the delta IP, it runs with the selection on posting date, the same value that i used for init.
    Even if i modify and clear the delta IP of any selection, and run it, it still runs with the selection.
    How do i rectify this.
    Thanks,

    that is the correct process. if u do init with some filters then those would be applied to Delta by default. u cannt remove those filters from delta. if u want to do it anyway u have to delete the last init request then the filters wodnt be applied. but in this case u have to rerun ur init again without any filters so that u can get delta.

  • How to select rowid with select * from table_name

    Hello guys i have a cursor like so.
      Cursor c1 IS SELECT * FROM FZRASST;
      -- Row of type FZRASST row
      fzrasst_row c1%ROWTYPE;when i try to reference the row id like this
    fzrasst_row.rowid;i get an error invalid indentifier? how can i reference the row id without implicitely selecting rowid? is this possible or do i need to change my select statement to select every column on the table?
    Any help would be greatly appreciated.

    Hi,
    mlov83 wrote:
    Hello guys i have a cursor like so.
    Cursor c1 IS SELECT * FROM FZRASST;
    -- Row of type FZRASST row
    fzrasst_row c1%ROWTYPE;when i try to reference the row id like this
    fzrasst_row.rowid;i get an error invalid indentifier? how can i reference the row id without implicitely selecting rowid? is this possible or do i need to change my select statement to select every column on the table?Fzrasst_row contains every column that is in the SELECT clause, and nothing more. If you want fzrasst_row to include pseudo-columns (such as ROWID) or anything else, then you have to include them in the SELECT clause.
    To avoid naming every single column in hte table, you can do something like this:
    Cursor c1 IS
        SELECT  FZRASST.*
        ,       ROWID   AS r_id
        FROM    FZRASST;(assuming the table doesn't already have a column called r_id).
    Edited by: Frank Kulash on Feb 13, 2012 3:29 PM

Maybe you are looking for

  • Online Help for Oracle HRMS Self Service System

    I am looking into developing context-sensitive online help for an Oracle HRMS Self Service application. There is currently no online help for the application; all help is provided in printed and online docs, so users are having trouble navigating to

  • Invoice A/R Payment Split Transaction into Several GL Accounts

    Hi, I got following message from SAP Support: The SplitTransaction property is not included in product develop plan by now. By SAP Note 1028874, we would like to ask you to post your requirement in our SAP Business One Product Development Collaborati

  • Writing equations in words, how to accomplish

    I want to express a number of equations on words, as opposed to symbols. Since the word descriptions are often six words or more I'm looking for a solution in PAGES that allows me to create what are essentially text boxes side by side. Then of course

  • Handle National Character Objects

    Hi, I am working on Oracle Database 11g. To fetch the data from csv file loaded we are using a function which calls another function that converts the BLOB(csv file saved as blob column in one of the tables)  data into NCLOB. Please find below the fu

  • The reason for very little viruses on MACs

    As far as I know, there are very few viruses that are spread through the internet that cause harm to a mac. I'm going to purchase an macbook within a couple months and was just curious what it has in terms of virus protection, if any. Are there just