How to perform an addition of column values in an insert query that would insert in the 3rd column, and the values how to insert into another table.

I have two tables (2) RESULT TAB (1)

CREATE TABLE TAB

(

NUMBER OF SNO

A NUMBER,

B THE NUMBER.

NUMBER OF THE SUM

);

CREATE AN ARRAY OF RESULT

(

NUMBER OF SNO

NUMBER OF THE SUM

)

my doubt is:

(1) I want to insert a table TAB, my question is how to insert a column to the SUM using the column A AND B... Here im adding two values of the column and store result in the AMOUNT column.

SNO   A  SUM           

1 100 150 250

2 300 100 400

I want to like this, it is possible with single insert query?


(2) at the time of the insertion TAB of values that SNO, and the values of table TAB $ insert in the table of RESULTS... is it possible these two inserts at the same time?

in fact, im using another this table.fro TAB and easy to understand I write like that, please solve this problem

First, you post in the wrong forum as this one is only for Oracle's SQL developer tool. So you might ask your question in the general forum of SQL.

Second, you might solve your problems with bind variable:

Insert tab

(sno, a, b, sum)

values

(: SNO,: A: B: A + B :))

You should not use sum as column name because it is a reserved word.

More you cannot insert into two different tables with a single SQL, but you can use PL/SQL to do this:

Start

insert into tab values (: SNO,: A: B: A + B :);)

insert into result values (: SNO,: A + B :);)

end;

If you meet sno from a sequence, you could do something like this:

Start

insert into values tab (seq_sno.nextval,:,: B,: A +: B) return sno in: SNO.

insert into result values (: SNO,: A + B :);)

end;

Hope that helps,

dhalek

Tags: Database

Similar Questions

  • [11g] ORA-22993 when extracted xmltype great values in the outbreak of the BIU as a CLOB in another table

    [I ask nicely for a few comments for this question.

    Someone else can reproduce it with the test below?

    Is my code invalid or false?

    Or what is the problem here?

    -Thank you

    Frank

    ]

    Hello

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for Linux: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    Trigger Before Insert or Update to a table, I invoke a PL/SQL package function to check the size of an xmltype column (passing as IN OUT NOCOPY).

    PL/SQL functions retrieves the xmltype. GetClobVal(), check its size, and when it is beyond a limit, he tries to insert the data into another table (GTT - global temporary table).

    Finally, it changes the value of the value of the column of xmltype to the shorter XML (just by referring to the corresponding record in the TWG).

    But the Insert SQL in the TWG operation strike ORA-22993: specified input is greater than the amount actual source.

    I don't know why this happens. In the internet I only find references on importing files in lob/clob.

    Anyone have the same problem?

    I know that you prefer to have a sample program to demonstrate the problem - I'll try to post one, but it will take time.

    But maybe someone can help me based on the information above already.

    -Thanks a lot!

    Best regards

    Frank

    I have reproduced the issue.

    It must be a bug.

  • Validate values inserted into a table against an another record in the table.

    Hi, I have this two tables on my Oracle Database 10g:
            Status                                    
    
    Id_Status | Description        
    --------------------------------       
      102     |   Ok                 
      123     |   Damaged 
      345     |   Broken
    
    Cars
    
    Car_ID|  wheel  |  hood  |  bumper  |  radiator
    -------------------------------------------------
      1   |   1     |     2  |     2    |   3
    and what I have to do is to make sure that you can only insert a record if the [wheel, hood, bumper, radiator etc...] values are values that already exist in the State of the table, but I do not know if you add FK as:
    ALTER TABLE "RCVRY"."COMPANY" 
        ADD (CONSTRAINT "CITY_ID" FOREIGN KEY("STATE") 
        REFERENCES "RCVRY"."CITIES"("STATE")
    is the right way to do it.

    If anyone can help by providing code samples or pointing to the right place in the documentation to look out it will be greatly appreciated.
    Concerning

    JMHP

    Hello

    José M. Hurtado says:
    Hi, I have this two tables on my Oracle Database 10g:

    Status                                    
    
    Id_Status | Description
    --------------------------------
    102     |   Ok
    123     |   Damaged
    345     |   Broken
    
    Cars
    
    Car_ID|  wheel  |  hood  |  bumper  |  radiator
    -------------------------------------------------
    1   |   1     |     2  |     2    |   3
    

    and what I have to do is to make sure that you can only insert a record if the [wheel, hood, bumper, radiator etc...] values are values that already exist in the State of the table, but I do not know if you add FK as:

    ALTER TABLE "RCVRY"."COMPANY"
    ADD (CONSTRAINT "CITY_ID" FOREIGN KEY("STATE")
    REFERENCES "RCVRY"."CITIES"("STATE")
    

    is the right way to do it.

    Yes, foreign keys are the right way to do it.
    Make sure that first of all, there is a constraint of PRIMARY KEY (or UNIQUE) on status.id_status.

    If anyone can help by providing code samples or pointing to the right place in the documentation to look out it will be greatly appreciated.

    The code you have posted has an imbalance ' (' between ADD and CONSTRAINT.) Lose that ' (' and you have the right syntax.)
    Double quotes are necessary only if you use non-standard names. Do not.
    The schema name (RCVRY in the above example) is optional.

    So, you could say:

    ALTER TABLE     cars
    ADD CONSTRAINT     cars_wheel_fk
    FOREIGN KEY     (wheel)
    REFERENCES     status (id_status)
    ;
    

    I hope that answers your question.
    If this is not the case, after a test script.
    Publish instructions CREATE TABLE for tables and ALTER TABLE instructions for constraints (if they are not part of the CREATE TABLE statements).
    Let's just do the constraint on wheel first. Once you know how to do this, add similar constraints for the other columns (radiator, hood, bumper,) will be easy.
    After a series of INSERT statements (and update, if you want) for the two tables, which must be executed in order.
    Say if you want as each INSERT (or UPDATE) statement of work or not. (Include a few of them).

    Published by: Frank Kulash, December 7, 2010 19:15

  • How to identify the name of the procedure that inserts into a table in the TRIGGER

    Hello
    There are several procedures in my DB that perform the INSERT operation on a main table - MYTAB say.

    I created a trigger on the table MYTAB, to follow closely, what procedure is insert data in there. Is there a function that captures the name of this object?

    For example: PROC_A, PROC_B, PROC_C insert into the table MYTAB. And my query is - the trigger on table MYTAB should document these object names where the lines fit.
    Please let me know your suggestions...

    SQL> create table t (no integer, dt timestamp, who_inserted varchar2(4000));
    
    Table created.
    
    SQL> create or replace procedure p
      2  as
      3  begin
      4    insert into t (no, dt) values (1, systimestamp);
      5  end;
      6  /
    
    Procedure created.
    
    SQL> show err
    No errors.
    
    SQL> create or replace trigger t_trig before insert on t for each row
      2  begin
      3     :new.who_inserted := dbms_utility.format_call_stack;
      4  end;
      5  /
    
    Trigger created.
    
    SQL> show err
    No errors.
    
    SQL> begin
      2    p;
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> select * from t;
    
            NO DT                             WHO_INSERTED
    ---------- ------------------------------ ----------------------------------------
             1 31-OCT-14 04.58.53.668465 AM   ----- PL/SQL Call Stack -----
                                                object      line  object
                                                handle    number  name
                                              3a7ddbea0         2  KARTHICK.T_TRIG
                                              3ac979f30         4  procedure KARTHICK.P
                                              3a822deb8         2  anonymous block
    
  • call a function inside a function to insert into a table and receiver error - ORA-14551: cannot perform a DML operation within a query.

    Hi all

    your help is greatly appreciated...

    Calling B.fucntion inside an A.fonctions to insert data into a table.


    Here when you call the B.fucntion to insert data in the table... receiver AM a mistake

    Omitted in B - SQL Error: ORA-14551: cannot perform a DML operation inside a query...


    Can someone please help me to clarify this...


    The FUNCTION A(varUPD_TYPE IN VARCHAR2) RETURN VARCHAR2 IS
    varRETURN_VALUE VARCHAR2 (25): = NULL;

    numALLOWED_COUNT PROD. PROCESS_COUNTER. TYPE % ALLOWED_COUNT;
    numLAST_COUNT_ADDED PROD. PROCESS_COUNTER. TYPE % LAST_COUNT_ADDED;
    dtCHANGE_DATE DATE: = NULL;
    varSTMT VARCHAR2 (2000);
    bln_Allowed BOOLEAN;
    myVar VARCHAR2 (32767).


    BEGIN

    IF varUPD_TYPE = "A" THEN

    BEGIN
    SELECT CH_DATE, LAST_COUNT_ADDED, ALLOWED_COUNT
    IN dtCH_DATE, numLAST_COUNT_ADDED, numALLOWED_COUNT
    PROD. PROCESS_COUNTER
    WHERE NOM_PROCESSUS = "DAILY".
    AND COUNTER_IND = A '

    IF dtCH_DATE < = trunc (sysdate) THEN
    numLAST_COUNT_ADDED: = 0;
    END IF;

    EXCEPTION
    WHILE OTHERS THEN
    numLAST_COUNT_ADDED: = 0;
    numALLOWED_COUNT: = 1;
    END;
    IF numALLOWED_COUNT > = numLAST_COUNT_ADDED + 1 THEN

    bln_Allowed: = True;

    varSTMT: = "UPDATE PROD. TMS_PROCESS_COUNTER ';
    varSTMT: = varSTMT | ' SET last_count_added = ' | (numLAST_COUNT_ADDED + 1);
    varSTMT: = varSTMT | "WHERE nom_processus =" DAILY "';
    varSTMT: = varSTMT | "AND COUNTER_IND ="D"';


    IF varSTMT IS NOT NULL
    THEN
    MyVar: = B(96,varSTMT);
    PROC_LOG (' CALL B ': myVar);
    IF myvar > 0 THEN
    NULL;
    END IF;
    END IF;
    On the other

    End if;

    END IF;

    EXCEPTION WHEN OTHERS THEN
    PROC_LOG ("A failed '");
    PROC_LOG (' SQL error: ' |) SUBSTR (SQLERRM, 1, 1000));
    RETURNS A NULL VALUE.
    PUT AN END TO;

    The FUNCTION B(numTABLE_ID IN NUMBER, varSQL_STATEMENT IN VARCHAR2) RETURNS NUMBER IS
    varINSERT_BATCH_STMT VARCHAR2 (32767): = NULL;
    varADD_REC_TYPE BATCH_TABLES. TYPE % ADD_REC_TYPE;

    BEGIN

    INSERT INTO BATCH_STATEMENT (ID, TABLE_ID, STATEMENT, QUEUE_SEQUENCE_ID)
    VALUES (Numidian, numTABLE_ID, varSQL_STATEMENT, 1);

    EXCEPTION WHEN OTHERS THEN
    PROC_LOG ('B failed');
    PROC_LOG (' SQL error: ' |) SUBSTR (SQLERRM, 1, 1000));
    RETURNS - 1;
    END B;


    Structure of the Batch_statement table:


    ID Number (15) not null
    number (2) not null table_id
    Statement varchar2 (4000) not null
    Queue_sequence_id number (5) not null


    Why do you do such coding mess full of bad practices.

    Remove the exceptions WHEN OTHERS, you're a turing a mistake in this way, they are bugs and (never) use functions to perform DML.

    Functions are not intended for DML. Period.

  • How to insert into DB tables of bean

    I want to insert in some custom tables of bean. How

    (1) get the connection?

    (2) can someone please give me the code?

    (3) how to engage? or the transaction AM will assign commit?

    (4) I intend to do so in the following manner, but I am getting error "getDBTransaction method not found" even if I imported all needed packages

     

      DBTransaction trans = getDBTransaction();

          CallableStatement statement = null;

          int rows = 0;   

          String plsql =

                " BEGIN "

              + " INSERT INTO EMPLOYEES "

              + " VALUES (?,?,?);"

              + " END; ";

           

          statement = trans.createCallableStatement(plsql, 3);

          try{

              statement.setInt(1, empName);

              statement.setInt(2, empId);

    statement.setInt(3, deptId); 

             rows = statement.executeUpdate();

    (5) I'm doing right thing by inserting Backing Beans? Ideally, I know we do h, but how I read AM screen values?

    All the world done this before? any help?

    Thank you

    Rahul

    Do not like that!

    I would do the following:

    -Create an entity object, then a view based on this object to insert lines.

    -Write an Application Module method that gets values that must be inserted as parameters. Get the VO, create a new line, set the values and insert the line.

    -To make this method available in the interface of the AM AM.

    -Create the binding of the method in the user interface.

    -Use this method within managed bean and run the validation using binding validation operation.

    I hope this helps.

    Kind regards

    Linda

  • How to pass the variable to a swf into another swf

    I declared a variable in the one.fla file

    I open another file swf on a button.

    the code is as follows

    name = 'personName ';

    myButton.onRelease = function () {}

    trace ("liberation" + name);     personName

    loadMovie ("mainPage.swf", _root);

    _root.loadMovie ("mainPage.swf");

    }

    I want the variable 'name' of access to another swf file. IE (mainPage.swf)

    How do I do that?

    You want to use the MoveClipLoader class (using loadClip() and addListener methods) rather than loadMovie so that you can wait for the file to load before you try to access anything in it.  You can create an empty movieclip to load the SWF in, and in this way the loaded file can be targeted using the empty movieclip instance name.

  • How to set the default on a table when data is inserted in another table

    Hi all
    I use Jdeveloper 11.1.1.2 and ADFBC.
    I have two tables and tableA, tableB.
    I wish that when I insert a line in tableA, automatically, a row is inserted in tableB.
    How can I do? Creating a java class for tableA OS? How can I reference/create a line in the area of occurrence of another table?

    Thank you

    Andrea

    When you want that to happen... If you want to occur when you run the page, then have it in the getter()... If you like... When you set it... then's it in the Set accessor... You manually assign the id. or is he from any order?

  • I can create a text box so that it grows with the amount of text entered into it?  I don't see how a defined size.

    I have a form and am adding text boxes.  I want them to be able to grow with the amount of text entered by the user.  It is essentially to 'comments' on a form.  Most of the text boxes may only need a few words, and some may be 2 paragraphs.  It seems that I have to create a text box and give it a static size.  Is that what I am missing how?

    Thank you!

    Michelle

    I can still see the 'Auto' as font size.

    If you want dynamic fields, then you must use LiveCycle or be prepared to do a lot of redesign of the form and coding.

  • How export a project consisting of 2 video tracks with many clips/effects and 1 stereo audio track so that the project can be worked into another compatible editing system?

    How do I export a project composed of 2 video tracks with many clips/effects more 1 stereo audio followed that project ACR is still worked in a


    compatible mounting system? Thank you!!

    When you export, you create a new video file that will have effects applied... in other words, a book finished

    Of course, this video 'complete' may be edited by someone else on another computer... but it SEEMS to me that what you want is for someone to take your editing, continue editing, THEN export a finished video

    Is this correct?

    If so, do some reading in the help file on the Manager project, so you can put your project and all files on an external drive to give to any other person

  • How less INT from another table

    Hello

    How could I go to try at least an intiger of two tables?

    for example:

    1 event has an availability of 100 seats.

    1 user can complete 1 transaction (1 sheet) but select several places to book through this 1 transaction.

    The event would then 98 seats available.

    Untitled-1.png

    It would be better to display through php, or it is set to a field in the event table (for example, current_availability)?

    PS do not know if this makes sense.

    So seats_amount of booking could be 1, 2, or more, depending on the number of reserved seats. With SQL, you can get the sum of the seats_amount like this: SELECT SUM (seats_amount) FROM booking WHERE the... You might return the number of original_availability and the sum of reservation in the same query if you use a LEFT JOIN to the reservation. (A left join is necessary because if nobody has yet booked, there was no result returned by reservation).

    Then I'd do the comparison in PHP to see if there are places available, taking into account the number of places required by the current transaction.

  • Performance problem on the SQL query that does not use the primary key index

    Hello!

    I have some performance issues on a single SQL query (Oracle 10 g).
    I could solve the problem by using the INDEX indicator, but I would like to know WHY this is happening.

    * Tables *.
    create table jobs)
    ID number (5) not null,
    name varchar2 (100),
    primary key constraint Job_PK (id)
    )
    /
    -Record count: 298

    create table Comp)
    integer ID not null,
    name varchar2 (100),
    primary key constraint Comp_PK (id)
    )
    /
    -Record count: 193

    -Relation m: n
    create table JobComp)
    integer ID not null,
    id_job integer not null,
    id_comp integer not null,
    primary key constraint JobComp_PK (id),
    unique key constraint JobComp_UK (id_job, id_comp),
    Constraint JobComp_FK_Job foreign key (id_job) refers to Job (id),
    Constraint JobComp_FK_Comp foreign key (id_comp) makes reference Comp (id)
    )
    /
    create index JobComp_IX_Comp on JobComp (Cod_Comp)
    /
    create index JobComp_IX_Job on JobComp (Cod_Job)
    /
    -Record count: 6431

    * Ask *.

    When I run this query, the execution plan shows the index using (JobComp_PK and JobComp_IX_Comp).
    No problem.

    Select JobComp.*
    of JobComp
    Join jobs
    on Job.id = JobComp.id_job
    where JobComp.id_comp = 134
    /
    -runs in 0.20 sec

    But when I add the field 'name' of the work table the plan uses full access table to the table of work

    Select JobComp.*, Job.name
    of JobComp
    Join jobs
    on Job.id = JobComp.id_job
    where JobComp.id_comp = 134
    /
    -runs in the 2.70 dry

    With the help of the index

    Select / * + INDEX (Job Job_PK) * /.
    JobComp.*, Job.name
    of JobComp
    Join jobs
    on Job.id = JobComp.id_job
    where JobComp.id_comp = 134
    /
    -runs in 0.20 sec

    * Doubt *.

    This behavior is correct?

    PS. : I tried to recalculate the statistics, but nothing changes:

    analyze the job calculation table statistics.
    /
    change the statistical calculation of index Job_PK reconstruction;
    /
    Start
    dbms_utility.analyze_schema (sys_context ('userenv', 'current_schema'), 'CALCULATE');
    end;
    /

    [of]
    Gustavo Ehrhardt

    Gus.EHR wrote:
    Hello.
    I'm sorry for the plan unformatted.
    The execution time of the querys "without field name' and 'with the field name with suspicion" are equal.
    He has no problem caching, because I get the plans of the sequence different from the querys and repeated the performance. The result is always the same.

    I don't think that there is no problem with oracle crossing LOOP IMBRIQUEE to the HASH JOIN when you include the field name and this should be the expected behavior. But it seems that your WORKING table has a degree of parallelism set against what is causing the query to run in parallel (as JOB table is now available with full table scan, instead of indexed access earlier). It could be that the parallel execution is contributor to extra Runtime.
    (a) do you know why the degree of parallelism on the WORK table has been defined? Do you need it?

    You can see if the following query provides a better response time?

    select /*+ NOPARALLEL(JOB) */ JobComp.*, Job.Name
      from JobComp
      join Job
        on Job.id = JobComp.id_job
     where JobComp.id_comp = 134
    
  • Satellite L675 - how to change into another language (Windows 7)?

    We recently bought a number of L675s with Windows 7 Home Premium. I installed it with the language = German, but a couple of our staff now came back and asked to have the English instead. The machines came with four languages (English, German, French, Italian), but once installed, it is not possible to change the language. Not even using the recovery disk. What should I do to achieve it - buy the Toshiba Recovery disk support?

    Hello

    As far as I know it of not possible to change the language after you have selected the language during the installation process.
    So either you will modernize the Windows 7 Enterprise or Ultimate and install a package of multiple language (it is available for the version of Win 7 Enterprise and Ultimate only), or you can buy the here Toshiba Recovery disk:
    http://backupmedia.Toshiba.EU/landing.aspx

  • How to add text on an image that is inserted into a table in Dreamweaver

    I am relatively new to dreamworks and I saw the easiest way so far is the use of tables to make your layouts, I wonder if there is a way where you can insert text on (in front of) an image that fits into a table?

    Easy and best are not synonymous.  The best way to create modern web pages is no tables with CSS layouts.   If someone told you of tables are better, they are ill-informed, out-of-touch and/or you are looking at a tutorial very old.

    Getting back to your original question, put your image in the background with the CSS code.

    CSS background-image property

    If you are not familiar with HTML and CSS code, you will need to do some homework first.  He had to learn to get the most out of Dreamweaver.

  • How to update a table and insert into another

    I need to update a table and also to insert into another table and want to do it in the same form. I can it will break in 2 different forms, but it is awkward for the user. Is there a way common to this address? As a backdrop, the user is updated the status of a message (IE, changing it from open to closed) and then provide an answer. The response table is separate from the table of messages because its format is doing different.

    Thank you and sorry to bombard the forum today.

    .oO (davidbarrackphoto)

    > I need to update a table and also to insert into another table and want to
    > do it in the same form. I can it will break in 2 different forms, but it is
    > awkward for the user. Is there a way common to this address?

    You can do what you want in your form processing script. But for
    much more advanced than you must write your own code.

    > As a backdrop.
    > the user updates the status of a message (IE, changing it from open to closed)
    > and then provide an answer. The response table is separate from the table of messages
    > because its format is doing different.

    Just curious: what is the difference? IMHO, there should be only one table
    for messages. Can you post more details about it?

    Micha

Maybe you are looking for

  • I just accidentally deleted all of my favorites. How can I get these?

    Bookmarks were in a folder with several subfolders,

  • Want 5530: Print speeds double

    I'm unhappy with my 5530 want new all-in-one. First of all, it would not print from MS Word documents with precision (is not WYSIWYG).  Repeated Downlods of the pilot has not solved the problem and I was finally told by HP to replace the Envy pilot w

  • How do you get $_SESSION vars in jquery mobile

    Hello everyone. I'm creating a mobile application with jquery. I have created.a connection format that uses getJSON() to validate the connection with photos. If successful the login.html redirects to the loggedin.html. I kept the name of user in. A s

  • CSS media queries

    Making browsers OS 5 and 6 both CSS media queries? I am trying to create style sheets separate to a Torch, Bold (9700) and a curve (9300). http://forabeautifulweb.com/blog/about/hardboiled_css3_media_queries/

  • RV180 behind DSL ROUTER cannot connect with QuickVPN

    Hello I would like to ask if it is possible to configure the RV180 behind my DSL router to connect using QuickVPN. First of all, I tried to connect to the PPTP server and worked fine, but when I tried to connect using QickVPN, seems to connect, but w