Text search in PLSQL

Happens to me to be working more and more on Oracle SQL, and, having no tech background about it, I take notice about every trick I put my hands on.

Expanding a previous topic, I would like now to look in an Oracle database structure.

For now, I only need to look for columns name and all it take is

SELECT *
FROM all_tabs_columns
WHERE column_name LIKE '%keyword%'
ORDER BY 2

Hell that was easy.

How to use Google WebFonts in Rails

One of the Rails main mantras is to DRY (Dont Repeat Yourself).

If you are just like me and would like to follow this principle, you should use this code in your controller in order to use Google WebFonts.

def google_font_link_tag(family)

tag(‘link’, {:rel => :stylesheet,
:type => Mime::CSS,
:href => “http://fonts.googleapis.com/css?family=#{family}”},
false, false)

end

APPP

Un’iniziativa singolare, di quelle che ti fanno pensare, in Svizzera.

Un movimento dal nome (decisamente auto-esplicativo) Anti PowerPoint Party.

Non si presentano come un partito che però promuove l’opensource o alternative più economiche.
Predicano piuttosto il puro fastidio derivante dall’uso ossessivo di presentazioni anche nei casi meno adeguati e quindi la necessità di bandire l’applicazione dai pc svizzeri.

Cadono però nella trappola del volersi guadagnare spazio gonfiando il petto e sparando cifre irragionevolmente alte sia riguardo al costo effettivo di PowerPoint che riguardo ai loro irrealistici obiettivi di seguito elettorale, ma una menzione se la meritano, se non altro perchè mi piacciono i partiti che mettono bene in chiaro il loro obiettivo, specie se direttamente nel nome.

Se fondassi un partito politico

Non mi capita spesso di parlare di politica. Di solito preferisco starmene ad ascoltare gli altri che ne parlano.

La politica poi è un argomento pesante da trattare: ho imparato presto concetti come il voto e la sua segretezza, ma anche che per questioni di politica si rischia di rompere amicizie o rapporti in genere. E, anche in Italia, questo non succede nemmeno per il calcio.
Proprio per questo non sono per niente adatto a politicare.

Però SE fondassi un partito politico, lo chiamerei qualcosa del tipo

Non voglio il tuo voto

Si, perchè del tuo voto non me ne frega davvero un cazzo.

Read more…

Text search in stored procedures and jobs in SQL Server

Sometimes you have to face a database without documentation.
Sometimes you have so many stored procedures that you don’t know where they are used.
To be able to search in the content of stored procedures or jobs is useful in this case and many others.

Stored Procedures

In SQL Server 2000 every database object is indexed in the sys.sysobjects of the same database, while the content is contained in sys.syscomments.
Since SQL Server 2005 you should use respectively sys.objects and sys.sql_modules.

Therefore, to search in this content you just have to

/** SQL Server 2000 **/
SELECT DISTINCT name, type_desc
FROM sysobjects O
  JOIN syscomments C
ON ( O.id = C.id )
WHERE text LIKE '%%'
ORDER BY name

/** SQL Server 2005/8 **/
SELECT DISTINCT name, type_desc
FROM sys.objects O
  JOIN sys.sql_modules SM
ON ( O.object_id = SM.object_id )
WHERE definition LIKE '%%'
ORDER BY name

Read more…

Delete duplicate records/rows in SQL

If in a table, you have 2 identical records, no SQL query can help you to distinguish them. That’s it.

However, there are many ways to deal with this probably undesired situation.

We’ll follow our analysis using a table shaped like this one

CREATE TABLE [dbo].[LU_PRODUCTS](
  [ID_STYLE] [int] NOT NULL,
  [ID_SUBCLASS] [int] NOT NULL,
  [ID_COLOR] [smallint] NOT NULL,
  [DESC_STYLE_COLOR] [varchar](100) NOT NULL,
  [ID_BORN_EVENT] [smallint] NULL
)

Verifying the problem

First of all, you’ll need to be aware that duplicate records are present in your table. The next query returns the duplicate rows and the number of duplicates

SELECT *, COUNT(*) AS DUPLICATES
FROM [dbo].[LU_PRODUCTS]
GROUP BY [ID_STYLE], [ID_SUBCLASS][ID_COLOR], [DESC_STYLE_COLOR],
  [ID_BORN_EVENT]
HAVING COUNT(*) > 1

Read more…

Select grouped rows, basing on another field

As many, facing calculus, I used to say things like ”this will never help me in real life”
Same was about joining the a table with itself in SQL. I finally figured out how this could help.

I got a table shaped like this one

CREATE TABLE [dbo].[BICatalog] (
  [SKU_ID] [char](15),
  [FLAG] [char](1),
  [COMPANY] [float],
  [EVENT] [char](2),
  [YEAR] [float],
...  )
SKU_ID             Flag   Company  Event   Year
-----------------------------------------------
173547Y1EBD9025    A      1        21      2007
173547Y1EBD9025    K      1        21      2011
173547Y1EBD9025    V      1        AF      2009
152058J06901064    B      6        92      2007
152058J06901064    E      6        92      2008
105678J13301037    B      9        SV      2005
118681I31208276    C      1        CO      2005
118681I31208276    D      1        CO      2004

and I would like to select, for every ID, the most updated row, basing on the Year field.

Read more…

HowTo: Riconoscere un buon programmatore

Ripescando tra i bookmark, ho trovato un’interessante articolo di Punto-Informatico dal titolo “Riconoscere un bravo programmatore”, contenente alcune linee guida che possono aiutare i datori di lavoro a riconoscere – pensa un pò – un bravo programmatore quando gli si presenta davanti.

Qui riporto i 3 passi che ho ritenuto maggiormente interessanti:

Indicatori positivi

  • Passione per la tecnologia
  • Programma come se fosse un hobby
  • Ti parlerà di un soggetto tecnico se incoraggiato
  • Significativi progetti personali realizzati
  • Impara da solo nuove tecnologie
  • Ha una sua opinione su quale tecnologia sia migliore a seconda dell’uso
  • Lavora a malincuore su una tecnologia che disapprova
  • È chiaramente svelto, è un piacevole conversatore su una grande quantità di argomenti
  • Ha iniziato a programmare molto prima dell’università
  • Oltre a quanto detto nel CV, ha realizzato grossi progetti che non menziona
  • Conosce un sacco di tecnologie, anche se non lo dice nel CV
  • Difficilmente fa quello che gli si dice di fare, in genere fa molto di più

Read more…