2

How to prompt a user for input in oracle using SQLTools v1.6? I tried the following PL/SQL block:

DECLARE 
 type tes_tab is table of test_table%rowtype;
 test_tab tes_tab;    
BEGIN

  execute immediate 'SELECT * FROM test_table WHERE memid=' || &MemID
       bulk collect into test_tab;

  for i in 1..test_tab.count 
  loop
    dbms_output.put_line(test_tab(i).memid || ' ' || test_tab(i).clmtype);
  end loop;

END;

It prompts the user for input during compile time. However, the value cannot be used in the select statement. Is there any other way to achieve what I am seeking.

The table contains 852269 records with multiple rows for a single memID(I have provided a few rows here):

 MEMID       CLMTYPE   PAIDAMT   SERVICEDATE           PAIDDATE
----------- --------- --------- --------------------- ---------------------
 220000096   RX         77.22    06.05.2011 00:00:00   27.05.2011 00:00:00
 220000096   RX         77.22    04.02.2011 00:00:00   27.02.2011 00:00:00
 220000096   RX         93.36    01.01.2011 00:00:00   27.01.2011 00:00:00
 220000096   RX         15.07    09.08.2012 00:00:00   07.09.2012 00:00:00
 220000096   RX        105.52    06.01.2012 00:00:00   04.02.2012 00:00:00
 220000096   RX         93.36    02.03.2011 00:00:00   27.03.2011 00:00:00
 220000096   RX        105.52    09.11.2011 00:00:00   09.12.2011 00:00:00
 220000096   RX        105.52    10.03.2012 00:00:00   13.04.2012 00:00:00
 220000096   RX         50.52    06.04.2011 00:00:00   27.04.2011 00:00:00
diziaq
  • 6,881
  • 16
  • 54
  • 96
hsuyaa
  • 41
  • 2
  • 11

1 Answers1

1

Small modifications to your code

DECLARE 
  vblMemID test_table%rowtype;
BEGIN
  EXECUTE IMMEDIATE'SELECT * FROM test_table WHERE memid='||&MemID into vblMemID ;
dbms_output.put_line(vblMemID.column1_name||' '||vblMemID.column2_name);
END;

Note: Column1_name and column2_name means your table column names. And the above code will works if your select query returns only one row. If it returns more than one row we have to use another method. If you need i will post that code.

Edit The below code will work if a select query will returns more than one row. For more than one row we have to use collections or sysref cursors in oracle.

DECLARE 
 type tes_tab is table of test_table%rowtype;
test_tab tes_tab;
BEGIN

execute immediate 'SELECT * FROM test_table WHERE memid='||&MemID bulk collect into test_tab;

for i in 1..test_tab.count 
loop
dbms_output.put_line(test_tab(i).column1_name||' '||test_tab(i).column2_name);
end loop; 
END;
Tharunkumar Reddy
  • 2,773
  • 18
  • 32