Wednesday, August 28, 2024

Image view In BI Publisher Report In Oracle Apex

 1. First we need to create procedure which convert image to pdf. The procedure will like bellow.

CREATE OR REPLACE FUNCTION HRMS.PDF2IMAGE (p_blob IN BLOB)

   RETURN CLOB

IS

   l_clob   CLOB;

   l_step   PLS_INTEGER := 24573;--12000;

--        make sure you set a multiple of 3 not higher than 24573

BEGIN

   FOR i IN 0 .. TRUNC ( (DBMS_LOB.getlength (p_blob) - 1) / l_step)

   LOOP

      l_clob :=

            l_clob

         || UTL_RAW.cast_to_varchar2 (

               UTL_ENCODE.base64_encode (

                  DBMS_LOB.SUBSTR (p_blob, l_step, i * l_step + 1)));

   END LOOP;


   RETURN l_clob;

END;

2. We need to create sample query to bring data from database.

SELECT UNIQUE_ID, EMPLOYEE_NAME,

          (SELECT CODE_DESC

             FROM CODE_MASTER

            WHERE HARD_CODE = 'DSG' AND SOFT_CODE = DESIGNATION_CODE)

       || CHR (10)

       || (SELECT CODE_DESC FROM CODE_MASTER  WHERE HARD_CODE = 'CDV' 

         AND  SOFT_CODE = COMPANY_DIVISION_ID)

       || CHR (10)

       || 'ID: '

       || UNIQUE_ID

       || CHR (10)

       || 'Blood Group: '

       || (SELECT CODE_DESC

             FROM CODE_MASTER

            WHERE HARD_CODE = 'BLD' AND SOFT_CODE = BLOOD_GROUP)

          EMPLOYEE_DETAILS,

          'Date of Issue: '

       || TO_CHAR (SYSDATE, 'DD.MM.RRRR')

       || CHR (10)

       || 'Date of Expire: '

       || TO_CHAR (ADD_MONTHS (SYSDATE, 24), 'DD.MM.RRRR')

          ISSUE_DATE,

       PDF2IMAGE (PICTURE) PICTURE

  FROM EMPLOYEE_INFORMATION

 WHERE UNIQUE_ID =:P464_UNIQUE_ID;

3. In BI Publisher Image Filed Properties change with Following code

 <fo:instream-foreign-object content-type="image/jpg"  height="1.2  in" width="1  in" border="1  in" border-color="blue" >

<xsl:value-of select="PICTURE"/>

</fo:instream-foreign-object>.

4. Image Resize Procedure.

CREATE OR REPLACE PROCEDURE HRMS.RESIZE_IMAGE (P_UNIQUE_ID NUMBER)

IS

   V_PHOTO        BLOB;

   V_THUMD        BLOB;

   V_MIME_TYPE    VARCHAR2 (200);

   V_FILE_NAME    VARCHAR2 (300);

   V_IMAGE_SIZE   NUMBER;

   V_WIDTH        NUMBER := 360;

   V_HEIGHT       NUMBER := 410;

BEGIN

   SELECT TO_NUMBER (CEIL (SUM (DBMS_LOB.GetLength (picture) / 1024)))

     INTO V_IMAGE_SIZE

     FROM EMPLOYEE_INFORMATION

    WHERE UNIQUE_ID = P_UNIQUE_ID;


 IF V_IMAGE_SIZE > 20

   THEN

      SELECT PICTURE,

             PICTURE,

             MIME_TYPE,

             FILENAME

        INTO V_PHOTO,

             V_THUMD,

             V_MIME_TYPE,

             V_FILE_NAME

        FROM EMPLOYEE_INFORMATION

       WHERE UNIQUE_ID = P_UNIQUE_ID

      FOR UPDATE;


      -----------Scale The Image Size

      ORDSYS.ORDIMAGE.process (V_THUMD, 'maxScale=250 320');

      ORDSYS.ORDIMAGE.process (V_PHOTO,

                               'maxScale=' || V_WIDTH || ' ' || V_HEIGHT);


      UPDATE EMPLOYEE_INFORMATION

         SET PICTURE = V_PHOTO,

             MIME_TYPE = V_MIME_TYPE,

             FILENAME = V_FILE_NAME

       WHERE UNIQUE_ID = P_UNIQUE_ID;

   END IF;


   COMMIT;

END;

/



Tuesday, August 20, 2024

Copy Item Value From One Item to Another Item In Oracle Apex

 We can copy one apex items value to another apex items by using javascritp. The javascript code will be like this.

First need to creat Dynamic action on selected item. The action of Dynamic action will be Execute Javascript code.

var x = $v("P392_TAX_YEAR");   

 $s('P392_SECTION_ID', x);

The Execute options=> Fire on initialization will be no.

Monday, July 1, 2024

Oracle Database Interview Question

  1. DATA Doctionary Table:
    • USER_TAB_COLUMNS: All table names with column names and data types.
    • USER_CONSTRAINTS: Table’s constraints name.
    • USER_INDEXES: Table’s index name.
    • TTTT
  2. FUNCTION:
    • GREATEST(): This function will return the greatest value in a list of expressions.
    • LEAST(): This function will return the smallest value in a list of expressions.
    • YYYYYYYYYY
  3. Linewise Total Calculation: Using Analytical Functions, we can achieve this. SELECT EMPLOYEE_ID,SALARY,SUM(SALARY) OVER (ORDER BY EMPLOYEE_ID) LINE_TOTAL FROM EMPLOYEES.
  4. Modify the order of columns without dropping the table: ALTER TABLE EMPLOYEES_TEST MODIFY MANAGER_ID INVISIBLE; Alter TABLE EMPLOYEES_TEST MODIFY MANAGER_ID VISIBLE;
  5. Suppose we open and start working on a cursor, and in between some records were deleted by another user from the table. Are we still able to see all the selected rows of the cursor? Answer: Yes, we are able to see all the records that are selected in the cursor, because when we open a cursor, then it will load all data into memory, and data will be viewed from memory, not the base table. But if we operate any DML operation using cursor data, then the DML operation will fail because related data will not be available on the base table. We can also prevent DML operations during cursor execution by using the For Update clause within the cursor declaration.

  6. Private Procedure Or Private Function: A private procedure or function is only defined within the package body, and no one will be able to access it. Only other package objects will be able to use this type of procedure or function. 

  7. What is Pragma: Prgama is a precompiler directive to instruct the compiler to compile the program unit differently for a specific functionality at the runtime. List of pragma available in Oracle (based on 18C): AUTONOMOUS_TRANSACTION,COVERAGE,DEPRECATE,EXCEPTION_INIT,INLINE,RESTRICT_REFERENCES,SERIALLY_REUSABLE,UDF.
  8. Table Level & Column Level Constraints: When we define a constraint in the column definition, then it will be column-level constraints, and when we define a constraint in the table level, then it will be table-level constraints. Composite constraints are now allowed in column-level constraints.
  9. DELETE command will be fired by DML trigger, but Truncate command will not be fired by DML trigger. The Truncate command will be fired by DDL trigger. DDL trigger will be created on schema level, and we can specify it for specific tables by using the ORA_DICT_OBJ_NAME & ORA_DICT_OBJECT_TYPE function. The syntex will be:

    CREATE OR REPLACE TRIGGER T_TRUNCATE_TRG
    BEFORE TRUNCATE ON SCHEMA
    BEGIN
    IF ORA_DICT_OBJ_NAME ='Table_name' and ORA_DICT_OBJECT_TYPE ='TABLE THEN
    RAISE_APPLICATION_ERROR(-20001,'Truncation not allowed on Tables');
    END IF;
    END;
  10. Hierarcial Query:
    SELECT FIRST_NAME, LAST_NAME, SYS_CONNECT_BY_PATH(LAST_NAME,'->') PATH, LEVEL,CONNECT_BY_ISLEAF FROM EMPLOYEES START WITH MANAGER_ID IS NULL CONNECT BY PRIOR EMPLOYEE_ID=MANAGER_ID
  11. Different between Delete, Truncate, & Drop.
    Delete: Delete is a DML operation, and we can delete partial data by using the where clause. Deleted data can be recovered by using rollback. No impact on dependent object. This command is slower because it uses an undo segment, and triggers will get fired (on delete trigger). Deleted data is temporarily stored in the redo log.
    Truncate: Truncate is a DDL (autocommit) operation. All rows will be removed and we cannot use the where clause. Data lost forever and no impact-dependent object. The truncate command is faster, and no trigger will get invoked.
    Drop: DDL Command and removes the dependent object. Data can be recovered if the flashback option is on. A dependent object will have to be created. 
  12. What is implicit cursor? Answer: An implicit cursois a session cursor that is constructed and managed by Oracle. PL/SQL opens an implicit cursor every time when we run a SELECT or DML statement. We cannot control implicit cursor, but we can get information from its attributes.
    An explicit cursor is a session cursor that is constructed and managed by the user.
    Cursor Attributes are ISOPEN,FOUND,NOTFOUND,ROWCOUNT
  13. What is bulk bind?
    Answer: The PL/SQL engine executes all the procedural code, and the SQL engine will execute all the SQL statements. Assigning values to PL/SQL variables that appear in SQL statements is called binding.
    Bulk binding is a process in which instead of doing the binding one by one because of CONTEXT SWITCHING, the entire information from the SQL statement will be binded back to the PL/SQL variable either with a single switch or with fewer switches, and this concept is called bulk binding.
    Bulk binding binds an entire collection of values at once. To implement bulk binding, Oracle provides two statements. One is called a FORALL statement, and another is called a BULK collection clause.
  14. What is sort merge join? 
    Answer: A sort-merge join is a join algorithm used in Oracle to combine data from two tables based on a common join key. It's a variation of a nested loop join. 
  15. What is trigger?
  16. What is materialised view? can we use materialized view without materialized view log?
  17. In which case can we use Pragma Autonomous transactions?
  18. What is a save exception?
    Answer: Save Exception used in FORALL statement. Using Save Exception PL/SQL does not raise an exception; instead, it saves information about the failure. After the FORALL statement is complete, PL/SQL raises a single exception for the FORALL statement.
  19. What is Dynamic SQL? Using EXECUTE IMMEDIATE, we can use dynamic SQL.
  20. When do we use ref Cursor?
  21. What is the virtual column and syntax for that column?
  22. What is the difference between a nested array and a V-array?
  23. Did DML operations allow in materialised view?
    Answer: Users can perform DML operations on a writeable materialised view, but if we refresh the materialised view, then these changes are not pushed back to the master and the changes are lost in the materialised view itself.

 

Monday, April 29, 2024

Protect Restfull API with Basic Authentication

 1. Create new module from Restfull service.



2. Create Template..

3. Create Authentication User from ==> Manage Users & Group ==> Create User
   


4. From Privilage Create New privilage.

 
Now API is protected and when we want to call API then we need to use Basic Authentication.
 




Image File store outside of Oracle Database and show image into Apex Application

Directory Create : grant execute on utl_file to HRMS; CREATE OR REPLACE DIRECTORY STOCK_DIRECTORY AS 'C:\Program Files (x86)\Apache Sof...