Skip to content
Advertisement

Procedure For Get String And insert , In Oracle [closed]

I Have Two Tables
first :

Second:

How Write Procedure for Insert Into Second Table By String ,With This Conditions :
1- Example Of input String : nam1;fam1,nam2;fam2 => nam1 Insert Into NAME Column And fam1 Into FAMILY
2-ID Generated By Trigger I Have Writed Before
3-NAME_ID Comes From FIRST table

Advertisement

Answer

With a table you previously created (I remember that question so I reused it, as well as the sequence), you’d split input string into rows and fetch names, somehow; I chose regular expressions, presuming that names consist of only one word.

Table with names (inserted previously):

Procedure expects that strings you’re passing as parameters contain name which is already inserted into the z_names table.

Testing:


However, from my point of view, that’s somewhat awkward approach. I don’t know what tables you use in this exercise represent, but I’d expect them to be related to each other (via referential integrity constraint). It also means that z_fname most probably isn’t normalized – you would store only the foreign key constraint value which points to the master table (z_names), not store both name AND id.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement