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!

Inserting comma separated string value passed from UI into oracle table column as mapped comma separ

SB2011Feb 25 2014 — edited Feb 25 2014

Hi,

>select banner from v$version;

Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production

PL/SQL Release 11.1.0.7.0 - Production

CORE     11.1.0.7.0             Production

TNS for Linux: Version 11.1.0.7.0 - Production

NLSRTL Version 11.1.0.7.0 - Production

I have  the following requirement.

From UI if the user is saving ,multiple records  are getting saved into the data base table for a candidate sb_no value.In UI the OS values are comma separated osnames ex,HP Unix,Solaris,Linux but when I have to save it in DB I have to save comma separated id values like 12,26,17 by mapping the osnames with the oses table.Similarly for Lang column.Here the constraint is I cannot fetch the records directly into temp table because the comma separated osname values from UI could exceed 4000 byte which is the maximum size of varchar2 column in DB.That is why the requirement is to convert into comma separated ids and save it in DB column.

The 3 DB table has the following structure:

create table a_main

  (ID NUMBER,

   sb_no VARCHAR2(30),

   Pc_NUMBER VARCHAR2(30),

   PC_FLAG CHAR(1),

   INlON_ord NUMBER,

   SP_OR_LATER_VSN CHAR(1),

   OS VARCHAR2(4000),

   LANG VARCHAR2(4000)

    );

Ex:

In UI For SB_NO=SWB1

'SWB0','P',1,'S','UNIX,SOLARIS,LINUX','ENGLISH,FRENCH,GERMAN'--record 1

'SWB2','P',3,'S','HP UNIX,SOLARIS,LINUX','ENGLISH,USA ENGLISH'---record 2

'SWB3','P',2,'S','DOS,SOLARIS,LINUX','GERMAN,FRENCH'---record 3

Then in DB it will be save as follows( os and lang column are comma separated id values):

idSB_NOPc_NUMBERPC_FLAGINlON_ordSP_OR_LATER_VSNOSLANG
seq.nextvalSWB1SWB0P1S11,12,56,128(CORRESPONDING ID VALUES OF OS)SAME AS  OS COLUMN
seq.nextvalSWB1SWB3P2S45,78,96,23
seq.nextvalSWB1SWB2P3S22,45,60

structure of oses and lang table are as follows:

CREATE TABLE oses(

  OSCD                 VARCHAR2(10 BYTE),

     ID                     NUMBER                 DEFAULT NULL,

  AG_OSCD          VARCHAR2(250 BYTE),

);

insert into oses

values('HUX',12,'HP UNIX');

insert into oses

values('SUX',26,'SOLARIS');

insert into oses

values('LUX',17,'LINUX');

CREATE TABLE langs

(

  LANGCD       CHAR(2 BYTE),

  LANGNM       VARCHAR2(255 BYTE),

     ID                 NUMBER    NOT NULL

);

insert into langs

values('ENG','UK ENGLISH',35);

insert into langs

values('UEG','USA ENGLISH',27);

insert into langs

values('FR','FRENCH',45);

Can anyone please help me.

Thanks in advance.

Regards,

SB2011

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 25 2014
Added on Feb 25 2014
1 comment
1,555 views