30 Nisan 2015 Perşembe

Hashtable on PL/SQL


Some time ago, It's bubbled up that if there is a way to use hashtables in PL/SQL just like in Java which is very oftenly used. We associate the key-value relationship with arrays but since the keys are numeric we need to use associative arrays in order to produce alpha keys. There is a simple and self explanatory example below:


Java:

Hashtable<String, String> htable = new Hashtable<String, String>();

htable.put("MIDFIELDER", "SNEIJDER");
htable.put("STRIKER", "DROGBA");

System.out.println(htable.get("STRIKER"));


PL/SQL:

DECLARE
  TYPE t_htable IS TABLE OF VARCHAR2(30) INDEX BY VARCHAR2(30);
  htable t_htable;
BEGIN
  htable('MIDFIELDER') := 'SNEIJDER';
  htable('STRIKER') := 'DROGBA';

  dbms_output.put_line(htable('STRIKER'));


END;

Hiç yorum yok:

Yorum Gönder