sql >> Database teknologi >  >> RDS >> Oracle

Vil have denne enkle forespørgsel til at sløjfe

Du kan gøre dette med 2 SQL-scriptfiler som denne:

1) Filer myscript.sql:

ACCEPT column_name CHAR PROMPT 'Please insert column name: '

SELECT DISTINCT owner, table_name
FROM all_tab_columns
WHERE column_name IN ('&column_name');

-- Ask the user if the want to search again
ACCEPT response CHAR PROMPT 'Would you like to search for another column? '

-- Use a SELECT statement to look at their response and set variable "script" as appropriate
COLUMN script new_value script

-- Stop this select's results being displayed (in SQL Plus)
SET TERM OFF

SELECT CASE LOWER('&response.') WHEN 'yes' THEN 'myscript' ELSE 'stop' END AS script
FROM DUAL;

-- Switch terminal output back on
SET TERM ON

-- Run whichever script the user chose i.e. "myscript.sql" if they said "yes", "stop.sql" if they said "no".
@&script.

2) Filen stop.sql:

-- This script just says "Have a nice day" then ends.
PROMPT Have a nice day

Afhængigt af om brugeren svarer 'ja' eller 'nej', kører scriptet enten sig selv igen (loops) eller kører stop.sql scriptet, som bare siger "Hav en god dag".




  1. hvordan laver man forbindelsespooling i java?

  2. sqoop eksport lokal csv til MySQL fejl på mapreduce

  3. Navn på SQL Server variabel kolonner?

  4. Sql - Fletning af rækker, hvis dato forbinder