0

I've the following query in a test script window

declare
  -- Local variables here
  p_StartDate date := to_date('10/15/2012');
  p_EndDate   date := to_date('10/16/2012');
  p_ClientID  integer := 000192;
begin
  -- Test statements here
  select d.r                          "R",
         e.amount                     "Amount",
         e.inv_da                     "InvoiceData",
         e.product                    "ProductId",
         d.system_time                "Date",
         d.action_code                "Status",
         e.term_rrn                   "IRRN",
         d.commiount                  "Commission",
         0                            "CardStatus"
    from docs d
   inner join ext_inv e on d.id = e.or_document
   inner join term t on t.id = d.term_id
   where d.system_time >= p_StartDate
     and d.system_time <= p_EndDate
     and e.need_r = 1
     and t.term_gr_id = p_ClientID;
end


Here is the error:

ORA-06550: line 9, column 3: PLS-00428: an INTO clause is expected in this SELECT statement


I've been using T-SQL for a long time and I'm new to PL/SQL.

What's wrong here?

VC1
  • 1,660
  • 4
  • 25
  • 42
levi
  • 3,451
  • 6
  • 50
  • 86

3 Answers3

0

These columns need to be stored in some type structure. like given in this example

DECLARE
  deptid        employees.department_id%TYPE;
  jobid         employees.job_id%TYPE;
  emp_rec       employees%ROWTYPE;
**Create type structure**
  TYPE emp_tab IS TABLE OF employees%ROWTYPE INDEX BY PLS_INTEGER;
  all_emps      emp_tab;
BEGIN
  SELECT department_id, job_id INTO deptid, jobid 
     FROM employees WHERE employee_id = 140;
  IF SQL%FOUND THEN 
    DBMS_OUTPUT.PUT_LINE('Dept Id: ' || deptid || ', Job Id: ' || jobid);
  END IF;
  SELECT * INTO emp_rec FROM employees WHERE employee_id = 105;
  SELECT * INTO all_emps FROM employees;  **//storing into all_emp type structure**
  DBMS_OUTPUT.PUT_LINE('Number of rows: ' || SQL%ROWCOUNT);
END;
/
Tribhuwan
  • 180
  • 1
  • 1
  • 11
0

Assuming that what you really want is quering the db with some parameters, then you have some options:
1- use sqlplus or plsql developer "command window" or "sql window" with the query like this:

  select d.r                          "R",
         e.amount                     "Amount",
         e.inv_da                     "InvoiceData",
         e.product                    "ProductId",
         d.system_time                "Date",
         d.action_code                "Status",
         e.term_rrn                   "IRRN",
         d.commiount                  "Commission",
         0                            "CardStatus"
    from docs d
   inner join ext_inv e on d.id = e.or_document
   inner join term t on t.id = d.term_id
   where d.system_time >= &p_StartDate
     and d.system_time <= &p_EndDate
     and e.need_r = 1
     and t.term_gr_id = &p_ClientID;

You'll be prompted to give values to the parameters.

2- You can use plsql (though I don't see why) but then you need an explicit cursor
For example if you're using a "test window":

declare
  -- Local variables here
  p_StartDate date := to_date('10/15/2012');
  p_EndDate   date := to_date('10/16/2012');
  p_ClientID  integer := 000192;
begin
  -- Test statements here
  OPEN :src FOR select d.r                          "R",
         e.amount                     "Amount",
         e.inv_da                     "InvoiceData",
         e.product                    "ProductId",
         d.system_time                "Date",
         d.action_code                "Status",
         e.term_rrn                   "IRRN",
         d.commiount                  "Commission",
         0                            "CardStatus"
    from docs d
   inner join ext_inv e on d.id = e.or_document
   inner join term t on t.id = d.term_id
   where d.system_time >= p_StartDate
     and d.system_time <= p_EndDate
     and e.need_r = 1
     and t.term_gr_id = p_ClientID;
end

Note that you need to add a variable in the table below with the name "src" and type "cursor", after running the plsql block it will hold the resultset

A.B.Cade
  • 16,735
  • 1
  • 37
  • 53
0

You can try this solution:

set serveroutput on
declare
  -- Local variables here
  p_StartDate date := to_date('10/15/2012');
  p_EndDate   date := to_date('10/16/2012');
  p_ClientID  integer := 000192;
begin
  for cur in ( select d.r                          "R",
                      e.amount                     "Amount",
                      e.inv_da                     "InvoiceData",
                      e.product                    "ProductId",
                      d.system_time                "Date",
                      d.action_code                "Status",
                      e.term_rrn                   "IRRN",
                      d.commiount                  "Commission",
                      0                            "CardStatus"
                 from docs d
                 inner join ext_inv e on d.id = e.or_document
                 inner join term t on t.id = d.term_id
                 where d.system_time >= p_StartDate
                   and d.system_time <= p_EndDate
                   and e.need_r = 1
                   and t.term_gr_id = p_ClientID)
   LOOP
       dbms_output.put_line('R: '||cur.R||'Amount:  '||cur.Amount/*...*/);
   END LOOP;

end;
/
Robert
  • 25,425
  • 8
  • 67
  • 81