-1

[Resolved] Hello,
(sorry if my english is not exact i'm not english)
I'm using a "test" database and a "working" database
I would like to know how much results i have in my table "incident" in each database to compare
I'm using SQLplus in a .bat file

I resolved the problem writing in only 1 text file (but you can do it with 2)
Write in resultat.txt the result of the query on the working database :

echo SELECT count(*) FROM table; | sqlplus -s user/password@dbprod > path\resultat.txt

Set in the variable return1 (i think the last line of) the content of resultat.txt :

for /f "tokens=*" %%i in (path\resultat.txt) do set return1=%%i 

Same commands with the test

echo SELECT count(*) FROM table; | sqlplus -s user/password@dbtest > path\resultat.txt
for /f "tokens=*" %%i in (path\resultat.txt) do set return1=%%i

Here i overwrite the resultat.txt file but you can write in another text file
And now you can display and test the equality :

echo resultat prod : %return1%
echo resultat test : %return2%
if %return1%==%return2% ( 
echo IMPORT REUSSI 
) else ( 
ECHO IMPORT RATE 
) 
pause
Kishiro
  • 131
  • 1
  • 2
  • 15
  • Je suis sûr que vous auriez plus de réponse si vous auriez demandé en anglais. Comme les .bat n'offrent pas beaucoup, est-ce possible d'utiliser quelque-chose comme powershell? – Axel Apr 16 '18 at 09:08
  • [possible duplicate](https://stackoverflow.com/questions/46179288/get-output-from-command-line-and-save-into-variable/46179429#46179429) – Stephan Apr 16 '18 at 09:10
  • Oui je peux utiliser powershell par contre il faudrais que je "traduise" tout mon .bat en powershell non? – Kishiro Apr 16 '18 at 09:16
  • [not necessarily](https://stackoverflow.com/a/25305537/2152082) – Stephan Apr 16 '18 at 09:17
  • ok Thakns @stephan so i can use : for /f "tokens=*" %%i in ('powershell /command "..."') do set return=%%i echo %return% and replace by my powershell command – Kishiro Apr 16 '18 at 09:21
  • 1
    This is an English site, so you'll have to translate your question to English; otherwise it might likely get closed. Refer to this help article: [ask] – aschipfl Apr 16 '18 at 11:18
  • Translates done – Kishiro Apr 16 '18 at 12:16
  • Your last line looks fine. Define "doesn't work". Any errormessages? Wrong result? What do you expect, and what do you get? – Stephan Apr 16 '18 at 12:23
  • i expected to have the result of my query SELECT (example : 12345) – Kishiro Apr 16 '18 at 12:41
  • When i don't write "@echo off" I actually have a doc (SQLplus i think) – Kishiro Apr 16 '18 at 12:43
  • I have put a screenshot – Kishiro Apr 16 '18 at 13:02
  • the output in your linked image is the help of `sqlplus`. Which probably means, there is a syntax error with the `sqlplus` command. Try to use the `sqlplus` command on ith's own (without the surrounding `for`) and correct, until you get the correct output. * Then* put the `for` around it. – Stephan Apr 16 '18 at 13:04
  • I have fount another method : @echo SELECT count(*) FROM incident_demande; | sqlplus -s m_test/m_test@asisline_test > C:\path...\resultat.txt – Kishiro Apr 16 '18 at 13:44
  • It writes correctly in my files but there is the name of column, how should i take only the number? – Kishiro Apr 16 '18 at 13:45
  • you can use proper tokens and delims with a `for /f` loop with a [file content](https://ss64.com/nt/for_f.html) or [a command](https://ss64.com/nt/for_cmd.html) (sorry, I never worked with `sql`, so I don't know, how the output would look like to help you; If you can't manage it yourself, show the exact ouput of your command) – Stephan Apr 16 '18 at 14:26
  • It's ok i resolved the problem i post the solution – Kishiro Apr 16 '18 at 14:37

1 Answers1

0

[Resolved] Hello,
(sorry if my english is not exact i'm not english)
I'm using a "test" database and a "working" database
I would like to know how much results i have in my table "incident" in each database to compare
I'm using SQLplus in a .bat file

I resolved the problem writing in only 1 text file (but you can do it with 2)
Write in resultat.txt the result of the query on the working database :

echo SELECT count(*) FROM table; | sqlplus -s user/password@dbprod > path\resultat.txt

Set in the variable return1 (i think the last line of) the content of resultat.txt :

for /f "tokens=*" %%i in (path\resultat.txt) do set return1=%%i 

Same commands with the test

echo SELECT count(*) FROM table; | sqlplus -s user/password@dbprod > path\resultat.txt
for /f "tokens=*" %%i in (path\resultat.txt) do set return1=%%i

Here i overwrite the resultat.txt file but you can write in another text file
And now you can display and test the equality :

echo resultat prod : %return1%
echo resultat test : %return2%
if %return1%==%return2% ( 
echo IMPORT REUSSI 
) else ( 
ECHO IMPORT RATE 
) 
pause
Kishiro
  • 131
  • 1
  • 2
  • 15