简体   繁体   中英

Converting a SQL query into PL/SQL in Oracle

I'm new to PL/SQL and trying to convert an SQL statement into the PL/SQL format. I have the SQL statement as:

SELECT StudentIDNumber
FROM Lease
INNER JOIN Invoice
ON Invoice.LeaseID = Lease.LeaseID
WHERE IsPaid = 'N';

How would I go about this? Any solutions would be greatly appreciated!

I think you would only need to specify your schema in Oracle and that's about it. The other syntax should be correct (provided your tables are coming from the same Schema/table):

SELECT StudentIDNumber
FROM PRODDATA.Lease
INNER JOIN Invoice
ON Invoice.LeaseID = Lease.LeaseID
WHERE IsPaid = 'N';

This document offered by Oracle also has some basic syntax changes that could prove useful to you https://docs.oracle.com/cd/E10405_01/appdev.120/e10379/ss_oracle_compared.htm

may be try below PlSQL snippet?

DECLARE
   TYPE lv_student_ID IS TABLE OF NUMBER;
BEGIN
   -- assuming you are trying to find all students who have not yet paid, you can use a nested table
   SELECT StudentIDNumber
     BULK COLLECT INTO lv_student_ID
     FROM Lease INNER JOIN Invoice ON Invoice.LeaseID = Lease.LeaseID
    WHERE IsPaid = 'N';

   -- use value as you want
   DBMS_OUTPUT.put_line (lv_student_ID.COUNT);
END;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM