update columns in the return clause

Hi gurus

Need your new for my purpose of learning. I have the sample data.

Examples of data

DROP TABLE plch_parts;

CREATE TABLE plch_parts

(

partNum NUMBER,

partName VARCHAR2 (100),

changed_on DATE

);

---------------------------

Insertion

BEGIN
INSERT INTO plch_parts (partnum, partname)
VALUES (1, 'handle');

INSERT INTO plch_parts (partnum, partname)
VALUES (100, 'hinge');

INSERT INTO plch_parts (partnum, partname)
VALUES (500, 'lock');

COMMIT;
END;

----------------------------

DECLARE

TYPE parts_t

IS

RECORD

(

partNum NUMBER,

partName VARCHAR2 (100));

l_part parts_t;

BEGIN

UPDATE plch_parts

PartName SET = UPPER (partname)

-WHERE partnum = 1

RETURN partnum,

partName

IN l_part;

Dbms_output.put_line (' Changed: ' | l_part.partnum |) '-' || l_part.PartName);

END;

-------------

Error

ORA-01422: exact fetch returns more than number of lines

-------------------

I know the above code to support only 1 sheet update, my question is that how to I print records of all updates, I tried to use bulk collect with return clause but as Miss me something.

Please guide.

Concerning

Shu

set serveroutput on size 2000
declare
  --
  type parts_record is record (
    partnum  number,
    partname varchar2(100)
  );
  --
  type parts_table is table of parts_record index by pls_integer;
  changed_parts parts_table;
begin
  --
  update plch_parts set partname  = upper (partname)
  returning partnum, partname bulk collect into changed_parts;
  --
  for i in changed_parts.first .. changed_parts.last
  loop
    dbms_output.put_line('Changed #' || changed_parts(i).partnum || ': ' || changed_parts(i).partname);
  end loop;
end;
/

anonymous block completed
Changed #1: DOORKNOB
Changed #100: HINGE
Changed #500: LOCK

Please read http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#LNPLS005

Tags: Database

Similar Questions

  • What is the role of the RETURN clause in a pipeline service?

    I wrote several functions in pipeline and they work fine without the return clause. However, in the oracle documentation he returns in pipeline positions:
    CREATE FUNCTION StockPivot(p refcur_pkg.refcur_t) RETURN TickerTypeSet
    PIPELINED IS
      out_rec TickerType := TickerType(NULL,NULL,NULL);
      in_rec p%ROWTYPE;
    BEGIN
      LOOP
        FETCH p INTO in_rec; 
        EXIT WHEN p%NOTFOUND;
        -- first row
        out_rec.ticker := in_rec.Ticker;
        out_rec.PriceType := 'O';
        out_rec.price := in_rec.OpenPrice;
        PIPE ROW(out_rec);
        -- second row
        out_rec.PriceType := 'C';   
        out_rec.Price := in_rec.ClosePrice;
        PIPE ROW(out_rec);
      END LOOP;
      CLOSE p;
      RETURN;
    END;
    /
    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e10765/pipe_paral_tbl.htm#CHDJEGHC

    In addition, at least in PL/SQL developer I receive advice that my pipeline functions return no values, well as I said features operate smoothly. So is it necessary in the return clause in the functions of pipeline or is redundant?

    My version of oracle is 11.2.0.2.0

    You can find it in the documentation (you linked):

    A function table pipeline must have a RETURN statement that does not return a value. The RETURN statement transfers control to the customer and ensures that the next extraction Gets an exception NO_DATA_FOUND.

    HM

  • How to remove the name of the column in the select clause

    Hello guys,.

    I want to just delete a column name in the select clause. Because I don't want to write all the names of columns. I hope I am.

    In other words, I want the following.
    Select   * - unwanted_column  from table;
    
    instead of this 
    
    Select col1, col2, col3, col4, ........ col 10000 from table;

    Hello

    There is nothing in SQL, which means "all columns * except *...» ». As others have said, the only way to achieve these results in SQL is to list all the columns you want.

    Your front end may have a feature that allows you to hide a specific column. For example, in SQL * Plus, you can use COLUMN... NOPRINT , like this:

    COLUMN      dname     NOPRINT
    
    SELECT       *
    FROM       scott.dept
    ORDER BY  dname
    ;
    

    Output:

    `   DEPTNO LOC
    ---------- -------------
            10 NEW YORK
            40 BOSTON
            20 DALLAS
            30 CHICAGO
    

    There is a column called dname in the scott.dept table; the query above uses actually. But, because of the order of the COLUMN, SQL * Plus will not display this column.

    Published by: Frank Kulash on February 26, 2013 10:10
    Example of scott.dept has changed.

  • massive many update column of the cursor?

    I have the problem of finding how to make an update of several columns using the update statement block (if possible). I know how to do it using merge or correleated update, I just want to know how to write using features in bulk by pl/sql. Here's the code for the sample tables:
    create table emp_tmp as select empno, job, sal, comm from emp where deptno = 30;
    update emp_tmp set sal=1000, comm=200, job='CLERK';
    commit;
    Now, I want to update original emp table with job, sal, comm emp_tmp table for some empnos. So I write:
    declare
      cursor c is ( select e.empno, t.job, t.sal, t.comm
                    from emp e, emp_tmp t
                    where e.empno = t.empno
                    and e.empno > 7700 );
    begin
      -- ... here I would like to use bulk feature for update statement on emp
    end;
    I can't understand the syntax above idea in bulk using statements. Could you give me some advice about this? How it should be written?

    Thank you

    A sample:

    declare
      cursor csr is ( select t.empno, t.job, t.sal, t.comm
                    from emp_tmp t
                    where t.empno > 7700 );
     type t_emp is table of csr%rowtype;
     t_emp1 t_emp;
    begin
      open csr;
      loop
        fetch csr bulk collect into t_emp1 limit 100;
        forall i in 1..t_emp1.count
          update emp
          set sal = t_emp1(i).sal
          where empno = t_emp1(i).empno;
        exit when csr%notfound;
      end loop;
      close csr;
    end;
    
  • You will need to insert update column with the username?

    Hi all

    I'm new to this forum of the apex. New to apex as well.

    My question is do we have a form and a single column is editable by the user. whenever an update to this column, I need to write their name in the update column.

    I heard that we can do with trigger using the variable app_user. But in our project, they made authentication ldap for this form and when an employee login with their company login id they can see only this form of apex. no other option.

    In the same form, they were able to show the user name. I checked how they did it. they used * & user * variable for this. , It makes sense for you gentlemen?

    all I have to do is insert this & user in the column value.

    How to do this. I'm started working in the apex for the past four days alone. willing to bare with me if im a very stupid question.

    Thank you
    knani

    PS: I know that what im asking is the user name for the Web page the user name of the apex.

    Published by: kart on May 26, 2010 11:45

    Hello

    You can use: APP_USER substitution string.
    If you like to use that in the syntax of database trigger is v('APP_USER') for example

    :NEW.CHANGED_BY := NVL(v('APP_USER'), user);
    

    BR, Jari

  • How to update columns with the value of other lines in the same table

    Hello

    I use Oracle 11.2, I'd use SQL statements to update a column based on values in other rows in the same table. Here are the details:

    create table TB_test (number 4 myId, crtTs date, date of MDPU);

    insert into tb_test (1, to_date ('20110101', 'YYYYMMDD'), null);
    insert into tb_test (1, to_date ('20110201', 'YYYYMMDD'), null);
    insert into tb_test (1, to_date ('20110301', 'YYYYMMDD'), null);
    insert into tb_test (2, to_date ('20110901', 'YYYYMMDD'), null);
    insert into tb_test (2, to_date ('20110902', 'YYYYMMDD'), null);

    After you run the SQL code, I would like to have the following result:

    1, 20110101, 20110201
    1, 20110201, 20110301
    1, 20110301, null
    2, 20110901, 20110902
    2, 20110902, null

    Thanks for your suggestion.

    I guess you need this, otherwise please explain logic correctly:

    SQL> merge into tb_test t
      2  using (
      3    select rowid as rid
      4         , lead(crtts) over(partition by myid order by crtts) as updts
      5    from tb_test
      6  ) v
      7  on (t.rowid = v.rid)
      8  when matched then update
      9   set t.updts = v.updts
     10  ;
    
    5 rows merged.
    
    SQL> select * from tb_test order by 1,2;
    
          MYID CRTTS     UPDTS
    ---------- --------- ---------
             1 01-JAN-11 01-FEB-11
             1 01-FEB-11 01-MAR-11
             1 01-MAR-11
             2 01-SEP-11 02-SEP-11
             2 02-SEP-11
    
  • Updating column in the table using forms...

    Well Guyz I got my submission today... everything went well... .but yet they want to add IE more features want to donate this application at different times working in the company on different projects... .initailly told me that u have to create this application for just our project, now they use my work to give to other PMsss:(et prendre tout le crédit avec aucun faisait pour moi u n personnes m'a beaucoup aidé dans la construction de cette application...) Well, they want to create an application where they can change some columns... that is to say over write the existing value in a column with a new value.
    Now, suppose I have col1, col2 in the table paymast, how should I proceed to create trigger for when I press the button on the form is updated to the number of given employee (I want to say if enter the respective information for the particular EMP as soon as I press the button the old values shud b replaced by new values...)

    A method that I have noe is to use the wizard to create the form n, and then enter the value of the respective areas of the column to be updated n, then press F6 DB... .i do not want to use this function...

    I want to update the application by pressing the button

    soon :)

    Published by: Chase Suhail on Nov 15, 2009 12:26 AM

    Published by: Chase Suhail on Nov 15, 2009 12:29 AM

    Published by: Chase Suhail on Nov 15, 2009 12:30 AM

    Published by: Chase Suhail on 15 Nov 2009 02:05

    I don't know a lot of your application, but if you build it near standard forms (e.g. base your blocks on the tables), then its standard Frédérique you type the new value in the field and press save. the button... do you want to the "economy"? then put a DO_KEY ('COMMIT_FORM'); in it.

  • email accounts + updated column on the page of the options not available

    Hello, sorry to ask this, but I can't find a similar problem on the community forum:

    I tried to change the look of my Thunderbird and switched in Vertical mode, now all the options in the view > page layout are empty, no way to change it back...

    Second question: while I was managing the columns in layout with the cursor, the one on the left with all accounts, now gone, there seems to be no way to recover it. It appears when I run Thunderbird for a fraction of a second, then nothing.

    I even removed Thunderbird and installed it again, but it opens with the same layout.

    Is there anyway that I can change to the default layout?

    Thanks for any help.

    Are you using a Add ons? If so restart with Add ons disabled in order to see if it works better. Helps in the menu.

  • Managed CPU driver loads using the output to the RETURNING clause parameter

    Using version 4.121.1.0, If code


      
       OracleCommand mycommandUpdateDB = new OracleCommand(ActualOperationalSQL, OracleConnect);
    ActualOperationalSQL = "INSERT INTO SYSTEM_USERS(LOGIN , PASSWORD, STATE)  VALUES (:LOGIN , :PASSWORD, :STATE) return SYSTEM_USERS_ID into :IDD";
                                  mycommandUpdateDB = new OracleCommand(ActualOperationalSQL, OracleConnect);
                                 mycommandUpdateDB.Parameters.Add(":LOGIN", "4444");
                                 mycommandUpdateDB.Parameters.Add(":PASSWORD", "444");
                                 mycommandUpdateDB.Parameters.Add(":STATE", "3434");
                                 mycommandUpdateDB.Parameters.Add(":IDD", Oracle.ManagedDataAccess.Client.OracleDbType.Int32, ParameterDirection.ReturnValue);
                                mycommandUpdateDB.ExecuteNonQuery();
                                string ID_NEW_OBJ = mycommandUpdateDB.Parameters[":IDD"].Value.ToString();
    


    runtime error does not occur , but the program " " "" freezes " and load the processor 25%.
    Any error could not do of the program.

    Do you see the question if you replace the keyword 'return' with the keyword 'return '. (for example) instead of

    "INSERT INTO SYSTEM_USERS(LOGIN, PASSWORD, STATE) VALUES (: LOGIN: PASSWORD: STATE) return SYSTEM_USERS_ID in: DLI;

    can you please try

    "INSERT INTO SYSTEM_USERS(LOGIN, PASSWORD, STATE) VALUES (: LOGIN: PASSWORD: STATE) return SYSTEM_USERS_ID in: DLI;

    It work?

  • Columns in the WHERE clause - order affect the output?

    I work on some queries to feed a DWH and stumbled upon this question. Let's say I have this query:
    (SELECT ARTREGNROS FROM gx.artabo aa,gx.toccab tc1
                    where aa.artid=tc1.artid
                    and t.tocid=tc1.tocid
                    and aa.abocod=c.abocod
                    and aa.artconcod=c.concod
                    and aa.percod=a.percod
                    and aa.ArtAboFlgA='S'
                    ) Tarjeta
    The exit will happen anyway if I do like this:
    (SELECT ARTREGNROS FROM gx.artabo aa,gx.toccab tc1
                    where aa.artid=tc1.artid
                    and a.percod=aa.percod
                     and aa.ArtAboFlgA='S
                    and tc1.tocid=t.tocid
                    and c.abocod=aa.abocod
                    and aa.artconcod=c.concod
                     ) Tarjeta
    I guess what he used, or at least I him did not change with the data that I use, but I thought to check here once just to have peace of mind. Maybe it's not the happiest example, but I guess the question is clear

    No difference.

  • Update or merge it with the return data

    Hello, I want to do an update in a single statement, and select (I want to get the data and update a field in one of the tables involved with a timestamp), I tried this:

    merge into table t

    using (SELECT ... a long and complex select...) e

    on (e.ID = t.ID)

    When matched then

    update the value t.ts = systimestamp

    e return

    It does not work because his return does not seem possible with the merger, he did the update but I get no data...

    With an update, I tried:

    Update

    (

    SELECT...) e

    Aliens set = systimestamp

    And I get ORA-01779: cannont change a column that maps to a table of key-preserver nonkey.

    The select is complex with many paintings and selects involved and more than 20 KB of text only select... and this isn't mine so I want a solution that does not need to change the internal selection if possible.

    Any ideas? Sorry for my limited knowledge of sql :-(

    No, you did not read what I said.  The RETURNING clause allows you to capture the details of the update table.  You may not have the details of the complex query that you use to determine the return lines.  There is no way in SQL to a single statement that updates a table and queries data from other tables at the same time.

    The best you're going to manage is to update the data, turning the ID (or regardless of the primary key is appropriate) and then query the query data complex where once again the ID in your collection.  However, it's really messy.  What US the real purpose of all this?

  • parent ID column in the outbreak of the child

    Hello

    It's Jean Philippe

    I use a sequence to generate the primary key column in the table emp

    but I continue in this mode for n1.dept_id | Seq.nextval in emp_id

    (IE dept_id + sequence becomes the employee id)

    and I also, child table

    in the child table that I need to insert this manually generated emp_id in emp_id (referenced column) child table

    How to insert

    Please let me know

    Thank you

    You could use the RETURNING clause on your insert statement to get the value that the trigger is created and then use this value in your child table for example inserts

    SQL > create table emp_parent (ID, ename varchar2 (50), number of deptno)
    2.

    Table created.

    SQL > create table emp_child (ID number, emp_parent_id number, varchar2 (50)) txt
    2.

    Table created.

    SQL > create sequence generic_sequence
    2.

    Order of creation.

    SQL > create trigger TrgEmpChild before insert on emp_child
    2 for each line
    3. start
    4: new.id: = generic_sequence.nextval;
    5 end;
    6.

    Trigger created.

    SQL > create trigger TrgEmpParent before insert on emp_parent
    2 for each line
    3. start
    4: new.id: = (: new.deptno * 10000) + generic_sequence.nextval;
    5 end;
    6.

    Trigger created.

    SQL > declare
    2 number of EmpParentId;
    3. start
    4 insert into emp_parent (ename, deptno)
    5 values ('Fred', 10)
    6 return id in EmpParentId;
    7 insert into emp_child (emp_parent_id, txt)
    8 values (EmpParentId, ' Some child Text ');
    9 validation;
    10 end;
    11.

    PL/SQL procedure successfully completed.

    SQL > select * from emp_parent;

    ID ENAME, DEPTNO
    ---------- -------------------------------------------------- ----------
    100001 Fred                                                       10

    SQL > select * from emp_child;

    ID EMP_PARENT_ID TXT
    ---------- ------------- --------------------------------------------------
    2 100001 certain child text

  • updating columns by using variables substitiution dataform

    Hi all

    I would like to know if there is any chance to update columns in the form of data using proxy.
    As if I need to create a form of data from jan to & currmonth. (June), so changing the value subvar say August, I'll be able to get the columns dynamically in the change of form of data until August. ?

    Thank you

    Hi, yes you can create a hierarchy of alternative for periods. For more information, see rolling forecast Web Form

    You can then use the descendants function of your other rollups

    Another way to define your period as sparse. Periods a link to an attribute fades with 1... 12 for the month and try to use fewer function selector Member dataform

    As you can see, none of them is easy

  • Slider with return return clause

    Hello

    What is the use of the cursor with return return clause?


    Thank you

    REDA

    Hello

    The return clause lets you create a specification for the cursor and always hide the implementation.

    So you can write in the specification of the package:

    CURSOR emp_cur (empno IN emp.empno%TYPE) RETURN emp%ROWTYPE;
    

    And then put in place the cursor in the body, as usual.

    Read all the docs
    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/packages.htm#LNPLS00910

    Concerning
    Peter

  • DML with values returned of dml another inside the WITH clause

    Hello community, I want to use the ELECTION of an insert or update values to other insertion within a single transaction without staging of values returned. Here's what I mean. In some other dbs, I can do it like this

    WITH moved_rows AS)

    DELETE FROM products

    "WHERE purchased_date > = ' 2010-10-01' AND purchased_date < ' 2010-11-01"

    RETURN *.

    )

    INSERT INTO products_log

    SELECT product_id, product_date, sysdate, user moved_rows;

    I know the return value must be assigned to a local variable before they can be used within other dml, but I'm curious to know if the approach described above is supported in Oracle. Note that outside dml returns all columns (*) of the table products and then I took and chose the values I want to be inserted in the log table.

    Hello community, I want to use the ELECTION of an insert or update values to other insertion within a single transaction without staging of values returned. Here's what I mean. In some other dbs, I can do it like this

    WITH moved_rows AS)

    DELETE FROM products

    WHERE purchased_date > = "2010-10-01' AND purchased_date<>

    RETURN *.

    )

    INSERT INTO products_log

    SELECT product_id, product_date, sysdate, user moved_rows;

    I know the return value must be assigned to a local variable before they can be used within other dml, but I'm curious to know if the approach described above is supported in Oracle. Note that outside dml returns all columns (*) of the table products and then I took and chose the values I want to be inserted in the log table.

    Non - "approach above" don't is NOT supported in Oracle.

    For operations from multiple tables, you must use SET of treatment to prevent other sessions modify data during your transaction.

    Jarkko #8 post shows the steps involved.

Maybe you are looking for

  • Storage utilization &amp; iCloud &gt; storage management &gt; Photos and camera

    I'm trying to free up storage on my iPhone 6 more running iOS 9.3.1. Photos is empty. Recently deleted photos is empty. Photos is disabled in settings > icloud > photos. The rockers are disabled in the settings > photos and camera. But its still appe

  • Network printer

    I have a printer 1522nf MF that is connected with a cable to a PC HP Windows 7. A router is also connected to the PC. I'm trying to get my laptop to print over my home network, but the printer does not appear on my laptop.  The printer is a network p

  • HP DV7T 6100 CD ROM DOES NOT

    6100 windows 7 DV t 8.1When I insert a disc turn as it will read and then stops with no messages or anything. CD ROM IS NOT READING DISC. I don't know whether or not this has begun with the new windows update.

  • I can't print from my wireless Mac

    I have to use the cord to print from my Mac.  But surprisingly, others in my house can print to the HP Office Jet Pro 8600.  What gives?

  • I get an error when I connect to my computer that says Core Services Shell.exe - Application error

    Original title: shell.exe basic service error I get an error when I connect to my computer that says:Core Services Shell.exe - Application ErrorThe exception unknown software expection (Oxc0000409) occurred in the application at location 0x0b98deaa.