SELECT LPAD (MONTH, 20 – (20 – LENGTH (MONTH)) / 2) MONTH, “Sun”, “Mon”,
“Tue”, “Wed”, “Thu”, “Fri”, “Sat”
FROM (SELECT TO_CHAR (dt, ‘fmMonthfm YYYY’) MONTH,
TO_CHAR (dt + 1, ‘iw’) week,
MAX (DECODE (TO_CHAR (dt, ‘d’),
‘1’, LPAD (TO_CHAR (dt, ‘fmdd’), 2)
)
) “Sun”,
MAX (DECODE (TO_CHAR (dt, ‘d’),
‘2’, LPAD (TO_CHAR (dt, ‘fmdd’), 2)
)
) “Mon”,
MAX (DECODE (TO_CHAR (dt, ‘d’),
‘3’, LPAD (TO_CHAR (dt, ‘fmdd’), 2)
)
) “Tue”,
MAX (DECODE (TO_CHAR (dt, ‘d’),
‘4’, LPAD (TO_CHAR (dt, ‘fmdd’), 2)
)
) “Wed”,
MAX (DECODE (TO_CHAR (dt, ‘d’),
‘5’, LPAD (TO_CHAR (dt, ‘fmdd’), 2)
)
) “Thu”,
MAX (DECODE (TO_CHAR (dt, ‘d’),
‘6’, LPAD (TO_CHAR (dt, ‘fmdd’), 2)
)
) “Fri”,
MAX (DECODE (TO_CHAR (dt, ‘d’),
‘7’, LPAD (TO_CHAR (dt, ‘fmdd’), 2)
)
) “Sat”
FROM (SELECT TRUNC (SYSDATE, ‘y’) – 1 + ROWNUM dt
FROM all_objects
WHERE ROWNUM <= ADD_MONTHS (TRUNC (SYSDATE, ‘y’), 12) – TRUNC (SYSDATE, ‘y’)) GROUP BY TO_CHAR (dt, ‘fmMonthfm YYYY’), TO_CHAR (dt + 1, ‘iw’))
ORDER BY TO_DATE (MONTH, ‘Month YYYY’), TO_NUMBER (week)
You have a purchase order and you have a requisition, but wait how do you know how this purchase order is linked with requisition. Here is the query thats answers this. Use this query find linked Purchase order and Requisition.

This could be really a helpful one.

SELECT prh.segment1 req_number
      ,prh.authorization_status
      ,prl.line_num req_line_num
      ,prl.item_description req_item_description
      ,prl.unit_price req_unit_price
      ,prl.quantity req_quantity
      ,pd.req_header_reference_num
      ,pd.req_line_reference_num
      ,pl.line_num
      ,pl.item_description
      ,pl.quantity
      ,pl.amount
      ,ph.segment1 po_number
      ,prd.distribution_id
      ,pd.req_distribution_id
  FROM po_requisition_headers_all prh
      ,po_requisition_lines_all   prl
      ,po_req_distributions_all   prd
      ,po_distributions_all       pd
      ,po_line_locations_all      pll
      ,po_lines_all           pl
      ,po_headers_all             ph
 WHERE prh.requisition_header_id = prl.requisition_header_id
   and prh.org_id = prl.org_id
   and prl.requisition_line_id = prd.requisition_line_id
   and prl.org_id = prd.org_id
   and prd.distribution_id = pd.req_distribution_id(+)
   and prd.org_id = pd.org_id(+)
   and pd.line_location_id = pll.line_location_id(+)
   and pd.org_id = pll.org_id(+)
   and pll.po_line_id = pl.po_line_id(+)
   and pll.org_id = pl.org_id(+)
   and pl.po_header_id = ph.po_header_id(+)
   and pl.org_id = ph.org_id(+)

Based on a request from one of the reader here is the query which he was looking for.

He needed query that can list all the responsibilities attached to a user.

select fu.user_name, fr.responsibility_name, furg.START_DATE, furg.END_DATE
from fnd_user_resp_groups_direct furg, fnd_user fu, fnd_responsibility_tl fr
where fu.user_user_name = :user_name
and furg.user_id = fu.user_id
and furg.responsibility_id = fr.responsibility_id
and fr.language = userenv(‘LANG’)

Here we will discuss how to insert BLOB file in the database. For this we will create a table and then a procedure that will be used to insert records in the table.

Use following script to create an employee table

CREATE TABLE SV_EMP_PHOTO
(
  ID          NUMBER(3) NOT NULL,
  PHOTO_NAME  VARCHAR2(40),
  PHOTO_RAW   BLOB,
  EMP_NAME    VARCHAR2(80)
)

Create a directory where the photos will be stored. I am creating a directory in UNIX as our database is created in UNIX.

Create directory SV_PHOTO_DIR as ‘/u002/app/applmgr/empphoto’

Script to create a procedure SV_LOAD_IMAGE that will insert records in the table.

CREATE OR REPLACE PROCEDURE sv_load_image (
   p_id                NUMBER
 , p_emp_name     IN   VARCHAR2
 , p_photo_name   IN   VARCHAR2
)
IS
   l_source   BFILE;
   l_dest     BLOB;
   l_length   BINARY_INTEGER;
BEGIN
   l_source := BFILENAME (‘SV_PHOTO_DIR’, p_photo_name);

   INSERT INTO sv_emp_photo
               (ID
              , photo_name
              , emp_name
              , photo_raw
               )
   VALUES      (p_id
              , p_photo_name
              , p_emp_name
              , EMPTY_BLOB ()
               )
   RETURNING   photo_raw
   INTO        l_dest;

   — lock record
   SELECT     photo_raw
   INTO       l_dest
   FROM       sv_emp_photo
   WHERE      ID = p_id AND photo_name = p_photo_name
   FOR UPDATE;

   — open the file
   DBMS_LOB.fileopen (l_source, DBMS_LOB.file_readonly);
   — get length
   l_length := DBMS_LOB.getlength (l_source);
   — read the file and store in the destination
   DBMS_LOB.loadfromfile (l_dest, l_source, l_length);

   — update the blob field with destination
   UPDATE sv_emp_photo
   SET photo_raw = l_dest
   WHERE  ID = p_id AND photo_name = p_photo_name;

   — close file
   DBMS_LOB.fileclose (l_source);
END –sv_load_image;
/
I have copied few .jpg images in /u002/app/applmgr/empphoto in UNIX.
Execute the procedure as follows to create record in database

exec sv_load_image(1,’Pavki’,’one.jpg’)
exec sv_load_image(2,’Suresh’,’two.jpg’)
exec sv_load_image(3,’Rachna’,’three.jpg’)

From your command prompt, type
sqlplus “/ as sysdba”

Once logged in as SYSDBA, you need to unlock the scott account
SQL> alter user scott account unlock;
SQL> grant connect, resource to scott;