How can I concat a defined variable in oracle? - oracle

I'm new in Oracle db and I'm working on script. So I trying to run a lot of scripts with a relative
var path and I have subfolder.
Folder A:
Folder A.Child-1
Folder A.Child-2
RunAll.sql
Folder A.Child-1:
Script 1
Script 2
I know we can define path var like:
define path='C:\Folder A.Child-1';
#&pathScr\RunAll.sql;
If I put a complete path for Eg: Script 1, the script can be exec. But is there any way to do something like:
define Scriptpath= Concat(&path, 'Folder A.Child-1')
#&Scriptpath\Script 1.sql;
So that I only need to declare the path only once.
What I tried:
define Scriptpath= concat(&path, 'Folder A.Child-1')
#&Scriptpath\Script 1.sql;
define Scriptpath= &path || 'Folder A.Child-1'
#&Scriptpath\Script 1.sql;
Declare Scriptpath:= = &path || 'Folder A.Child-1';
Begin
End;
#&Scriptpath\Script 1.sql;
All those trial return errors something like
Can not open file concat(&path, 'Folder A.Child-1')

You don't need concat, just use the same way with simple variable substitution in shell scripting:
SQL> def path1='mypath'
SQL> def path2='&path1/xyz.sql'
SQL> prompt &path1
mypath
SQL> prompt &path2
mypath/xyz.sql

Related

Is there any way to pass variables from bash script to Jenkinsfile without using extra plugins

I'm trying to use variables declared in bash script in my Jenkinsfile (jenkins pipeline) without using extra plugins like EnvInject plugin
please help, any idea will be appreciated
you need to output those variables to a file like Property/Yaml file. Then use pipeline step readProperties / readYaml to read into Map in Jenkinsfile.
steps {
sh'''
...
AA=XXX
BB=YYY
set > vars.prop
'''
script {
vars = readProperties file: 'vars.prop'
env << vars // merge vars into env
echo 'AA='+ env['AA']
}
}
I have done it with something like this, you can store the variables inside Shell into a file inside workspace and then you are out of shell block, read the file in groovy to load the key value pair into your environment
Something like:
def env_file = "${WORKSPACE}/shell_env.txt"
echo ("INFO: envFileName = ${env_file}")
def read_env_file = readFile env_file
def lines = read_env_file.readLines()
lines.each { String line ->
def object = line.split("=")
env.object[0] = object[1]
}

Export output of sql in Excel using Query

I want to export outupt of sql query. But I dont want to do it manually like right click on output and then export. I want to export output in excel in specific directory.
Change filename_excel to
filename_excel = [my_directory name '_N' num2str(1) '.xlsx'];
where
my_directory = 'C:\some\directory\structure\';
Alternatively (though use the first solution if possible) you can go:
current_dir = cd;
cd my_directory;
filename_excel = [ name '_N' num2str(1) '.xlsx'];
writetable(Table,filename_excel,'Sheet', 3, 'Range','A5');
cd current_dir;
clear current_dir;
by #aybybtu

How to sequentially create multiple CSV files in Ruby?

Silly question, but I want to do some processing on a dataset and put them into different CSVs, like UDID1.csv, UDID2.csv, ..., UDID1000.csv. So this is my code:
for i in 1..1000
logfile = File.new('C:\Users\hp1\Desktop\Datasets\New File\UDID#{i}\.csv',"a")
#I'll do some processing here
end
But the program throws an error when running because of the UDID#{i} part. So, how to overcome this issue? Thanks.
Edit: This is the error:
in `initialize': No such file or directory # rb_sysopen - C:\Users\hp1\Desktop\Datasets\New File\udid#{1}\.csv (Errno::ENOENT)from C:/Ruby21/bin/hashedUDID.rb:38:in `new' from C:/Ruby21/bin/hashedUDID.rb:38:in '<main>'
The ' is one problem, another problem is the path.
In your posting the New File must exist as a directory. Inside this directory must exist another directories like UDID0001. This gets a .csv file.
Correct is (I don't use the non-rubyesk for-loop):
1.upto(1000) do |i|
logfile = File.new("C:\\Users\\hp1\\Desktop\\Datasets\\UDID#{i}.csv", "a")
#I'll do some processing here
logfile.close #Don't forget to close the file
end
Inside " the backslash must be masked (\\). Instead you may use /:
logfile = File.new("C:/Users/hp1/Desktop/Datasets/New File/UDID#{i}/.csv", "a")
Another possibility is the usage of %i to insert the number:
logfile = File.new("C:/Users/hp1/Desktop/Datasets/New File/UDID%02i/.csv" % i, "a")
I prefer to use open, then the file is closed with the end of the block:
File.open("C:/Users/hp1/Desktop/Datasets/New File/UDID%04i/.csv" % i, "a") do |logfile|
#I'll do some processing here
end #closes the file
Warning:
I'm not sure, if you really want to create 1000 log files (The File is opened inside the loop. so each step creates a file.).
If yes, then the %04i-version has the advantage, that the files get all the same number of digits (starting with 0001 and ending with 1000).
(1..10).each { |i| logfile = File.new("/base/path/UDID#{i}.csv") }
You must use double quote (") when you need string interpolation.
#{} can only be used in strings with double quotes ". So change your code to:
for i in 1..1000
logfile = File.new("C:\Users\hp1\Desktop\Datasets\New File\UDID#{i}\.csv","a")
# other stuff
end

How to write a file in specific path in ruby

I want to save my files in specific path..
I have used like this
file_name = gets
F = open.(Dir.pwd, /data/folder /#{#file_name },w+)
I'm not sure whether the above line is correct or not! Where Dir.pwd tell the directory path followed by my folder path and the file name given.
It should get store the value on the specific path with the specific file name given. Can anyone tell me how to do that.
Your code has multiple errors. Have you ever tried to execute the script?
Your script ends with:
test.rb:7: unknown regexp options - fldr
test.rb:7: syntax error, unexpected end-of-input
F = open.(Dir.pwd, /data/folder /#{#file_name },w+)
First: You need to define the strings with ' or ":
file_name = gets
F = open.(Dir.pwd, "/data/folder/#{#file_name}","w+")
Some other errors:
You use file_name and later #file_name.
The open method belongs to File and needs two parameters.
The file is defined as a constant F. I would use a variable.
The path must be concatenated. I'd use File.join for it.
You don't close the file.
After all these changes you get:
file_name = gets
f = File.open(File.join(Dir.pwd, "/data/folder/#{file_name}"),"w+")
##
f.close
and the error:
test.rb:29:in `initialize': No such file or directory # rb_sysopen - C:/Temp/data/folder/sdssd (Errno::ENOENT)
The folder must exist, so you must create it first.
Now the script looks like:
require 'fileutils'
dirname = "data/folder"
file_name = gets.strip
FileUtils.mkdir_p(dirname) unless Dir.exists?(dirname)
f = File.open(File.join(Dir.pwd, dirname, file_name),"w+")
##fill the content
f.close

Run a gdb macro for all files in a directory

I want to create a macro for which a directory path will be given. The macro in-turn has to run another macro for all the files in the directory. Is that possible in gdb ?
I assume that the macro you want to run is a gdb macro. To solve this, I suggest you use the Python support in gdb to encompass this. Put the following in forallindir.py
import gdb
import os
class ForAllInDir (gdb.Command):
"Executes a gdb-macro for all files in a directory."
def __init__ (self):
super (ForAllInDir, self).__init__ ("forallindir",
gdb.COMMAND_SUPPORT,
gdb.COMPLETE_NONE, True)
def invoke(self, arg, from_tty):
arg_list = gdb.string_to_argv(arg)
path = arg_list[0]
macro = arg_list[1]
for filename in os.listdir(path):
gdb.execute(macro + ' ' + os.path.join(path, filename))
ForAllInDir()
Then in gdb to source forallindir.py and it should work. For example, define a test macro like
define testit
print "i got called with $arg0"
end
and forallindir /tmp/xx testit with two sample files in that directory will give us
$1 = "i got called with /tmp/xx/ape"
$2 = "i got called with /tmp/xx/bear"
Hope that helps.

Resources