简体   繁体   中英

Multi-Row PL/SQL Select statements

I have been performing queries for awhile using Excel VBA and other tools, but I am trying to transition to be able to perform some tasks directly in SQL and PL/SQL. I have been trying to create PL/SQL that will perform the following SELECT and have just not been able to grasp what I'm reading.

SELECT
  c.NAME, i.PROPERTY
FROM
  Schema.Table1 c,  Schema.Table2 i
WHERE
  c.ID = i.Prop_ID
  AND c.NAME = 'XXXX'

I want to be able to output the name, property.
I have a couple of restrictions. First, I cannot make any changes to the database. Second I will running this select across a number of identical schema.

Last any recommendations for a good PL/SQL reference would also be appreciated.

The simplest solution is to run the SQL*Plus scripts with substitution variables. These allow us to inject values each time we run the script. Find out more .

SELECT
  c.NAME, i.PROPERTY
FROM
  &&Target_Schema..Table1 c
    ,  &&Target_Schema..Table2 i
WHERE
  c.ID = i.Prop_ID
  AND c.NAME = 'XXXX'
/

Couple of notes:

  1. The '&&' notation means you only need to enter the schema name once. If you want to run the script against a different schema in the same session you will need to undef target_schema .
  2. The two .. after the schema is not a typo. It is a quirk of passing schema as a substitution variable that we need to escape the dot notation.

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