Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Full Text Search

Maestro_VineetDec 3 2017 — edited Dec 4 2017

Hi

I am using  Oracle Database 11g Release 2: 11.2.0.1.

I am having two different table and the requirement is to find the match for a value stored in a column named 'Pur_Order_Id',of a PUR_ORDR_ITEM table.

Structure of the two tables is listed below.

1) PUR_ORDR_ITEM

Create Table VIN.PUR_ORDR_ITEM (

"Pur_Order_Id" VARCHAR(64) NOT NULL,
         "PUR_ORDER_ITEM_ID" VARCHAR(64) NOT NULL,
          "MTRL_ID" VARCHAR(64),
         "SITE_ID" VARCHAR(64),
         "PROJ_ID" VARCHAR(64),
          "QTY" NUMBER(17 , 2)

)

2) TRANSPT_INVOICE_ITEM

CREATE TABLE "VIN"."TRANSPT_INVOICE_ITEM" (

         "TRANSPT_INVOICE_ID" VARCHAR(64) NOT NULL,

         "TRANSPT_INVOICE_ITM_ID" VARCHAR(64) NOT NULL,

         "CNSGNMNT_NOTE_ID" VARCHAR(64),

         "INVC_ITEM_REF_1" VARCHAR(255),

         "INVC_ITEM_REF_2" VARCHAR(255),

         "TRANS_DT" Date,

         "QTY" NUMBER(12 , 2),

         "TOT_AMT" NUMBERL(12 , 2)

        )

Problem is that i need to find out the records where PUR_ORDR_ITEM.Pur_Order_Id is either equal to  TRANSPT_INVOICE_ITEM.INVC_ITEM_REF_1 or TRANSPT_INVOICE_ITEM.INVC_ITEM_REF_2,this sound pretty simple but there is twist to it.And i am struggling to resolve that twist.

The twist is,column named INVC_ITEM_REF_1 and INVC_ITEM_REF_2 contains value which might be exactly equal to the Pur_Order_id and again these columns  also contains values with additional characters either prefixed or suffixed to the Pur_Order_Id.

For example the PUR_ORDR_ITEM table is having below rows.

            

PRCHS_ORDR_IDPRCHS_ORDR_ITM_IDMATRL_IDSITE_IDPROJ_IDQTY
505882961 Z2NULL1
5076269119600138DC13NULL150
50821735191101537Z2NULL1
50773559190400047Z2A46029557-0A26091
50821735391101540Z2NULL1
50775801190400009Z2A46029557-0A4850
508442941 Z24100067389500
50810561155000484VOIVNULL13000
50821735291101539Z2NULL1
50846780118790255Z24100067401

TRANSPT_INVOICE_ITEM table is having following rows.

TRANSPT_INVOICE_IDTRANSPT_INVOICE_ITM_IDCNSGNMNT_NOTE_IDINVC_ITEM_REF_1INVC_ITEM_REF_2TRANS_DTQTYTOT_AMT
CEVA_TRANSPT_20141201134WEB015220420CCUWCM/973000/14878012014-12-012178.81
CEVA_TRANSPT_201607082578WEB019560090CCA27M/8610011488256/981505882962016-07-08134.50
CEVA_TRANSPT_201703051139WEB017061090OMAG04/J73000  9050821735/1594661 2017-03-05318.75
CEVA_TRANSPT_201703087546

  ENP012504542

CCQSME/5757009507626912017-03-084410.00
CEVA_TRANSPT_201703103039NLP665479871CQ50821737/CDX561508217352017-03-102165.75
CEVA_TRANSPT_201704128546VXZ34598WZ89COP631/858108507735592017-04-126205.10
CEVA_TRANSPT_201704167677BAC749432409NEPVC1/858109508217362017-04-16117.80
CEVA_TRANSPT_201705127878RIC015606163GCOAD1/858110507758012017-05-12355.50
CEVA_TRANSPT_201706184004CRB764505222ESG010/858111508442942017-06-18251.10
CEVA_TRANSPT_201708102189GEO856344576CBP716/858112508105612017-08-104210.35
CEVA_TRANSPT_2017091124RIC161610635ISAP10/85811300141380028MF9F2017-09-116760.80
CEVA_TRANSPT_201710107788EPN549016610VXW778/85811400141380028SJ0D2017-10-10216.70

Expected/Desired output.

TRANSPT_INVOICE_IDTRANSPT_INVOICE_ITM_IDCNSGNMNT_NOTE_IDINVC_ITEM_REF_1INVC_ITEM_REF_2Trans_DtQTYTot_AMT
CEVA_TRANSPT_201607082578WEB019560090Null505882962016-07-08134.50
CEVA_TRANSPT_201703087546ENP012504542Null507626912017-03-184410.00
CEVA_TRANSPT_201703103039NLP66547987150821737508217352017-03-102165.75
CEVA_TRANSPT_201704128546VXZ34598WZ89Null507735592017-04-126205.10
CEVA_TRANSPT_201704167677BAC749432409Null508217362017-04-16117.80
CEVA_TRANSPT_201705127878RIC015606163Null507758012017-05-12355.50
CEVA_TRANSPT_201706184004CRB764505222Null508442942017-06-18251.10
CEVA_TRANSPT_201708102189GEO856344576Null508105612017-08-104210.35

Seek your guidance to get this desired output.

Ideally with the LIKE function we can address this issue but it will require me to write the statement N number of times,i am looking for a feasible solution either in the form of  a sql statement or Stored Procedure.

Any sort of help is highly appreciated.

Cheers

Vinny

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 1 2018
Added on Dec 3 2017
2 comments
205 views