Procedure to insert data into table by selecting data from another table
Hi all,
I have to create a procedure where i have to select the data from one table and insert it into another table. Any help on this. And i have to update the 2nd table also when ever new records got inserted in the 1st table then.
Regards
Hi, you can try something like:
CREATE [OR REPLACE] PROCEDURE procedure_name
IS
BEGIN
INSERT INTO TABLE1
VALUES (SELECT * FROM TABLE2);
END;
For the other part you may create a trigger on the first table AFTER INSERT to insert the values in the second table too.
Similar Messages
-
Insert data from another sheet
I have a problem;
I want to be able to create a drop down list on one sheet that references a table on another sheet. The data looks like this;
UNIT
Cost per day
unit a
10
unit b
20
unit c
30
I am hoping to create a Drop-down box on another sheet that lets me select a 'unit', and then places the Cost per day in the cell next to it.
Is this possible within numbers without a huge IF'cell'= formula?
My aim is to be able to use an iPad running Numbers to create instant quotes when onsite with clients, by referencing a data sheet but presenting it nicely.Yes, VLOOKUP should work nicely for that. Set the formula up on one sheet and complete it by clicking the ranges in the lookup table on the other sheet.
SG -
Insert /*+ Append */ into table...
Hi Guys,
if i use /*+ Append */ hint with insert statment then will redologs generate or not?
ThanksEasy to find out...
SQL> insert /*+ APPEND */ into junk
2 select *
3 from all_objects;
7870 rows created.
Statistics
504 recursive calls
91 db block gets
86173 consistent gets
6 physical reads
11824 redo size
405 bytes sent via SQL*Net to client
470 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
7870 rows processedOracle will still generate redo, but much less. -
How do I run a database procedure that inserts data into a table from withi
How do I run a database procedure that inserts data into a table from within a Crystal report?
I'm using CR 2008 with an Oracle 10i database containing a number of database tables, procedures and packages that provide the data for the reports I'm developing for my department. However, I'd like to know when a particular report is run and by whom. To do this I have created a database table called Report_Log and an associated procedure called prc_Insert_Entry that inserts a new line in the table each time it's called. The procedure has 2 imput parameters (Report_Name & Username), the report name is just text and I'd like the username to be the account name of the person logged onto the PC. How can I call this procedure from within a report when it's run and provide it with the 2 parameters? I know the procedure works, I just can't figure out how to call it from with a report.
I'd be grateful for any help.
ColinHi Colin,
Just so I'm clear about what you want:
You have a Stored procedure in your report. When the report runs, you want that same procedure to write to a table called Report_Log.
If this is what you want the simple answer is cannot be done. Crystal's fundamental prupose is to read only, not write. That being said, there are ways around this.
One way is to have a trigger in your database that updates the Report_Log table when the Stored Procedure is executed. This would be the most efficient.
The other way would be to have an application run the report and manage the entry.
Good luck,
Brian -
How to insert Data from a function on server A into a table on Server B.
Hi,
I have a function which is like this
DECLARE @oldmax bigint, @newmax bigint
SELECT @oldmax = max(exportTimestamp) FROM EXPORT_TIMESTAMPS
IF @oldmax IS NULL
SET @oldmax = 0
SELECT * FROM ServerA.TableA.fnExportTrafficTS(@oldmax) ORDER BY storeID, TrafDate
SELECT @newmax = max(timestamp) FROM TRAFFIC t
IF @newmax > @oldmax
INSERT INTO EXPORT_TIMESTAMPS
VALUES(@newmax, GETDATE())
And now i need to insert the data coming out of this function into ServerB Table B
And the column names and everything coming out of the function is the same columns in Table B.So, no need to worry there.
I have never worked with inserting data from function through linked server.
Can someone please help me with this?
Thanks,
SujithWell, first of all, your table structure doesn't match the structure of returned table by your table-valued function.
This is what table valued function returns:
[storeID] varchar(32) default('noRefID'),
[TrafDate] [datetime] default(NULL),
[QtyTraffic] [float] default(0)
And this is what your table structure is:
[tUTL_JobLogging_Key] [int] NOT NULL,
[StoreId] [varchar](10) NULL,
[TrafDate] [datetime] NULL,
[Visits] [numeric](8, 2) NULL
Apart from different size for the StoreID and using float vs. numeric and different name for the last column, there is one extra column in your table.
So, this is the first problem you need to correct.
Also, please post how exactly you're calling your procedure? E.g. the procedure has 2 parameters, but the values of them are not used as you're calculating them in the code. So, I assume they should not be parameters for the procedure.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
How to insert data from different internal table into a data base table
hi all,
I want to insert a particular field in an internal table to a field in a data base table.Note that the fields in the internal table and database table are not of the same name since i need to insert data from different internal tables.can some one tell me how to do this?
in short i want to do something like the foll:
INSERT INTO ZMIS_CODES-CODE VALUE '1'.
*INSERT INTO ZMIS_CODES-COL1 VALUE DATA_MTD-AUFNR .(zmis_codes is the db table and data_mtd is the int.table)REPORT ZINSERT.
tables kna1.
data: itab LIKE KNA1.
data lv_kUNAG LIKE KNA1-KUNNR.
lv_kuNAG = '0000010223'.
ITAB-kuNNR = lv_kuNAG.
ITAB-name1 = 'XYZ'.
INSERT INTO KNA1 VALUES ITAB.
IF SY-SUBRC = 0.
WRITE:/ 'SUCCESS'.
ELSE.
WRITE:/ 'FAILED'.
ENDIF.
Here lv_kunag is ref to kna1 kunnr passed in different name
In internal table .
Try and let me know if this logic dint work. -
[ECC6] Inserting data from internal table (deep structure) into db table
Hi experts,
I have a problem when inserting data from IT using deep structure into a database table. Please help:
I have one database table with 2 columns ZTest (col1, col2). Col1 is key.
In my program I have a deep structure t_screen using table type lvc_t_scol:
In 4.6c systems, the INSERT statement works well but it does not work in ECC6 systems.
DATA: BEGIN OF t_screen OCCURS 0,
rec_count(3) TYPE n,
col1 LIKE ZTest-col1,
col2 LIKE ZTest-col2.
DATA: ct TYPE lvc_t_scol.
DATA: END OF t_screen.
t_screen-col1 = 'test1'.
t_screen-col2 = 'test1'.
APPEND t_screen.
t_screen-col1 = 'test2'.
t_screen-col2 = 'test2'.
APPEND t_screen.
INSERT ZTest FROM TABLE t_screen ACCEPTING DUPLICATE KEYS.
Currently I have an idea using a temporary internal table with the same structure as ZTest. Use MOVE-CORRESPONDING statement to move data from t_screen table to temporary table before inserting --> It worked. But do you have any ideas without using temporary table?Hi
There are a large number of stataments couldn't be supported in unicode system and so it doesn't allow to do it in ECC 6.
U need to delete the deep structure from your defination:
DATA: BEGIN OF t_screen OCCURS 0,
rec_count(3) TYPE n,
col1 LIKE ZTest-col1,
col2 LIKE ZTest-col2.
DATA: ct TYPE lvc_t_scol. "<-------- Error is here
DATA: END OF t_screen.
So u need to use a structure like this to update your table:
DATA: BEGIN OF T_ZTEST OCCURS 0,
rec_count(3) TYPE n,
col1 LIKE ZTest-col1,
col2 LIKE ZTest-col2.
DATA: END OFT_ZTEST.
Max -
PL/SQL procedure to insert data doesn't work and unable to find reason.
Sorry that I couldn't find the best place to post this question. It seems that the forum does not deal with this kind of question. I post here for help.
I have a stored procedure to insert data into one table. SP was compiled without error and executed without error (from log table to get information). But the data was not inserted into
the target table. I have tried different way to figure out the reason. But I failed to get any idea. Please help me to find possible reasons. The smple SP looks like this:
CREATE OR REPLACE PROCEDURE my.sp_insert( P_DATE IN VARCHAR2)
IS
declare section
begin
insert into target_table (column1, column2, column3, column4)
select record1, record2, record3, record4 from table1, table2, table3, table4
where clause;
commit;
exception section
UPDATE PROCESS_LOG_TABLE CLAUSE;
html_email section;
rollback;
end my.sp_insert
I have tested that "select record1, record2, record3, record4 from table1, table2, table3, table4" really fetch the 7,000 records. and if I only run part of SQL from SQLPLUS as
insert into target_table (column1, column2, column3, column4)
select record1, record2, record3, record4 from table1, table2, table3, table4
where clause;
It will work and insert 7,000 records into target table. Why did it not insert into target_table when execiting as stored procedure? Please help with your input. Thanks.
Edited by: citicbj on Feb 12, 2013 4:15 PMDear Friend,
Is the user from which you created database procedure and sqlplus that you tested the code successfully is same?
Regards
Ahamed Rafeeque Cherkala -
Error Inserting Data from Procedure ODI 11g (No data)
Hi everyone!
I have a problem inserting data from a procedure, the procedure works "fine" (no errors), on the log counter shows the number of rows inserted, but, on the database rows does not exists, an easy sample is:
TARGET: ORACLE
insert into table_t
(desc)
values
(:description)
SOURCE: ORACLE
select description from table_s
I check (ODI), the conection (works fine), modules (works fine), "select from table" (works fine).
I check (Database), inserting rows direct (works fine).
What can i check?
Thanks for your response.Hi
Try below 2 things
First
In target:oracle
insert into table_t
(desc)
values
('#descpt');
Second
In target:oracle
insert into table_t
(desc)
values
('#Proc_Var');
Note: For alias name (*descpt* ) or Project variable (*Proc_Var*) with # symbol and single quotes
Regards,
Phanikanth -
Procedure to insert data in multiple rows
Hi,
I need a stored procedure which inserts data into multiple rows..
Ex: I need to have 3 columns in Procedure, where col3 has limit in size let's say 500.
If user insert about 1500 in col3, i has to insert first 500 in row1 and 501 - 1000 in row 2 and 1001 - 1500 in row 3.
Can any one help in creating procedure for above scenario.
Thanks in Advance...
Sreecreate table #t (id int, id1 int)
WITH [1-20]
AS
SELECT row_number() over (order by number) rn,number
FROM master..spt_values
WHERE type = 'P'
AND number BETWEEN 1 AND 20
[21-30]
AS
SELECT row_number() over (order by number) rn,number
FROM master..spt_values
WHERE type = 'P'
AND number BETWEEN 21 AND 30
) INSERT INTO #t
SELECT A.number,B.number FROM
[1-20] A JOIN [21-30] B ON A.rn=B.rn
SELECT * FROM #t
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Procedure to check data from different tables
Hi
I am trying to write a procedure to compare data from a table with another.
Table 1
ID Name Dept
1 ABC Y
2 DEF Z
Table 2
ID Dept
1 Y
2 Z
Table 3
Name ID
1 ABC
2 DEF
I would like to compare each record data in Table 1 with data from different tables table2,table3 by matching ID,name.... Please help me with how I could start writing a procedure and also spool data that does not match from the table1 with other tables
thanks
Edited by: 890563 on Apr 30, 2012 10:34 AMHope below helps you.
CREATE TABLE TABLE1
( ID VARCHAR2(10),
FIRST_NAME VARCHAR2(30),
LAST_NAME VARCHAR2(30),
MIDDLE_NAME VARCHAR2(30)
INSERT INTO TABLE1 VALUES('123456','testfirst','testlast','testmiddle');
INSERT INTO TABLE1 VALUES('123457','testfirst1','testlast1','testmiddle1');
CREATE TABLE TABLE1
( ID VARCHAR2(10),
FIRST_NAME VARCHAR2(30),
LAST_NAME VARCHAR2(30),
MIDDLE_NAME VARCHAR2(30)
INSERT INTO TABLE2 VALUES('123456','testfirst','testlas','testmidd');
INSERT INTO TABLE2 VALUES('123457','testfirst2','testlast1','testmiddle1');
SELECT TABLE1.ID,
-- Match First Name
CASE WHEN TABLE1.FIRST_NAME != TABLE2.FIRST_NAME THEN TABLE1.FIRST_NAME ELSE NULL END TABLE1_FIRST_NAME,
CASE WHEN TABLE1.FIRST_NAME != TABLE2.FIRST_NAME THEN TABLE2.FIRST_NAME ELSE NULL END TABLE2_FIRST_NAME,
-- Match Middle Name
CASE WHEN TABLE1.MIDDLE_NAME != TABLE2.MIDDLE_NAME THEN TABLE1.MIDDLE_NAME ELSE NULL END TABLE1_MIDDLE_NAME,
CASE WHEN TABLE1.MIDDLE_NAME != TABLE2.MIDDLE_NAME THEN TABLE2.MIDDLE_NAME ELSE NULL END TABLE2_MIDDLE_NAME,
-- Match Last Name
CASE WHEN TABLE1.LAST_NAME != TABLE2.LAST_NAME THEN TABLE1.LAST_NAME ELSE NULL END TABLE1_LAST_NAME,
CASE WHEN TABLE1.LAST_NAME != TABLE2.LAST_NAME THEN TABLE2.LAST_NAME ELSE NULL END TABLE2_LAST_NAME
FROM TABLE1, TABLE2
WHERE TABLE1.ID = TABLE2.ID
ID TABLE1_FIRST_NAME TABLE2_FIRST_NAME TABLE1_MIDDLE_NAME TABLE2_MIDDLE_NAME TABLE1_LAST_NAME TABLE2_LAST_NAME
123456 NULL NULL testmiddle testmidd testlast testlas
123457 testfirst1 testfirst2 NULL NULL NULL NULL
{code} -
Cannot insert data from local database into remote database using subquery
I have two oracle databases on different host.
One is version 8i in Host A and the other is 9i in Host B.
First, I try to create a dblink in 8i to 9i, but it fail.
Then, I create a dblink in 9i to 8i, it success.
I have already tried some select statement in 9i to view the table in 8i, which is success and that means the dblink is really work.
The sql statement is like
Select * from table1@hostA
Then I have tried running some INSERT statement in 9i, which is copy data from table 1 in 8i to table 2 in 8i, both tables are in 8i. The sql statement is like
Insert INTO table2@hostA(field1, field2)
select field1, field2
from table1@hostA
This also success.
Also, I have tried to use the following INSERT statement
Insert INTO table2@hostA(field1, field2) values ('XXX', 'XXX)
This also success.
However, when I try to insert data from table in 9i to table in 8i using the following INSERT statement, it failed.
Insert INTO table2@hostA(field1, field2)
select field1, field2
from table1
The statement can execute, but all the rows inserted with every field value equal to NULL. I have tried to run the select part, it can return the data. But when I run the INSERT statement above, the value inserted into table2 is all equal to NULL.
One more thing, I discover that the databases are using different NLS_CHARACTERSET
9i is AL32UTF8
8i is WE8ISO8859P1
Is this relevant to my problem?
Does anyone know the solution about this problem?
Thanks!!How is the best way to do this ?How much are you planning to send?
You can use COPY command. Ensure that you have valid database link between two databases.
Available options are:
create - creates a new table. errors out if the destination table exists.
replace - drop the destination table and re-creates with data.
insert - inserts data if the destination table exists.
append– appends data into an existing table.
use set arraysize 5000 -The arraysize specifies the number of rows that SQL*Plus will retrieve from the database at one time.
copy from scott/tiger@ORCL to scott/tiger@ORCL92 create new_emp using select * from emp; -
Can I create a Stored Procedure That access data from tables of another servers?
I'm developing a procedure and within it I'm trying to access another server and make a select into a table that belongs to this another server. When I compile this procedure I have this error message: " PLS-00904: insufficient privilege to access object BC.CADPAP", where BC.CADPAP is the problematic table.
How can I use more than one connection into an Oracle Stored Procedure?
How I can access tables of a server from a Stored Procedure since the moment I'm already connected with another server?
Can I create a Stored Procedure That access data from tables of another servers?You need to have a Database Link between two servers. Then you could do execute that statement without any problem. Try to create a database link with the help of
CREATE DATABASE LINK command. Refer Document for further details -
Question in ABAP syntax, read & insert data from internal table, while loop
Hi, SDN Fellow.
I am from Java background and learnt ABAP, I don't usually write much ABAP code.
I am trying to implement the following logic in a RFC now.
I have one z-custom database table, the structure as the following:
It has two columns, with these sample data.
Says datable table is ZEMPMGRTAB.
EmployeeID,ManagerID
user10,user1
user9,user1
user8,user1
user7,user2
user6,user2
user5,user2
user4,user2
user2,user1
The logic is this:
I have a input parameter, userid. I am using this parameter to have a select statement to query the record into export table,EXPTAB 'LIKE' table ZEMPMGRTAB.
SELECT * FROM ZEMPMGRTAB
into table EXPTAB
WHERE EMPLOYEEID = USERID.
Say, my parameter value, USERID ='USER4'.
Referring to the sample data above, I can get the record of this in my EXPTAB,
EmployeeID,ManagerID
user4,user2
Now, I want to iterately use the EXPTABLE-ManagerID
as the USERID input in SELECT statement, until it has no return result. Then, insert the new records in
EXPTAB.
In above new loop case, we will get this table content in EXPTAB,
EmployeeID,ManagerID
user4,user2
user2,user1
I kind of think of the pseudocode logic as below:
(These may not be a valid ABAP code, so I need help to convert/correct them)
DATA:
IWA TYEP ZZEMPMGRTAB,
ITAB
HASHED TABLE OF ZZEMPMGRTAB
WITH UNIQUE KEY EMPLOYEEID.
SELECT * FROM ZEMPMGRTAB
into table ITAB
WHERE EMPLOYEEID = USERID.
*Question 1: I cannot insert a internal table to export table, it is *incompatible type, what is the alternative way fo this?
*Question 2: How can I access thedata of the internal table like this,ITAB-MANAGERID? As if I can, I would do this:
* IWA-EMPLOYEEE = ITAB-EMPLOYEEID. IWA-MANAGERID = IWA-MANAGERID. INSERT IWA INTO TABLE EXPTAB.
* Question 3: Is the 'NE NULL' - 'not equal to NULL' is right syntax?
IF ITAB NE NULL.
INSERT ITAB INTO EXPTAB.
ENDIF
* Question 4: Is my WHILE loop setup right here? And are the syntax right?
WHILE ITAB NE NULL.
SELECT * FROM ZEMPMGRTAB
into table ITAB
WHERE EMPLOYEEID = ITAB-MANAGERID.
IF ITAB NE NULL.
INSERT ITAB INTO EXPTAB.
ENDIF
REFRESH ITAB.
ENDWHILE.
Assume all the syntax and logic are right, I should get this result:
EmployeeID,ManagerID
user4,user2
user2,user1
If I have a new entry in datable table,ZEMPMGRTAB like this:
user1,user0
My pseudocode logic will get this result:
EmployeeID,ManagerID
user4,user2
user2,user1
user1,user0
I truly appreciate if you can help me to validate the above syntax and pseudocode logic.
Thanks in advance.
KCHi,
FUNCTION ZGETSOMEINFO3.
*"*"Local Interface:
*" IMPORTING
*" VALUE(USERID) TYPE AWTXT
*" VALUE(FMTYPEID) TYPE AWTXT
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRETURN
*" TABLES
*" APPROVERT STRUCTURE ZTAB_FMAPPROVER
*" ACTOWNERT STRUCTURE ZTAB_FMACTOWNER
DATA: T_RESULT TYPE STANDARD TABLE OF ZTAB_FMAPPROVER.
**Question 1: For this line, I got an error says "Program ''USERID" *not found. Is the syntax right, as the USERID is a parameter for the function.
perform add_line(USERID).
ENDFUNCTION.
form add_line using i_user type ZTAB_FMAPPROVER.EMPLOYEEID
changing T_RESULT TYPE ZTAB_FMAPPROVER.
data: ls_row type ZTAB_FMAPPROVER.
* Get record for i_user
select single * into ls_row from ZTAB_FMAPPROVER
where EmployeeID = i_user.
if sy-subrc NE 0.
* Do nothing, there is not manager for this employee
else.
* Store result
QUESTION 2: I am still got stuck on this line of code. It still *says that "T_RESULT" is not an internal table "OCCURS n" *specification is missing. I thought the line: "T_RESULT TYPE *ZTAB_FMAPPROVER" means declare internal table, T_RESULT as type of ZTAB_FMAPPROVER". Am I understand it wrongly?
append ls_row to t_result.
* Call recursion
perform add_line using ls_row-ManagerID
changing t_result.
endif.
endform.
Thanks,
KC -
*Urgent*How to insert data from MS SQL to the table that create at the adobe form?
Hi,
I'm using Adobe life cycle designer 8 to do my interactive form. I would like to ask how to insert data from MS SQL to the table that i have created in my adobe interactive form?
I really need the information ASAP as i need to hand in my project by next week... i really appreciate any one who reply this post.
ThanksTou need to do a couple of things
1. On the Essbase server, set up an odbc system connection to your MySQL database
2. In the load rule , go to the file menu and select open SQL data source and in the data source put in your SQL statement . A couple of hints. Where it says Select, don't put in the word select and where it say from don't put in from. The system adds them for you. The easiest way ti enter a SQL statement is to do it all in the select area So if your SQL would normanlly say select * from mytable just enter the code as * from mytable in the select area
The click ol/retrieve and enter in your connection info. Itshould bring data back into the load rule. Save the load rule and use it -
hi,
i m create table, then create procedure, procedure is successfully compile, but when i m trying to insert image into table it error out.
for inserting image i go with
EXECUTE insert_image_file(1,'C:\sunset.jpg');
sunset.jpg is image which i want to insert in table, and which is present on 'c drive'.
when execute the following error are shown
ORA-22285: non-existent directory or file for FILEOPEN operation
ORA-06512: at "SYS.DBMS_LOB", line 635
ORA-06512: at "SCOTT.INSERT_IMAGE_FILE", line 26
ORA-06512: at line 1
how to solve it.
regards
prashantPrashant wrote:
CREATE OR REPLACE PROCEDURE insert_image_file (p_id NUMBER, p_image_name IN VARCHAR2)
...snipped...Not very nice code... why create an empty image row, then lock it (it is already locked by the uncommitted insert statement), and then update it again? Not very efficient or sensible.
image is on local machine.When a row is created on the server from user input on some PC, who supplied that input? Who read the user's keyboard input on that PC to obtain the values for the columns for the row to create?
Did PL/SQL read the keyboard of that remote PC? Of course not. The client program on that PC read the keyboard input. It then made a client call to the Oracle server. It supplied the data entered via the keyboard by the user to the Oracle server (using a PL/SQL call or using a SQL statement call to Oracle).
Now why would a local image data on that PC be treated any differently than the keyboard data on that PC? How can you expect PL/SQL code running on the Oracle server, to read that image data from the remote PC when the same PL/SQL code is incapable of reading keyboard input from that very same PC?
You need to review your understanding of client-server and how it pertains to using Oracle within client-server architecture.
Maybe you are looking for
-
I want to transfer my photoshop elements to a new computer ...
since the old one died and while I have all the original packaging, I evidently do not have the serial number because non of the other numbers listed work on the new computer. Can someone help with that
-
MacBook/iTunes not 'seeing' iPod
I haven't updated my iPod for a while, certainly not since the last couple of iTunes updates. However, today I opened iTunes, connected my iPod nano and it is not being seen by my MacBook. I've tried closing and reopening iTunes whilst keeping the iP
-
I've tried all the suggestions including deleting the inbox.msf etc. I have also tried uninstalling and reinstalling Thunderbird, but none of them seem to work.
-
What is the proces code for mbgmcr
what is the proces code for mbgmcr
-
Advice for sharing a calendar and syncing with a handheld device
Hi I want to publish my calendar to a select group of people - not publicly - and allow those people to alter my calendar - which then would sync with my blackberry - or other handheld, if i had to replace it. does anyone have any ideas? thanks!