-1

I have a procedure where it has few select statements (from different tables) and the output of these select statements will be loaded into a temp table. All the records which are loaded in this temp table will be displayed as an output. Now I have a requirement where my procedure should not have this temp table.

Can you please let me know the options of achieving it?

James Z
  • 12,209
  • 10
  • 24
  • 44
Siddharth
  • 21
  • 4
  • 2
    You could use `UNION (ALL)` to put the results together? Is this MySQL, Oracle, or SQL Server? The best approach may very depending on DBMS. It is probably also advisable to post the code you are using, otherwise any answer you get will be at best a guess. – GarethD Apr 12 '16 at 10:13
  • Can you share the sp? It would also help if you could include a sample of the output. If you can explain why temp tables are not an option that might help you avoid answers that run into similar restrictions. – David Rushton Apr 12 '16 at 10:43
  • This is in Oracle. Unfortunately, I think I do not have approvals for pasting the code here. The temp table that I am using has contention problem. So my requirement is that I should not use the temp table but any other way (in Procedures) to store the records (which came out of multiple select statements) and passing it – Siddharth Apr 12 '16 at 10:59

2 Answers2

1

Assuming that the SELECT queries have same number of COLUMNS and Datatype. Your best approach could be using union all and refcursor to display the output. Hope below snippet helps.

--You can try using nested table types here instead of using temp tables or simply UNIONALL
--Hope below example helps.

DECLARE
  p_lst sys_refcursor;
BEGIN
  --Assuming that all the SELECT statements have same number of columns as well as datatype
  OPEN p_lst FOR
  (SELECT 'AV',1 FROM DUAL
  UNION ALL
  SELECT'SH',2 FROM DUAL
  UNION ALL
  SELECT 'TK',3 FROM DUAL
  );
END;
Avrajit Roy
  • 3,233
  • 1
  • 13
  • 25
0

Assuming mysql... You could do something like

UPDATE [table1] AS t1 
INNER JOIN [table2] AS t2 
ON t1.[col1] = t2.[col1] 
SET t1.[col2] = t2.[col2];
Louis
  • 1
  • 1