10 Ağustos 2008 Pazar

Google Syntax Highlighter for PL/SQL

Google Syntax Highlighter App. provides us to show code in our blogs or other html pages. This application shows code of C,Java,Jscript,C#,SQL,XML,Ruby,Phyton. But as you predicted, Oracle PL/SQL is missing. So, i decided to develop a code to highlight our Oracle/PLSQL code. Things you have to do them are as follows :

  • Download the Google Syntaxlighter to your pc: http://code.google.com/p/syntaxhighlighter/
  • Then upload the folder that is extracted from zip file, to your server.
  • For blogger, go to your template page and edit.
  • After first head tag and before the closed head tag you should write some javascript code to template page.
  • The template page should look alike this page :

    <link type="text/css" rel="stylesheet" href="http://xxx.googlepages.com/SyntaxHighlighter.css"></link>

    <script language="javascript" src="http://xxx.googlepages.com/shCore.js"></script>

    <script language="javascript" src="http://xxx.googlepages.com/shPlsql.js"></script>

    ....

    ....

    ....

    // dont modify if you dont want to change template except to show coding

    ....

    <script language="javascript">

    window.onload = function () {

    dp.SyntaxHighlighter.ClipboardSwf = 'http://afsungur.googlepages.com/clipboard.swf';



    dp.SyntaxHighlighter.BloggerMode();



    dp.SyntaxHighlighter.HighlightAll('code');

    }

    </script>


  • Then writing a post, you should write your pl sql code as follows:
    <pre name="code" class="plsql">



    ... your pl sql code ...



    </pre>



Download shBrushPlSql.js

(This is compatible with reserver words and keywords of Oracle Latest Version )

After all of these step, now you can test your plsql code. Like this :)


CREATE OR REPLACE PACKAGE BODY PKG_RULE_CONTROL IS

-- CREATED BY A. FUAT SUNGUR
-- afsungur@gmail.com
--
--
-- Kural ile ilgili islemleri gerceklestiren pakettir

------------------------------------------------------------------------------------------
-- DBMS_SCHEDULER tarafindan cagrilacak pl sql blogunun dinamik olarak uretilmesini saglar
-- RUN_JOB prosedurune gonderilecek parametreler dinamik olarak ayarlanir.
FUNCTION PRODUCE_JOB_SQL
(
vExpr_1 VARCHAR2,
vExpr_2 VARCHAR2,
nCond_Id NUMBER,
iRuleId NUMBER
) RETURN VARCHAR2 IS

vJobSql VARCHAR2(2000);
iSqlCode INTEGER;
vSqlErrMsg VARCHAR2(250);

BEGIN
-- CHR(39) = ' ( tek tirnak )
IF (vExpr_2 IS NOT NULL)
THEN
vJobSql := 'BEGIN PKG_JOB_CONTROL.RUN_JOB(' || CHR(39) ||
vExpr_1 || CHR(39) || ',' || CHR(39) || VExpr_2 ||
CHR(39) || ',' || nCond_Id || ',' || iRuleId ||
'); END;';
ELSE
vJobSql := 'BEGIN PKG_JOB_CONTROL.RUN_JOB(' || CHR(39) ||
vExpr_1 || CHR(39) || ',NULL,' || nCond_Id || ',' ||
iRuleId || '); END;';
END IF;
RETURN vJobSql;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
INSERT INTO TERRORS
VALUES
(SEQ_TERRORS.NEXTVAL,
iSqlCode,
vSqlErrMsg,
CURRENT_TIMESTAMP,
'FUNCTION PKG_RULE_CONTROL.PRODUCE_JOB_SQL()');
COMMIT;
RETURN NULL;
END;
END;

Hiç yorum yok:

Yorum Gönder