Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

may be stored procedure.

Posted on 2014-01-22
11
Medium Priority
?
290 Views
Last Modified: 2014-02-06
I Have Table T1(A,B,C) and I have a Table t2(D,E,F).

when ever i want to insert on table t1 in coulmn A,B,C. I want to insert it into table T2 same value for clumns in T1 + may be  appending some additional value to table t2 or .

what would be the best approach and can i sample code for it.

for ex:
if insert (USA,UK,IND) in to T1 i need to pass values and append 001 for USA and 044 to uk and 091 to IND and it should insert like (USA001,UK044,IND091).

in above example 001,044,091 should be any value i want to append it to the value in table T1.
0
Comment
Question by:ajaybelde
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39800887
An insert trigger on t1 might work.

Where are you getting the values to append?

I don't see how a stored procedure would work unless you have some 'new' flag in t1 that the procedure can process in batch mode.
0
 

Author Comment

by:ajaybelde
ID: 39800892
its manual
0
 
LVL 78

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 1000 total points
ID: 39800897
So how do you know what records in t1 need manual values added to t2?
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 1000 total points
ID: 39800908
something like this?


CREATE OR REPLACE PROCEDURE insert_two_table(
    p_a   IN VARCHAR2,
    p_b   IN VARCHAR2,
    p_c   IN VARCHAR2,
    p_d   IN VARCHAR2,
    p_e   IN VARCHAR2,
    p_f   IN VARCHAR2
)
IS
BEGIN
    INSERT INTO t1(a, b, c)
         VALUES (p_a, p_b, p_c);

    INSERT INTO t2(d, e, f)
         VALUES (p_a || p_d, p_b || p_e, p_c || p_f);
END;
0
 

Author Comment

by:ajaybelde
ID: 39800934
@sdstuber
does  p_a ,p_b,p_c   is also need to be passed Manual?.

my req is whenver we insert  p_a ,p_b,p_c on t1(which is not manual)  it should insert VALUES in t2 (p_a || p_d, p_b || p_e, p_c || p_f) and i should able pass the values p_d, p_e, p_f manually where ever required
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39800955
if a non manual process inserts a,b,c to t1
how do you imagine a user could possibly be prompted to manually enter d,e,f?

The request doesn't make sense to me.
0
 

Author Comment

by:ajaybelde
ID: 39801096
if it is manual for all values. how would i pass 6 values to SP
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 1000 total points
ID: 39801126
>> if it is manual for all values. how would i pass 6 values to SP

begin
 insert_two_table('USA','UK','IND','001','044','091');
end;
0
 
LVL 78

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 1000 total points
ID: 39801131
>>if it is manual for all values. how would i pass 6 values to SP

You need some way to flag the new rows in t1.  How do you plan on knowing what rows in t1 need to have some value appended in t2?   Will ALL the new values in t1 get appended with the same values in t2?

What does appending a value give you?

I would think the design would be something like: t2(A,B,C,D,E,F).

Then a trigger on t1 could pre-populate A,B and C in t2.  Then all you need to do is look for null values for D,E and F in t2 to get what rows need processing.

Even if you need them concatenated, you can create a view off of t2 to perform the concatenation:

create or replace view t2_vw as
select a||d a_d, b||e b_e, c||f c_f from t2 where d||e||f is not null;
0
 
LVL 32

Expert Comment

by:awking00
ID: 39803519
What does the appended value do? From your example, it looks like it could be a numerical representation of the country code. That would mean for every value in T1, there would be a corresponding append value, which could be managed by a lookup table of some sort. If that's not the case and the values that get appended are truly random or at the mercy of someone's imagination, what good do they do? If there is some sort of criteria that define the values to be appended, I think you might still accomplish your intent with an after insert trigger that applies the criteria logic.
0
 

Author Closing Comment

by:ajaybelde
ID: 39839913
they are planning to prevent it from application logic
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question