martedì 11 ottobre 2016

Oracle Tip: executing SQL scripts in SQL Developer

One common problem with SQL Developer is executing huge SQL scripts (i.e. INSERT statements from the export of a big table).
Typically you will get the following error when trying to open the file: 


which is caused by an OutOfMemoryError of the Java Heap space.


One convenient way to execute .sql without having to open the script in the SQL Developer editor is to configure the default path for scripts.
Go to Tools -> Preferences->Database->Worksheet:


and select the path where you want to place the SQL scripts to execute.
Then, go to the SQL Developer editor and simply use the @ command to reference and execute the script.


lunedì 10 ottobre 2016

ODI Tip: Generating flat files with spaces in column names

I had a requirement of generating a .csv file with header out of a database table.
I had created the model as follows:
  • File Format: Delimited
  • Record Separator: Unix  
  • Field Separator: , (comma)
In the interface, I had placed the file as Target Datasource and used 'IKM SQL to File Append' with the following options:


Unfortunately, the header columns were truncated at the first space and adding double quotes did not help. The column header were all truncated after the first space found.
After investigating, I came to the conclusion that there is was no quick or easy way to deal with spaces. I guess the only way is creating a custom version of the IKM.
Therefore, since I have very little time, I have replaced the spaces with underscores and added a OdiOSCommand in the package to replace the underscores with spaces in the output file.



ODIOSCommand is a more flexible version of OSCommand and allows you to invoke a sed command to do the replacement in place (-i) of the underscores with spaces.

sed -i 's/_/ /g' <filename>

lunedì 18 luglio 2016

Oracle Tip: Exception getObjectName("R", "OBI_EXEC_SESS_<$=Y$>", "D")

When running OBIA Load Plan, today I got into the following error when running SIL_DomainGeneral_CM_Source_Load scenario:


com.sunopsis.tools.core.exception.SnpsSimpleMessageException: ODI-17517: Error during task interpretation.
 Task: 6
java.lang.Exception: The application script threw an exception: com.sunopsis.tools.core.exception.SnpsSimpleMessageException: Exception getObjectName("R", "OBI_EXEC_SESS_<$=Y$>", "D") :  BSF info: Run Alter Session Commands-SRC (DB Link) at line: 0 column: columnNo


The solution to this error is given in Doc ID 1948605.1 from Oracle Support.
You should connect to ODI Physical Architecture in ODI Topology and check that BIAPPS_BIACOMP has got a Default Schema defined (and that connectivity is in place). If there is no Physical Schema defined, then check the option. 
 


 

If this does not solve the problem, check BIAPPS DWH Physical Connection. Make sure that at least one of the physical schemas is marked as Default Schema.



Somehow during migration activities, we lost the selection on one of them.



lunedì 29 febbraio 2016

Configuring PGP Keys in GNU Private Guard

Imagine you are receiving a PGP encrypted file from a third-party. 
The file has been encrypted using the customer's Public Key and now you have to decrypt it in a separate server where Gnu PG is installed. 
The first thing you need to do is to import the keys so they can be used to decrypt the message.
The following command is used to import the Public Key: 

gpg --import newkey.txt
 
If a valid Public Key is given, this is how the command output should look like: 

bash-4.1$ gpg2 --import newkey.txt
gpg: key xxxxxx: "Public Key Description <email@xxx.com>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
 

To import the Private Key, use the following command: 

gpg --allow-secret-key-import --import newpriv_key.txt
 
To check if keys have been imported correctly, you can use the following command:

bash-4.1$ gpg --list-keys
/xxxx/xxxxx/.gnupg/pubring.gpg
-----------------------------------
pub   2048R/xxxxxxx 2016-02-17 [expires: 2019-02-16]
uid                 Public Key Description <email@xxx.com>

sub   2048R/xxxxxxx 2016-02-17 [expires: 2019-02-16]

The Private Key provided has got a passphrase. So if you want to decrypt a sample file that has been encrypted using the associated Public Key, you should use the following command.

bash-4.1$ echo <passphrase>|gpg --output test.txt --batch --passphrase-fd 0 --decrypt test.gpg
gpg: encrypted with 2048-bit RSA key, ID
XXX450C8 , created 2016-02-17
      "
Public Key Description <email@xxx.com>"
bash-4.1$ more test.txt
Hello World!!!

 

If you are getting an error when passing the passphrase, try setting up the following variables: 

 
export GPG_TTY=`tty` 
export PINENTRY_USER_DATA="USE_CURSES=1"

By doing this, I was able to decrypt the message successfully.

martedì 26 gennaio 2016

Automate DOS commands - Ping example

Imagine you have been given the lovely task of finding out the IP address of more than 40 servers. Do you really want to do it manually? Definitely I do not.
I have created a script and, even if I have to admit that it took me almost more time to write it than doing the task manually, I hope this can save someone's else time.
The script I have written looks like this:

@ECHO OFF
ping -n 1 <ServerName1> | for /F "tokens=*" %%a in ('findstr Reply') do @echo
<ServerName1>:%%a
ping -n 1
<ServerName2> | for /f "tokens=*" %%a in ('findstr Reply') do @echo <ServerName2>:%%a
exit


The option "-n 1" is used to define how many times the server is pinged. One time is enough to get the following output:

Pinging <ServerName1> [192.143.52.103] with 32 bytes of data:
Reply from 192.143.52.103: bytes=32 time=45ms TTL=59
Ping statistics for 192.143.52.103:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 45ms, Maximum = 45ms, Average = 45ms


The second part of the command parses the output of the ping command looking for a string starting with 'Reply' and prints the results.
@ECHO OFF is used to prevent the script to print the DOS command in the output.
Here is an example of output file:

<ServerName1>:Reply from 192.143.52.103: bytes=32 time=18ms TTL=59 <ServerName2>:Reply from 191.143.52.103: bytes=32 time=19ms TTL=59


I have decided to separate the server name from the 'Reply' string using a semicolon, but it is mainly because this way I can treat the output as a simple semicolon-delimited file.