Header Ads

Header ADS

Barcode Generate by SQL Query & Print On Oracle Apex

 Barcode Generate by SQL Query & Print On Oracle Apex

Topic Introduction: I will discuss Barcode Generate & Print On Oracle Apex in this tutorial. In my previous tutorial, I shared how to generate a barcode based on static value. If we think dynamically Barcode will create by SQL query value for this need to modify the code format. 


Here we will learn how to generate a barcode based on SQL query value and print out this barcode page.
follow step by step to make a barcode.





Barcode by SQL Query:


Barcode by SQL Query


This is an SQL query I have created for some demo data. You can use your own query using a database table. I will use this query on PL/SQL block for barcode generation.

SELECT 'EVTM-06' A, 'XL' B,'1599 BDT' C,'MADE IN BANGLADESH' D
FROM DUAL
UNION ALL
SELECT 'EVTM-06' A, 'XLL' B,'1599 BDT' C,'MADE IN BANGLADESH' D
FROM DUAL
UNION ALL
SELECT 'EVTM-06' A, 'L' B,'1599 BDT' C,'MADE IN BANGLADESH' D
FROM DUAL
UNION ALL
SELECT 'EVTM-06' A, 'M' B,'1599 BDT' C,'MADE IN BANGLADESH' D
FROM DUAL
UNION ALL
SELECT 'EVTM-06' A, 'S' B,'1599 BDT' C,'MADE IN BANGLADESH' D
FROM DUAL
  

1. Create a blank page
2. Take a Region
3. Create two-page items, one for Barcode value and another for Quantity which means how much Barcode Quantity will be generated.
4. Create a submit Button for barcode generation.
5. Create a subregion Region type that will be Dynamic Content and On PL/SQL code block past the PL/SQL Code.


DECLARE
    v_qty   NUMBER;
BEGIN
    HTP.p (
        '<input type="button1" class="t-Icon t-Icon--right fa fa-print" id="print" type="button" onclick="printdiv(''div_print1'');" value="print"/><br/><div id="div_print1" style="margin-top:5px;">');

    v_qty := NVL (:P2_QTY, 0);

    FOR i IN 1 .. v_qty
    LOOP
        FOR Y
            IN (SELECT 'EVTM-06'            A,
                       'XL'                 B,
                       '1599 BDT'           C,
                       'MADE IN BANGLADESH' D
                  FROM DUAL
                UNION ALL
                SELECT 'EVTM-06'            A,
                       'XLL'                B,
                       '1599 BDT'           C,
                       'MADE IN BANGLADESH' D
                  FROM DUAL
                UNION ALL
                SELECT 'EVTM-06'            A,
                       'L'                  B,
                       '1599 BDT'           C,
                       'MADE IN BANGLADESH' D
                  FROM DUAL
                UNION ALL
                SELECT 'EVTM-06'            A,
                       'M'                  B,
                       '1599 BDT'           C,
                       'MADE IN BANGLADESH' D
                  FROM DUAL
                UNION ALL
                SELECT 'EVTM-06'            A,
                       'S'                  B,
                       '1599 BDT'           C,
                       'MADE IN BANGLADESH' D
                  FROM DUAL)
        LOOP
            --htp.p('<img style= "height:80px;" src="https://barcode.tec-it.com/barcode.ashx?data='|| htf.escape_sc(y.B) ||'" alt="barcode"/>&nbsp;&nbsp;&nbsp;&nbsp;');

            HTP.p (
                   '

<tr>
<table>
<tr>
<td width="100%"  style="text-align:center;">
<img style= "height:80px;" src="https://barcode.tec-it.com/barcode.ashx?data='|| HTF.escape_sc (y.B)|| '" alt="barcode"/>&nbsp;&nbsp;&nbsp;&nbsp;
</b></td>
</tr>
<tr>
<td width="100%"  style="text-align:center;font-family: Roboto; font-size: 0.70rem;"><b>'|| y.A|| '</b></td>   
</tr>
<tr>
<td width="100%"  style="text-align:center;font-family: Roboto; font-size: 0.70rem;"><b>'|| y.c|| '</b></td>   
</tr>
<tr>
<td width="100%"  style="text-align:center;font-family: Roboto; font-size: 0.70rem;"><b>'|| y.d|| '</b></td>   
</tr>
</table>

</tr>

');
        END LOOP;
    END LOOP;

    HTP.p ('<div>');

    HTP.p ('</div>');
END;


Here Barcode Generate Complete.

6. Now if you want to Print this barcode region Add some code to the previous PL/SQL Block. Write this code on PL/SQL execution section after the Begin keyword. This code has already been given to the above PL/SQL block. No need to write or copy again.

Htp.p('<input type="button1" class="t-Icon t-Icon--right fa fa-print" id="print" type="button" onclick="printdiv(''div_print1'');" value="print"/><br/><div id="div_print1" style="margin-top:5px;">');

7. Write the Javascript code to the page properties Function and Global variable Declaration box

function printdiv(printpage)
{
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
var newstr = document.all.item(printpage).innerHTML;
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr+newstr+footstr;
window.print();
document.body.innerHTML = oldstr;
return false
}


No comments

Theme images by Deejpilot. Powered by Blogger.