Home » RDBMS Server » Server Administration » Select / update in a procedure
Select / update in a procedure [message #52434] Mon, 22 July 2002 01:01 Go to next message
Janna
Messages: 3
Registered: March 2002
Junior Member
Hi,

I want to do the following in a procedure

From user1
1. Select some columns from table1,table2 table 3 with some where condition

2. Select some other columns from table4,table5 table6 with some where condition and join it with resultset of 1

3. Update resultset got in 2 set column5 = some select statement

Now I have to tranfer the result set in 3 to user2 some_table.

How can i achieve this?

Thanks,
Janna
Re: Select / update in a procedure [message #52439 is a reply to message #52434] Mon, 22 July 2002 06:53 Go to previous messageGo to next message
Sanjay Bajracharya
Messages: 279
Registered: October 2001
Location: Florida
Senior Member
Your post needs a little more details ... still just by looking at it, your possible solution may be

1. Use UNION/UNION ALL if applicable
2. Use temp table to store the result sets, combine and then extract the outcome.

Good luck.
Re: Select / update in a procedure [message #52441 is a reply to message #52439] Mon, 22 July 2002 07:05 Go to previous messageGo to next message
Janna
Messages: 3
Registered: March 2002
Junior Member
Sanjay,

Union all cannot be used. Let us say I have

1.emp table with eid,ename,salary,dept_id

2. dept table with dept_id,dept_name,dept_head

in user user1

Also in user user2 I have a table called emp_dept with eid,ename,salary,dept_id,dept_name

Now let us write a stored procedure as detailed below

1. select eid,ename,salary,dept_id, null from user1.emp
2. update recordset got in Step-1 set dept_name = select dept_name from user1.dept where
recordset got in step-1.dept_id = user1.dept_id

3. insert into user2.emp_dept set values as in recordset got in step-2

I do not want to create original tables b'cos each of procedures will have many such tables. Therefore I tried using globl temporary table. But it is also not working

create or replace PROCEDURE temp_test
AS
BEGIN
EXECUTE IMMEDIATE 'create global temporary table temp_test1 as (select * from dual)';
END;

procedure created

exec temp_test;

BEGIN temp_test; END;

*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "USER!.TEMP_TEST", line 4
ORA-06512: at line 1

Referred the doc:

http://osi.oracle.com/~tkyte/Misc/RolesAndProcedures.html

I am not sure how to give priviledge granted dierctly to me?

Thanks & Regards,
Janna
Re: Select / update in a procedure [message #52450 is a reply to message #52439] Mon, 22 July 2002 23:44 Go to previous messageGo to next message
santosh
Messages: 85
Registered: October 2000
Member
Hi Janna,
Can you be more specific with your problem as i can not get where exactly you are stuck up .Whether you want the syntax for the query or u got some problem while running your own query and plz check your second reply step 2 it is not very clear .

Thank you

Santosh
Re: Select / update in a procedure [message #53787 is a reply to message #52439] Thu, 10 October 2002 22:28 Go to previous message
fairy
Messages: 1
Registered: October 2002
Junior Member
You should grant 'create any table' privilege to the user who excutes the procedure.
Previous Topic: maximum no of processes exceeded
Next Topic: oracle error ora-00600
Goto Forum:
  


Current Time: Fri Sep 20 00:40:52 CDT 2024