How to use list of selected values on the body of procedure [message #602160] |
Sat, 30 November 2013 11:30 |
|
lemune
Messages: 5 Registered: November 2013
|
Junior Member |
|
|
Hello, I need help with the structure of the procedure.
First of all, I should retrieve list of table names and owners.
At the body of the procedure I want to use this list for testing and comparisons.
I made some example that used cursor, I know it is not true.
Please advise how to implement this.
-------------------------------------
create or replace
PROCEDURE TEST_PROCEDURE (P_CODE IN NUMBER) IS
CURSOR C01 IS
(SELECT TABLE_NAME, OWNER
FROM TABLE1
UNION
SELECT TABLE_NAME, OWNER
FROM TABLE2);
BEGIN
SELECT MAX(SCORE)
INTO V_SCORE
FROM TABLE4 Q
WHERE EXISTS (SELECT 'Y'
FROM C01 T --- ?????????
WHERE Q.TABLE_NAME = T.TAB_NAME
AND Q.OWNER = T.OWNER);
END TEST_PROCEDURE;
|
|
|
|
|
|
Re: How to use list of selected values on the body of procedure [message #602170 is a reply to message #602165] |
Sat, 30 November 2013 14:46 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
lemune wrote on Sat, 30 November 2013 19:15Thanks, but I need to use this list several times during the procedure body.
Therefore, in my opinion should be another solution, without using cursor.
Here's an idea, why don't you tell us exactly what it is that you're trying to do instead of making vague allusions to your requirements.
|
|
|
Re: How to use list of selected values on the body of procedure [message #602200 is a reply to message #602160] |
Sun, 01 December 2013 07:05 |
|
lemune
Messages: 5 Registered: November 2013
|
Junior Member |
|
|
Sorry for the delay. Apparently I'm not being clear enough.
Below is the full code of my procedure.
I'm trying to find a way to implement the sub select only once (select from ri_relationships with union).
----------------------------------------------------------
create or replace
procedure test_procedure (p_owner in varchar2,
p_table_name in varchar2) is
v_owner varchar2(50) := upper(p_owner);
v_table_name varchar2(50) := upper(p_table_name);
v_score number := 0;
v_table_score number := 0;
begin
while v_table_score <> 99
loop
select nvl(max(score),0)
into v_score
from ds.ri_mng_queue q
where exists (select 'Y'
from (select t.dim_table_name tab_name,
t.dim_owner owner
from ds.ri_relationships t
where t.fact_table_name = v_table_name
and t.fact_owner = v_owner
union
select t.fact_table_name tab_name,
t.fact_owner owner
from ds.ri_relationships t
where t.dim_table_name = v_table_name
and t.dim_owner = v_owner) t
where q.table_name = t.tab_name
and q.owner = t.owner);
if v_score = 0 and v_table_score = 0 then
insert into ds.ri_mng_queue values (1, p_table_name, p_owner, sysdate);
v_table_score := 99;
else if v_table_score = 0 then
v_table_score := v_score + 1;
insert into ds.ri_mng_queue values (v_table_score, p_table_name, p_owner, sysdate);
dbms_lock.sleep(10);
else if v_table_score <> 0 and v_score = 0 then
v_table_score := 99;
else
dbms_lock.sleep(10);
end if;
end if;
end if;
commit;
end loop;
end test_procedure;
|
|
|
Re: How to use list of selected values on the body of procedure [message #602220 is a reply to message #602170] |
Sun, 01 December 2013 17:23 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
As Pabolee said earlier:
[quote title=pablolee wrote on Sat, 30 November 2013 20:46]lemune wrote on Sat, 30 November 2013 19:15
Here's an idea, why don't you tell us exactly what it is that you're trying to do instead of making vague allusions to your requirements.
I very much doubt anyone reading this has a clue what it is you're trying to do.
I suggest you explain your requirement using words, rather than code that presumably doesn't do what you want.
|
|
|
|
|
|