Friday, December 19, 2014

Find Difference between two Texts to see matching , added , deleted and changed data highlighted






A very common problem to all those people who write a lot specially in computer is to compare two text files and see the differences between those files . I also faced a lot of such scenarios where we need to find difference between 2 files which were written under 2 different versions and then it make us think, which one is the correct one ?  If this is correct one what is wrong in the other one?

Sometimes even a small space or semi colon or a special character change the meaning of whole text  and it makes you wonder for whole day . 

Well ! I came to know about this website http://www.comparefilesfoldersandtext.com/  which helps :
  1.  Compare Texts
  2.  Compare Files
  3.  Compare Folders
In this Blog I am going to explain how you can compare very long pieces of text using this website in seconds and that too free .

  •  You will see a screen like the screenshot below  :

Home Page of Text Comparison Utility



  • As you can see there are 2 text boxes here named Original Text and Test Text (highlighted in orange in figure below ) 
Showing Original Text and Test Text  - Text Boxes
  • Write some data in Text Box named Original Text
  • Write data which you want to compare in the Text Box named Test Text . See as below :
Written 2 Texts to Compare in Text Boxes provided
  • Click Show Difference ! button ( blue colored just below text boxes ) and we will see output in few seconds :
Text Comparison Result
  • The Screen above shows differences between 2 texts which were entered for comparison .See the green colored line under test Text . This is the line which was added in second text and this is the difference which we wanted to find .
  • The Screen also shows legends where Green Means text added which means anything which was added to the new text written
  • If there is any change it will be colour coded to yellow , see screen shot below where there is a little change in 2 versions and it highlights it in yellow:

Showing changes in text

  • If there is something which is in the first text but not in the second text it is highlighted in red:

Showing Deleted Text

  • It also provides link s legends , Links are shown in the left column of line numbers . f stands for first change . if you click f it will take you to the first change in the text .
  • Link n stands for next change and helps you to go to next change in forward direction
  • Link t is to go to the top of the result 

 

Give it a try and i hope you will love this wonderfully awesome application site . In my next blog I will write more about the files and folders differences shown by the same application .

Tuesday, December 16, 2014

How to enter & as a string in Insert statements in oracle SQL

If we need to enter & as a string in any SQL insert or query , Oracle asks for a new value .. To over come this , we have below solution :

1. select 'hi s this is how to enter &'||' as string in SQL ' from dual;

2. select 'hi s this is how to enter '|| '&' ||' as string in SQL ' from dual;

3. use following and run as a script :

set define off scan off
select 'hi s this is how to enter & as string in SQL ' from dual;

Quotes Operator in Oracle SQL

Sometimes its problematic to deal with single quotes in Oracle SQL which comes in while writing some SQL codes . Below is the new Quotes Operator introduced by oracle to overcome this :
Oracle realises that long complex strings having lot of single quotes can turn out to become cumbersome and prone to errors that may not be caught during testing.
Release 10g onwards, a new quoting mechanism is provided in the form of "q". This new quote operator allows us to choose our own quotation mark delimiter.
Here are some examples -
SQL> select 'amar's web blog. It's personal..' str from dual;
select 'amar's web blog. It's personal..' str from dual
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
What we normally do:-
SQL> select 'amar''s web blog. It''s personal..' str from dual;
STR
--------------------------------
amar's web blog. It's personal..
1 row selected.
Here is use of Q - quote operator. The above statement can also be represented as any one of the below.
select q'(amar's web blog. It's personal.)' str from dual;
select q'[amar's web blog. It's personal.]' str from dual;
select q'Aamar's web blog. It's personal.A' str from dual;
select q'/amar's web blog. It's personal./' str from dual;
select q'Zamar's web blog. It's personal.Z' str from dual;
select q'|amar's web blog. It's personal.|' str from dual;
select q'+amar's web blog. It's personal.+' str from dual;
(New added)
select q'zamar's web blog. It's personal.z' str from dual;
And so on. After the Q-quote is specified, provide the single quote along with a unique character at the beginning of the string. To close the string, provide the same character followed by the single quote. The single and the provided character form the two character string enclosure.
If you decide to use braces, Oracle expects matching enclosures, i.e., Open brackets should be represented by closed brackets at the end of the string. Other characters can be represented as they are at both ends.
All we need to take care of is that the last two character delimiter does not show up in the string itself. For instance the below will throw error as the closing characters get repeated within the string.
SQL> select q'aamar's web blog. Ita's personal.a' str from dual;
ERROR:
ORA-01756: quoted string not properly terminated
The same can be used in PL/SQL also.
SQL> declare
2 l_str varchar2(100) := q'[amar's web blog. Ita's personal.]';
3 begin
4 dbms_output.put_line(l_str);
5 end;
6 /
amar's web blog. Ita's personal.
PL/SQL procedure successfully completed.
I recently came across a program that framed dynamic INSERT statement to copy data from one database to another. Unfortunately, one of the record columns had a single quote embedded in the string and this resulted in the program unit to fail in production. This happened in release 9i and the only alternative available was to remove/double the single quotes from the string literal. From release 10g, Q-quote could also be used to prevent this problem. I will simulate the same scenario and try this out.
SQL> create table am100(col1 number, col2 varchar2(100));
Table created.
SQL> create table am102(col1 number, col2 varchar2(100));
Table created.
SQL> insert into am100 values(1, q'[amar's web blog. It's personal]');
1 row created.
SQL> insert into am100 values(2, q'[this is a simple string]');
1 row created.
SQL> insert into am100 values(3, q'[this is just another string]');
1 row created.
SQL> select * from am100;
COL1 COL2
---------- ----------------------------------
1 amar's web blog. It's personal
2 this is a simple string
3 this is just another string
3 rows selected.
SQL> commit;
Commit complete.
Now I will call a simple routine that will read the data and generate dynamic SQL for inserting into another table.
declare
l_str varchar2(4000);
begin
for rec in (select col1, col2 from am100) loop
l_str := 'insert into am102(col1, col2) values (' || rec.col1 ||',''' ||
rec.col2 || ''')';
dbms_output.put_line(l_str);
execute immediate l_str;
end loop;
end;
/
The unit errors out as below, because of the single quote mismatch.
insert into am102(col1, col2) values (1,'amar's web blog. It's personal');
begin
*
ERROR at line 1:
ORA-00917: missing comma
ORA-06512: at line 4
I will now modify the program unit to add Q-quote. We can also use the REPLACE function to remove or double-up single quote in strings, both options are given below.
[] With REPLACE function (doubling the single quote);
declare
l_str varchar2(4000);
begin
for rec in (select col1, replace(col2, '''', '''''') col2 from am100) loop
l_str := 'insert into am102(col1, col2) values ('
|| rec.col1 ||',''' || rec.col2 || ''')';
dbms_output.put_line(l_str);
execute immediate l_str;
end loop;
end;
/
Output generated:-
insert into am102(col1, col2) values (1,'amar''s web blog. It''s personal')
insert into am102(col1, col2) values (2,'this is a simple string')
insert into am102(col1, col2) values (3,'this is just another string')
[] With Q-quote
declare
l_str varchar2(4000);
Begin
for rec in (select col1, 'q''[' || col2 || ']''' col2 from am100) loop
l_str := 'insert into am102(col1, col2) values ('
|| rec.col1 ||',' || rec.col2 || ')';
dbms_output.put_line( l_str );
execute immediate l_str;
end loop;
end;
/
Output generated:-
insert into am102(col1, col2) values (1,q'[amar's web blog. It's personal]')
insert into am102(col1, col2) values (2,q'[this is a simple string]')
insert into am102(col1, col2) values (3,q'[this is just another string]')

Thursday, July 25, 2013

Cygwin error for perl /usr/bin/perl.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

Cygwin error for perl  :


/usr/bin/perl.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory


perl -v will throw error :

cygcheck: track_down: could not find cygssp-0.dll

symtom  : Missing libssp0  package from installation .

Fix : Open Cygwin and click on download from internet , search for  libssp0 . If this package was skipped during download/installation before, Install it now and then perl should be fixed .

$ perl -v

This is perl 5, version 14, subversion 4 (v5.14.4) built for cygwin-thread-multi
(with 7 registered patches, see perl -V for more detail)

Copyright 1987-2013, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

Sunday, February 19, 2012

Quotes Operator in Oracle

Oracle realises that long complex strings having lot of single quotes can turn out to become cumbersome and prone to errors that may not be caught during testing.

Release 10g onwards, a new quoting mechanism is provided in the form of "q". This new quote operator allows us to choose our own quotation mark delimiter.

Here are some examples -

SQL> select 'amar's web blog. It's personal..' str from dual;

select 'amar's web blog. It's personal..' str from dual

*

ERROR at line 1:

ORA-00923: FROM keyword not found where expected

What we normally do:-

SQL> select 'amar''s web blog. It''s personal..' str from dual;

STR

--------------------------------

amar's web blog. It's personal..

1 row selected.

Here is use of Q - quote operator. The above statement can also be represented as any one of the below.

select q'(amar's web blog. It's personal.)' str from dual;

select q'[amar's web blog. It's personal.]' str from dual;

select q'Aamar's web blog. It's personal.A' str from dual;

select q'/amar's web blog. It's personal./' str from dual;

select q'Zamar's web blog. It's personal.Z' str from dual;

select q'|amar's web blog. It's personal.|' str from dual;

select q'+amar's web blog. It's personal.+' str from dual;

(New added)

select q'zamar's web blog. It's personal.z' str from dual;

And so on. After the Q-quote is specified, provide the single quote along with a unique character at the beginning of the string. To close the string, provide the same character followed by the single quote. The single and the provided character form the two character string enclosure.

If you decide to use braces, Oracle expects matching enclosures, i.e., Open brackets should be represented by closed brackets at the end of the string. Other characters can be represented as they are at both ends.

All we need to take care of is that the last two character delimiter does not show up in the string itself. For instance the below will throw error as the closing characters get repeated within the string.

SQL> select q'aamar's web blog. Ita's personal.a' str from dual;

ERROR:

ORA-01756: quoted string not properly terminated

The same can be used in PL/SQL also.

SQL> declare

2 l_str varchar2(100) := q'[amar's web blog. Ita's personal.]';

3 begin

4 dbms_output.put_line(l_str);

5 end;

6 /

amar's web blog. Ita's personal.

PL/SQL procedure successfully completed.

I recently came across a program that framed dynamic INSERT statement to copy data from one database to another. Unfortunately, one of the record columns had a single quote embedded in the string and this resulted in the program unit to fail in production. This happened in release 9i and the only alternative available was to remove/double the single quotes from the string literal. From release 10g, Q-quote could also be used to prevent this problem. I will simulate the same scenario and try this out.

SQL> create table am100(col1 number, col2 varchar2(100));

Table created.

SQL> create table am102(col1 number, col2 varchar2(100));

Table created.

SQL> insert into am100 values(1, q'[amar's web blog. It's personal]');

1 row created.

SQL> insert into am100 values(2, q'[this is a simple string]');

1 row created.

SQL> insert into am100 values(3, q'[this is just another string]');

1 row created.

SQL> select * from am100;

COL1 COL2

---------- ----------------------------------

1 amar's web blog. It's personal

2 this is a simple string

3 this is just another string

3 rows selected.

SQL> commit;

Commit complete.

Now I will call a simple routine that will read the data and generate dynamic SQL for inserting into another table.

declare

l_str varchar2(4000);

begin

for rec in (select col1, col2 from am100) loop

l_str := 'insert into am102(col1, col2) values (' || rec.col1 ||',''' ||

rec.col2 || ''')';

dbms_output.put_line(l_str);

execute immediate l_str;

end loop;

end;

/

The unit errors out as below, because of the single quote mismatch.

insert into am102(col1, col2) values (1,'amar's web blog. It's personal');

begin

*

ERROR at line 1:

ORA-00917: missing comma

ORA-06512: at line 4

I will now modify the program unit to add Q-quote. We can also use the REPLACE function to remove or double-up single quote in strings, both options are given below.

[] With REPLACE function (doubling the single quote);

declare

l_str varchar2(4000);

begin

for rec in (select col1, replace(col2, '''', '''''') col2 from am100) loop

l_str := 'insert into am102(col1, col2) values ('

|| rec.col1 ||',''' || rec.col2 || ''')';

dbms_output.put_line(l_str);

execute immediate l_str;

end loop;

end;

/

Output generated:-

insert into am102(col1, col2) values (1,'amar''s web blog. It''s personal')

insert into am102(col1, col2) values (2,'this is a simple string')

insert into am102(col1, col2) values (3,'this is just another string')

[] With Q-quote

declare

l_str varchar2(4000);

Begin

for rec in (select col1, 'q''[' || col2 || ']''' col2 from am100) loop

l_str := 'insert into am102(col1, col2) values ('

|| rec.col1 ||',' || rec.col2 || ')';

dbms_output.put_line( l_str );

execute immediate l_str;

end loop;

end;

/

Output generated:-

insert into am102(col1, col2) values (1,q'[amar's web blog. It's personal]')

insert into am102(col1, col2) values (2,q'[this is a simple string]')

insert into am102(col1, col2) values (3,q'[this is just another string]')

Saturday, December 3, 2011

Default display format for date field in Oracle SQL Developer

For date fields, by default SQL Developer will display data in date only without the time. To set it to display the time as well, do the following:

1. From SQL Developer, open menu Tools >> Preferences.
2. From the Preferences dialog, select Database >> NLS Parameters from the left panel.
3. From the list of NLS parameters, enter DD-MON-RR HH24:MI:SS into the Date Format field.
4. Save and close the dialog, done!