Forum Discussion

Szymon's avatar
Szymon
New Contributor II
5 years ago
Solved

Oracle Insert - multiple rows in transaction possible?

Hi,

How to insert multiple rows at a time into Oracle table within one transaction?
Example:
Reading 10 lines from CSV/Excel file.
Insert 10 lines into Oracle using Oracle insert.
When one of the lines throws an error, none of the lines shall be written.
A classical rollback mechanism.
How to do that?

kind regards
Simon

  • Hello lake,

    You can iterate through one of the arrays using either map or filter (depends on what you want as an output) and check if the current element is present in the second array.

    Example input:

    [
    	{
    		"arr1": [
    			1,
    			2,
    			3,
    			4,
    			5,
    			6
    		],
    		"arr2": [
    			3,
    			4,
    			5,
    			6,
    			7,
    			8
    		]
    	}
    ]

    Using map:

    $arr1.map(x => {"elem": x,"found": $arr2.indexOf(x) != -1})
    "compare": [
    			{
    				"elem": 1,
    				"found": false
    			},
    			{
    				"elem": 2,
    				"found": false
    			},
    			{
    				"elem": 3,
    				"found": true
    			},
    			{
    				"elem": 4,
    				"found": true
    			},
    			{
    				"elem": 5,
    				"found": true
    			},
    			{
    				"elem": 6,
    				"found": true
    			}

    Using filter:

    $arr1.filter(x => $arr2.indexOf(x) != -1)
    "present": [
    			3,
    			4,
    			5,
    			6
    		]

    You can refer to the attached pipeline and let me know if it helps you.

    Regards,

    Aleksandar.

     

4 Replies

  • Hello lake,

    You can iterate through one of the arrays using either map or filter (depends on what you want as an output) and check if the current element is present in the second array.

    Example input:

    [
    	{
    		"arr1": [
    			1,
    			2,
    			3,
    			4,
    			5,
    			6
    		],
    		"arr2": [
    			3,
    			4,
    			5,
    			6,
    			7,
    			8
    		]
    	}
    ]

    Using map:

    $arr1.map(x => {"elem": x,"found": $arr2.indexOf(x) != -1})
    "compare": [
    			{
    				"elem": 1,
    				"found": false
    			},
    			{
    				"elem": 2,
    				"found": false
    			},
    			{
    				"elem": 3,
    				"found": true
    			},
    			{
    				"elem": 4,
    				"found": true
    			},
    			{
    				"elem": 5,
    				"found": true
    			},
    			{
    				"elem": 6,
    				"found": true
    			}

    Using filter:

    $arr1.filter(x => $arr2.indexOf(x) != -1)
    "present": [
    			3,
    			4,
    			5,
    			6
    		]

    You can refer to the attached pipeline and let me know if it helps you.

    Regards,

    Aleksandar.