Thursday, July 31, 2008

vi commands

Switch to command mode <ESC>

ESC start command mode ( it starts in command mode )
i change to insert mode
:q quit
:wq write and quit
:w write the file
:# goto line #
/str search down for "str"
?str search up for "str"
dd delete line
x delete character
dw delete word ( cut )
yy yank line ( copy )
yw yank word
p paste
u undo ( only limit is the last write )
. repeat last change
cw change word

Go to line number ## :##

Undo previous command: u

Undo all changes to line: U

Search backward for string: ?string

Search forward for string: /string

% (entire file) s (search and replace) /old text with new/ c (confirm) g (global - all): %s/oldstring/newstring/cg

Delete 5 lines (to buffer): 5dd

Delete lines 5-10:5,10d

string replacement

Sometimes you want to replace one string with another. This is done with the ex command "s". The form of the replacement is :
: line_range s/old/new/g
ex ( replace foo with bar from line 10 to 20 ) :
:10,20s/foo/bar/g
You can use visual mode to select the lines, when you type the colon to start the command it will use symbols for the visual line range.

Wednesday, June 4, 2008

Increment a variable in for-each loop

No can do.

XSLT is a declarative programming language. You can bind a value to a variable only once, you cannot change it later. <link>

Search by Element and print RANum and position()

XML:
<InvoiceAdj>
<RAInfo RANumType="79">
<RANum>RANumType_79</RANum>
</RAInfo>
<RAInfo RANumType="82">
<RANum>RANumType_82</RANum>
</RAInfo>
<RAInfo RANumType="85">
<RANum>RANumType_85</RANum>
</RAInfo>
<RAInfo RANumType="88">
<RANum>RANumType_88</RANum>
</RAInfo>
<RAInfo RANumType="79">
<RANum>RANumType_79_1</RANum>
</RAInfo>
<RAInfo RANumType="82">
<RANum>RANumType_82_1</RANum>
</RAInfo>
<RAInfo RANumType="85">
<RANum>RANumType_85_1</RANum>
</RAInfo>
<RAInfo RANumType="88">
<RANum>RANumType_88_1</RANum>
</RAInfo>
</InvoiceAdj>


XSLT: Search by attribute RANum = 'RANumType_88'
<xsl:for-each select="InvoiceAdj/RAInfo">
<xsl:choose>
<xsl:when test="RANum = 'RANumType_88'">
<tr>
<td><xsl:value-of select="RANum"/></td>
<td><xsl:value-of select="position()"/></td>
<td></td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>


HTML:
<tr>
<td>RANumType_88</td>
<td>4</td>
<td></td>
</tr>

Search by Attribute and print RANum and position()

XML:

<InvoiceAdj>
<RAInfo RANumType="79">
<RANum>RANumType_79</RANum>
</RAInfo>
<RAInfo RANumType="82">
<RANum>RANumType_82</RANum>
</RAInfo>
<RAInfo RANumType="85">
<RANum>RANumType_85</RANum>
</RAInfo>
<RAInfo RANumType="88">
<RANum>RANumType_88</RANum>
</RAInfo>
<RAInfo RANumType="79">
<RANum>RANumType_79_1</RANum>
</RAInfo>
<RAInfo RANumType="82">
<RANum>RANumType_82_1</RANum>
</RAInfo>
<RAInfo RANumType="85">
<RANum>RANumType_85_1</RANum>
</RAInfo>
<RAInfo RANumType="88">
<RANum>RANumType_88_1</RANum>
</RAInfo>
</InvoiceAdj>


XSLT: Search by attribute RANumType = 79 or 88

<xsl:for-each select="InvoiceAdj/RAInfo">
<xsl:choose>
<xsl:when test="@RANumType = 79 or @RANumType = 88">
<tr>
<td><xsl:value-of select="RANum"/></td>
<td><xsl:value-of select="position()"/></td>
<td></td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>


HTML:

<tr>
<td>RANumType_79</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>RANumType_88</td>
<td>4</td>
<td></td>
</tr>
<tr>
<td>RANumType_79_1</td>
<td>5</td>
<td></td>
</tr>
<tr>
<td>RANumType_88_1</td>
<td>8</td>
<td></td>
</tr>

xsl:for-each sample:

xml: <InvoiceAdj AdjType="CS" AdjNumType="BP">

1. <xsl:for-each select="InvoiceAdj">

2. <xsl:for-each select="InvoiceAdj[@AdjType='CS']">

3. <xsl:for-each select="InvoiceAdj[@AdjType='CS' and @AdjNumType = 'BP']">

Legal filter operators are:

1. = (equal)
2. != (not equal)
3. &lt; less than
4. &gt; greater than

XSLT Examples

Thursday, March 27, 2008

Select between dates in Oracle SQL

SQL> with t as (select to_date('01/01/2007','dd/mm/yyyy') as update_date from dual union all
2 select to_date('01/01/2007','dd/mm/yyyy') from dual union all
3 select to_date('03/01/2007','dd/mm/yyyy') from dual union all
4 select to_date('03/01/2007','dd/mm/yyyy') from dual union all
5 select to_date('03/01/2007','dd/mm/yyyy') from dual union all
6 select to_date('04/01/2007','dd/mm/yyyy') from dual union all
7 select to_date('05/01/2007','dd/mm/yyyy') from dual union all
8 select to_date('07/01/2007','dd/mm/yyyy') from dual union all
9 select to_date('07/01/2007','dd/mm/yyyy') from dual)
10 -- end of test data
11 select to_char(x.UPDATE_DATE, 'YYYY-MM-DD') as update_date, DECODE(t.update_date, NULL, 0, count (*)) as count
12 from (select to_date('2007-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')+(rownum-1) as update_date
13 from dual
14 connect by rownum <= (to_date('2007-02-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') -
15 to_date('2007-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'))) x
16 LEFT OUTER JOIN t ON (x.update_date = t.update_date)
17 where x.UPDATE_DATE >= to_date('2007-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
18 and x.UPDATE_DATE < color="navy">'2007-02-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
19 group by to_char(x.UPDATE_DATE, 'YYYY-MM-DD'), t.update_date
20 order by 1
21 /

UPDATE_DAT COUNT
---------- ----------
2007-01-01 2
2007-01-02 0
2007-01-03 3
2007-01-04 1
2007-01-05 1

Tuesday, March 11, 2008

Oracle Triggers

CREATE OR REPLACE TRIGGER EBP.INSERT_EBP_TRADING_PARTNERS
BEFORE INSERT
ON EBP.EBP_TRADING_PARTNERS
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
tmpVar NUMBER;
v_fax_subject_line VARCHAR2(60);
BEGIN
tmpVar := 0;

SELECT SUBJECT_LINE INTO v_fax_subject_line FROM EBP_BILLERS WHERE BILLER_ID = :NEW.BILLER_ID;

IF :NEW.FAX_SUBJECT IS NULL THEN
:NEW.FAX_SUBJECT := v_fax_subject_line;
END IF;

EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('Warning: The Biller_Id does not exist in EBP_BILLERS table.');

END ;
/