UPDATE SQL string substitution from another table

Hi - I've come across a tricky situation where I would want to update a column in all the relevant rows of a table with values obtained from another table WITHIN the same column update using string concatenation. im not getting any clean way of doing this.
The goal is to achieve something like this:
UPDATE table1 set col1 =
'LANG_ID=(%s),'||
'_CHALLENGE_RESPONSE_=(%s),'||
'CRDN_NAM=(%s),'||
'CLNT_MODE=(%s),'||
'PTY_ID=(%s),'||
'CRDN_VAL=(%s),' ||
'USER_TZ_COD=(%s),' ||
'GTS_USER_ID=(%s),'||
'SP_ID=(%s),' ||
'SP_ALIAS=(%s),' ||
'ORIG_CLNT_ID=(%s)'
where table1.col1 is null
and to substitute the (%s) with data from another table2*. An example is:
update table1 set col1=
'LANG_ID=(select LANG_ID from table2* where USER_ID = (select USER_ID from table1))' ||
'_CHALLENGE_RESPONSE_=((select CHALLENGERESPONSE_ from table2* where USER_id = (select USER_ID from table1)),' ||
etc for the rest of the values

I tried this -although the database shows that the affected rows are updated! but querying the table doesn't show the values in the column!
select col1 from table1 where col1 is null
shows back the original content (DESPITE it showing me xxx rows updated!)
UPDATE table1 t1
SET col1 = (SELECT 'LANG_ID=('||lang_id||')_CHALLENGE_RESPONSE_=('||
CHALLENGERESPONSE_|| ...*
FROM table2 t2
WHERE t1.user_id = t2.user_id)
WHERE t1.col1 is null;

Similar Messages

  • SQL select a concatination of entries from another table

    I am trying to select a few columns from one table and then add another column that is a concatination or names from another table that referances it as below. Is this possible to do in one select statement?
    table x1
    ID NAME
    1 Bob
    1 Tom
    2 Bill
    table x2
    ID NAMES
    1 Bob, Tom
    2 Bill
    3

    You mean string aggregation?
    If yes, then it is possible like this, if you are on 10g.
    SQL> create table x1 (id,name)
      2  as
      3  select 1, 'Bob' from dual union all
      4  select 1, 'Tom' from dual union all
      5  select 2, 'Bill' from dual
      6  /
    Tabel is aangemaakt.
    SQL> select id
      2       , rtrim(n,', ') names
      3    from ( select id
      4                , n
      5                , rn
      6             from x1
      7            model
      8                  partition by (id)
      9                  dimension by (row_number() over (partition by id order by null) rn)
    10                  measures (cast(name as varchar2(20)) n)
    11                  rules
    12                  ( n[any] order by rn desc = n[cv()] || ', ' || n[cv()+1]
    13                  )
    14         )
    15   where rn = 1
    16  /
            ID NAMES
             1 Bob, Tom
             2 Bill
    2 rijen zijn geselecteerd.There are several other (slower) techniques possible as well. You can find them by using the search function on this forum.
    Regards,
    Rob.

  • UPDATING A TABLE WITH SAME INFO FROM ANOTHER TABLE ON THE SAME DB

    0down votefavorite
    I am trying to update a table with info from another table on the same db with same table name. I just want the info to be the same , no primary key or constraint involve just a straight replacement of records and I keep getting errors WITH THE TABLE not
    being recignize. below is my query:
    UPDATE
    VNDFIL
    SET EOBTYP
    =  VNDFIL.EOBTYP, 
    EDI_X12_835_VERSION =  VNDFIL.EDI_X12_835_VERSION
    FROM
    AGERECOVERY
    WHERE
    VNDFIL.EOBTYP
    = VNDFIL.EOBTYP
    AND
    VNDFIL
    .EDI_X12_835_VERSION
    = VNDFIL.EDI_X12_835_VERSION

    Hi rotary,
    If those two same named tables are in the same database then they have to be in different schemas. If you mean they are in the same server instance, then they may be in different databases, besides the "table not being recognized" error,
    anyway you should use the fully qualified table names, that is database.Schema.Table(If across instances, ServerName should be prefixed) to avoid the table unrecognized error.
    Using Identifiers As Object Names
    With the fully qualified names, your update statement can be like below.
    UPDATE
    db1.schema1.VNDFIL
    SET EOBTYP = srcTbl.EOBTYP, EDI_X12_835_VERSION = srcTbl.EDI_X12_835_VERSION
    FROM
    db1.schema2.VNDFIL srcTbl
    WHERE
    db1.schema1.VNDFIL.EOBTYP = srcTbl.VNDFIL.EOBTYP AND
    db1.schema1.VNDFIL.EDI_X12_835_VERSION = srcTbl.VNDFIL.EDI_X12_835_VERSION
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Default value from another table - sql query

    I'm trying to make the default value of a text item as the result from an sql or pl/sql statement. I keep getting errors when I try to use a pl/sql statement to do this. Has anyone else done this?

    OK, here is what I tried to put in. I have a form and I wanted to add a text field that is derived from another table, such as:
    select question from qa_main where seq=:quest_num
    So, what I want is to have a form where questions on tests are answered, and I want the text of the question to be brought over from the question table. I'm not sure if I'm using the correct syntax, but the ":quest_num" would be a reference to a question number in the answer table that is linked to the sequence number (primary key) in the questions table.
    Of course if there are better ideas, please let me know. :)

  • Looping delete statement where table name is coming from another table

    Hi All,
    We have to write code to delete records from active tables of WDSO.We have 5 DSO  so inspite of writing delete statement for each table we want to put all table names into one table and then loop through it .but we are getting error when we are refering that table field which has active table name.error is :
    "dictionary structure or table is either not active or does not exist "
    As per my understanding in a delete /select /insert /update statement we need to put table name (whose field we are refering ) it can't be replaced by a variable .
    ex: v_table = 'EMPLOYEE' .
    DELETE FROMv_table WHERE EMP_NAME = 'ABDC' .
    is wrong and it must be like
    ex : DELETE FROM EMPLOYEE WHERE EMP_NAME = 'ABDC' .
    but we want to make our code dynamic .
    Can you please suggest a way so that we can read the table names from another table and delete data based on some selection fom those tables .
    I tried variants ,perform etc and even searched FM for the same but not found a solution .Your help will be greatly appreciated .
    Thanks in advance .
    Regards,
    Jaya

    Hi,
    You can change your statement as follows:
    DELETE FROM (v_table) WHERE EMP_NAME = 'ABDC' .
    However, I would not recommend this. There is a standard function module RSAN_ODS_DATA_DELETE which allows selective deletion - that should be a safer way to do this. You can

  • I can't create table from another table?

    Hi everyone!
    I have a problem that I don't known the reason why?
    I'm using Oracle version 8i and I want to create a table from another table, such as:
         CREATE TABLE a_backup as SELECT * FROM a => It's OK, table a_backup is created.
    But there is only a table that I can't created like that, such as:
         CREATE TABLE b_backup AS SELECT * FROM b;
    When I run over command, SQL Plus is not responding... and clients are can't access to DB or Executing forever
    This is the first time I met this problem.
    Can Anyone help me to resolved it?
    Thanks in advance!

    xi`tin wrote:
    Hi everyone!
    I have a problem that I don't known the reason why?
    I'm using Oracle version 8i and I want to create a table from another table, such as:You realize, of course, that 8i is completely out of support .... Is your OS and hardware just as old as your rdbms software, or is it only the rdbms that your company refuses to upgrade?
         CREATE TABLE a_backup as SELECT * FROM a => It's OK, table a_backup is created.
    But there is only a table that I can't created like that, such as:
         CREATE TABLE b_backup AS SELECT * FROM b;
    When I run over command, SQL Plus is not responding... and clients are can't access to DB or Executing forever
    This is the first time I met this problem.
    Can Anyone help me to resolved it?
    Thanks in advance!

  • Create a table from another table

    I have Windows XP with 10g 10.2.0.1.0
    I need to create a table from another table to re-arrange the table column order and add the following statement at the end of creation.
    PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "TAB_DATA"
    Below iis my SQL statement, but it doesn't work. Please help.
    create table my_table as (select t1, t5, t2, t3, t4 from orig_table
    PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "TAB_DATA"
    *);*

    Kee Kee wrote:
    I have Windows XP with 10g 10.2.0.1.0
    I need to create a table from another table to re-arrange the table column order Why? Column order has no meaning. The individual SELECT statement specifies the column order that particular statement wants, which may be different from the needs of some other SELECT statement.
    and add the following statement at the end of creation.
    PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "TAB_DATA"
    Below iis my SQL statement, but it doesn't work. Please help.
    create table my_table as (select t1, t5, t2, t3, t4 from orig_table
    PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "TAB_DATA"

  • Column names from another table

    Hi All,
    I have a scenario where i need to get names of a column from another table
    for eg,
    Table EMP
    EmpNo EmpName EmpContact EmpPhone
    1 xyz [email protected] 345     
    2 abc [email protected] 897
    3 ttp [email protected] 345
    The column names of this table can be configurable from some other place and its value is stored in another table like
    Table Config (2 Columns)
    Column_Name Value
    EmpName First name
    EmpContact Email
    EmpPhone Mobile
    Now i want to fetch the values from Emp table but with column headers that are changed and have a value in Config table.
    If a column name is not there in config table then the original column name should come.
    As shown below
    EmpNo First name Email Mobile
    1 xyz [email protected] 345
    2 abc     [email protected] 897
    3 ttp [email protected] 345
    Another eg, If EmpName is not changed and entered in second table , then i want to have the same name as the original EMP table has as shown below.
    EmpNo EmpName Email Mobile
    1 xyz [email protected] 345
    2 abc     [email protected] 897
    3 ttp [email protected] 345
    In other words something like this,
    select empno,
    EmpName as (select value from config where column_name=EmpName),
                   EmpContact as (select value from config where column_name=Empcontact),
                   EmpPhone as (select value from config where column_name=EmpPhone)
         From EMP
    Can some one please help me in providing a solution for this.
    Edited by: 941386 on May 30, 2013 6:20 AM

    Unfortunately, I think this is a job for dynamic sql ...
    Build your "query" first:
    (note this won't work "as is", fix the syntax - but you get the idea.)
    lv_str := 'select empno,
    EmpName as ' || (select value from config where column_name=EmpName) || ',
    EmpContact as ' || (select value from config where column_name=Empcontact) || ',
    EmpPhone as ' || (select value from config where column_name=EmpPhone) || '
    From EMP;';
    execute immediate lv_str;Not sure if there's a better way or not.
    Only other way I can think of is to leverage the way UNION [ALL] works.
    So the following query:
    select a, b, c from dual
    union all
    select d, e, f from dual
    /returns data in columns "named" : "a, b, c"
    Effectively renaming columns d, e, f. You just need to turn your data on edge in that first query, then throw out the rows (I don't know how to get it to work, but perhaps somebody else does?)
    [edit]
    another thought is create a view over top of the table, query that view, then drop the view :P
    that would work nicely - avoid the dynamic SQL. shrug
    [edit]
    Edited by: Greg.Spall on May 30, 2013 9:37 AM

  • Breakout table (fill table with matching data from another table)

    Hi
    I've been trying to study old discussions about breakout tables. I feel I'm close, but still no cigar :-)
    In plain english, I'm trying to autocreate rows with data on a table, based on matching values from another table. E.g. have a table to display all rows where type = AssetX
    I have attached a screenshot of my "master table" called Assets:
    I'm looking to prefill Asset name, Total from this table and populate a new table called e.g. Greenhouse
    Where I'd be adding more data (date, income, expense).
    Any help whould be greatly appreciated.
    Thanks!

    Hi,
    Here is a Sample Query.
    Update Emp A
    Set Sal = (Select Sal from emp b where
    a.empno = b.empno)
    where empno in (select empno from emp);
    Regards,
    Ganesh R
    null

  • Insert missing rows from another table

    Hi
    I need to insert rows from another table if there is gaps in my transaction table. For each ärendenr there should be 5 Id status rows (1-5). Except for the fact that the inserted rows never should have higher IdStatus number then the highest value from
    the transaction for each Ärendenr. See my example below that illustrates my transaction table, Stages master and the desired result.
    Is there some t sql code that could handle this problem?
    Best regards
    Arne
    So far i have tried to solve this with the code below but it doesnt work.
    I have copied the transaction file information to the TempLogTransTimes
    and then insert into LogTransTimes
    IF OBJECT_ID('dbo.TempLogTransTimes', 'U') IS NOT NULL --Här raderas den tillfälliga tabellen
    DROP TABLE dbo.TempLogTransTimes;
    SELECT *
    INTO TempLogTransTimes
    FROM LogTransTimes
    DECLARE @TopÄrende INT
    WHILE EXISTS(SELECT * FROM TempLogTransTimes)
    BEGIN
    SET @TopÄrende = (SELECT TOP(1) Ärendenr FROM TempLogTransTimes ORDER BY Ärendenr)
    INSERT INTO LogTransTimes(Ärendenr, IdStatus, StatusNamn, SourceId)
    SELECT @TopÄrende, SM.IdStatus, SM.StatusNamn, 'Beräkning'
    FROM Statusmall SM
    FULL JOIN TempLogTransTimes LT ON SM.IdStatus = LT.IdStatus
    WHERE LT.IdStatus IS NULL
    DELETE TempLogTransTimes WHERE Ärendenr = @TopÄrende
    END
    Arne Olsson

    Hi Arne Olsson, try this..
    DECLARE @Transactions TABLE
    Id1 INT,
    IdStatus INT,
    StatusName VARCHAR(10)
    DECLARE @Stages TABLE
    IdStatus INT,
    StatusName VARCHAR(10)
    INSERT INTO @Transactions VALUES(1,1,'AA'), (1,3,'CC'), (1,5,'EE'), (2,1,'AA'), (2,3,'CC')
    INSERT INTO @Stages VALUES (1,'AA'), (2,'BB'), (3,'CC'), (4,'DD'), (5,'EE')
    ;WITH CTE AS(SELECT DISTINCT Id1 FROM @Transactions)
    SELECT Id1, IdStatus, StatusName FROM CTE, @Stages
    EXCEPT
    SELECT Id1, IdStatus, StatusName FROM @Transactions
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

  • Add rows from another table

    Hi ,
    I have a table with 20 records and 10 columns.I want to add columns from another table with out cross join.

    As others have said, you need to have some sort of join condition otherwise it is a cross join.
    SQL> ed
    Wrote file afiedt.buf
      1  with T1 as (select 'e' as c1, 2 as c2 from dual union all
      2              select 'd', 3 from dual)
      3      ,T2 as (select 'x' as c3, 5 as c4 from dual union all
      4              select 'y', 6 from dual union all
      5              select 'z', 2 from dual)
      6  --
      7  select T2.c3, T2.c4, T1.c1, T1.c2
      8  FROM (select c1, c2, row_number() over (order by c1) as rn from T1) T1
      9       FULL OUTER JOIN
    10       (select c3, c4, row_number() over (order by c3) as rn from T2) T2
    11*      ON (T1.rn = T2.rn)
    SQL> /
    C         C4 C         C2
    x          5 d          3
    y          6 e          2
    z          2
    SQL>This example assigns a row number to each row within each table and then joins using that row number.
    (I've assumed the row number should be generated based on the order of the first column of each table, but you can change that as required).
    What is the point of your requirement?

  • How to populate a table based on a row selection from another table.

    Hi, i just started to use ADF BC and Faces. Could some one help me or point me a solution on the following scenario .
    By using a search component , a table is being displayed as a search result. If i select any row in the resulted table , i need to populate an another table at the bottom of the same page from another view. These two tables are related by primary key . May i know how to populate a table based on a row selection from another table. Thanks
    ganesh

    I understand your requirement and the tutorial doesn't talk about Association between the views so that you can create a Master-Detail or in DB parlance, a Parent-Child relationship.
    I will assume that we are dealing with two entities here: Department and Employees where a particular Department has many Employees and hence a Parent-Child relationship.
    Firstly, you need to create an Association between the two Entities - Department and Employees. You can do that by right clicking on the model's entity and then associating the two entities with the appropriate key say, DepartmentId.
    Once you have done that, you need to link the two entities in the View section with this Association that you created. Then go to AppModule and make sure that in the Available View Objects: 'EmployeesView' appears under 'DepartmentView' as "EmployeesView via <link you created>". Shuttle the 'DepartmentView' to the right, Data Model and then shuttle
    "EmployeesView via <link you created>" to the right, Data Model under 'DepartmentView'.
    This will then be reflected in your Data Controls. After that, you simply would have to drag this View into your page as a Master-Detail form...and then when you run this page, any row selected in the Master table, would display the data in the Detail table.
    Also, refer to this link: [Master-Detail|http://baigsorcl.blogspot.com/2010/03/creating-master-detail-form-in-adf.html]
    Hope this helps.

  • INSERTING INTO A TABLE FROM ANOTHER TABLE

    Hi,
    I am having a table called emp in which 5 columns are there, I want to insert some rows from another table called employees, only into three columns of emp table through a sub query.
    Is this scenario is possible, I tried so many queries but it is not working out.
    Can any body help me out.
    The columns in emp table is
    empno, ename, doj, designation, salary, deptno, mgrid
    The columns in employees table is
    empno, name, hiredate, post, salary, commission, deptno, mgr
    I want to insert into empno, ename, doj, designation columns of emp table from the employees table empno, name, hiredate, post columns.
    Ramesh.

    It looks like your EMP table has 7 columns, not 5, and you want to insert into 4 columns, not 3.
    insert into emp
      (empno, ename, doj, designation)
      select empno, name, hiredate, post
        from employees;

  • FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.

    Hi,
    I have one multi record block in which i want to fetch values
    (more then one record) from another table using select statement
    IN KEY NEXT ITEM.I am getting following error.
    ORA-01422: exact fetch returns more than requested number of rows
    Thanks in advance.

    In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
    Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
    However, you can replace the explicit cursor with implicit one like
    go_block('non_db_block_name');
    first_record();
    FOR v_tab IN (SELECT *
    FROM tab
    WHERE col_name = :variable)
    LOOP
    :non_db_block_name.field1 := v_tab.col1;
    :non_db_block_name.field2 := v_tab.col2;
    next_record();
    END LOOP;

  • Create table from another table including constraints

    Hi,
    Is there a way to create a table from another table including constraints.
    CREATE TABLE COPY_EMP
    as
    SELECT *
    FROM EMP
    WHERE 1 =2 ;
    This creates the table, but the constraints are not copied over.
    I was reading about DBMS_REDEFINITION - can that be used for this scenario ?
    Thanks!
    Anand

    >
    I tried that, but the constraint names are posing a problem. And unfortunately our constraints are not named in a standard, so am finding it difficult to replace them.
    Was just wondering if there were any simpler approach to this.
    >
    No - there isn't.
    You will have to use new names for the constraints. That usually means extracting the DDL and manually changing the constraint names.

Maybe you are looking for

  • How do I remove my personal information from my old iPod touch?

    Hello everyone.  I am looking at buying a fifth generation iPod Touch and my father gave me the idea of giving him my third generation iPod Touch.  How do I go about removing my personal data, including my Apple ID from the device?  When I get the ne

  • Missing authorization for plant ' '

    User is missing authorization for plant ' ' User trace gives the following missing authorization Object: M_IS_WERKS RC=4 MCINF=S039;WERKS=' ' Can anybody help me out to find the meaning of space( ' ' ) in plant or any field? thank you in advace

  • Socket DESede encrypt/decrypt

    I have set up a class that contains methods to enrypt and decrypt a byte[] with DESede. This works great. I then created a socket client/server and sent this encypted byte array over the net. I get this error: javax.crypto.BadPaddingException: Given

  • View Maintenance disabled in development and quality

    Hi, In my development , except client 100 where I generate request, and in quality , i cannot maintain view maintenance data like fiscal period, exchange rate. Is anything missing from basis side. Also I have observed that exchange rate is creating a

  • Meta tag insertion

    I am getting a meta tag called: <meta name="verify-v1" content="eUj9BSOttNphUSpV3NQOoKlXGgLOEYIYMkD0gfJYkPw=" /> on my dwt. Anyone know what this is or how it's getting on there?