Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL Plus prompt and loop

91707eb3-0eec-488f-a8ca-9f56088a9876Oct 3 2014 — edited Oct 3 2014

Dear all,

I’m trying do modify an existing program launched with SQL plus.

This program allows me to display (in a csv file) a table according a model number. Thanks the command « accept nof prompt 'Numero OF :' » I can prompt the user to tap the model number that he wants to display and the rest of the program create the list in the csv file.

The modification I want to do is as follow:

I’d like the user to be able to enter multiple model number (for exemple: 55125,55126,54672) instead of just typing one, get the csv file, copy/paste the result and execute the program with another model number.

The program should be able to display all the list one after the other.

The question is, how can I do that ?

I also think about another solution, the program prompt the user to enter a model number, write it in the csv file, prompt the user to enter an other model number, write it, etc. and stop writing when the user tap “exit”.

Thank you very much for your precious help, I’m a beginners with sql and I do not know very well how to use “IF” sequence and use the data input by the user.

My program is:

set serveroutput on

set termout on

accept nof prompt 'Numero OF :'

spool c:\temp\ext_prix.csv

set serveroutput off

set termout off

set heading off

set pagesize 0

set echo off

set trimspool on

set feedback off

select REOF_RESS_CODE || ';' ||

to_char(REOF_PHOF_NUMERO_PHASE) || ';' ||

translate(to_char(nvl(REOF_TPS_PASSE,0)),'.','.') || ';' ||

translate(to_char(nvl(REOF_MT_PASSE,0)),'.','.')

from ressource_of

where reof_orfa_numero = '&nof'

union all

select stmv_arti_code || ';' ||

arti_designation || ';;' ||

translate(to_char(stmv_prix_unitaire_ue * beof_qte_besoin_ue),'.','.')|| ';;' ||

       BEOF_QTE_BESOIN_UE|| ';;' ||

       BEOF_CUMUL_QTE_SORTIE_UE

from   stock_mouvement, article , besoin_of

where  arti_code        = stmv_arti_code

and    stmv_orfa_numero = '&nof'

and stmv_nmst_code   in ('OF-SOR-CPT','OF/SOR/CPT')

and STMV_CENT_CODE   != 'ELEC'

and beof_orfa_numero  = stmv_orfa_numero

and    beof_arti_code    = stmv_arti_code

group by stmv_arti_code,

         arti_designation,

         stmv_prix_unitaire_ue,

             BEOF_QTE_BESOIN_UE,

             BEOF_CUMUL_QTE_SORTIE_UE

;

spool off

exit

And the csv files look like:

 

132500
1321000
1321200
1321300
399147.5892.5
3231800
3231900
3232057.956896.05
323300.7589.25
3474000
399608952
3996500
399708952
323806.25743.75
323903357
32010000
34711000
10.2067Produit 113357.429122
45.1773Produit 261284.925822
100.0447Produit 32.282622
100.0473Produit 44.23052222
100.0489Produit 58.730622
110.0008Produit 60.47527422
110.001Produit 70.882622
110.0012Produit 81.71892822
116.2Produit 90.6282721212
120.0007Produit 100.14244822
120.0009Produit 110.20977422
120.0011Produit 120.3872522
120.2007Produit 130.131822
120.2009Produit 140.22282622
120.201Produit 150.9122
157.0059Produit 1615.4130422
157.006Produit 1723.63385622
157.008Produit 1815.63374622
169.0037Produit 1925.49210111
185.0027Produit 200.25466822
185.0035Produit 216.922
185.0075Produit 223.522
208.5232Produit 239.30178611
545.0567Produit 2412222
545.0568Produit 25126.48201822
800B0082Produit 26479.9372822
800B0082Produit 275279.310082222
TDProduit 28192222

Thank you very much in advance.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2014
Added on Oct 3 2014
3 comments
1,327 views