PHPackages                             yajra/laravel-sql-loader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. yajra/laravel-sql-loader

ActiveLibrary[Database &amp; ORM](/categories/database)

yajra/laravel-sql-loader
========================

Oracle SQL Loader for Laravel

v1.9.0(3mo ago)94.6k—5.3%5[1 PRs](https://github.com/yajra/laravel-sql-loader/pulls)MITPHPPHP ^8.2CI passing

Since May 30Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/yajra/laravel-sql-loader)[ Packagist](https://packagist.org/packages/yajra/laravel-sql-loader)[ Fund](https://www.paypal.me/yajra)[ GitHub Sponsors](https://github.com/yajra)[ RSS](/packages/yajra-laravel-sql-loader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (21)Used By (0)

Oracle SQL\*Loader for Laravel
==============================

[](#oracle-sqlloader-for-laravel)

[![Continuous Integration](https://github.com/yajra/laravel-sql-loader/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/yajra/laravel-sql-loader/actions/workflows/continuous-integration.yml)[![Static Analysis](https://github.com/yajra/laravel-sql-loader/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/yajra/laravel-sql-loader/actions/workflows/static-analysis.yml)[![Latest Stable Version](https://camo.githubusercontent.com/85dcb3c61e32dbb861c897e155822c8ab26190b29ee058033f807ebcd4122c82/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79616a72612f6c61726176656c2d73716c2d6c6f616465722e737667)](https://packagist.org/packages/yajra/laravel-sql-loader)[![Total Downloads](https://camo.githubusercontent.com/0d325f612adcc8af731f23ba1c5eef1edd087d0b5a1eb808789f6372e4437edf/68747470733a2f2f706f7365722e707567782e6f72672f79616a72612f6c61726176656c2d73716c2d6c6f616465722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/yajra/laravel-sql-loader)[![License](https://camo.githubusercontent.com/850eae1099d2b05f53383473d7cd51f9bc1ab09b7d0d9e5122f1dd930efdcc6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6173686170652f6170697374617475732e737667)](https://packagist.org/packages/yajra/laravel-sql-loader)

A Laravel package that allows you to easily load data into Oracle database using `sqlldr`.

Requirements
------------

[](#requirements)

- [Oracle Instant Client with Tools Package](https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html)
- [Laravel 10.x](https://laravel.com) or higher
- [Laravel OCI8](https://yajrabox.com/docs/laravel-oci8) 10.x or higher

Prerequisites
-------------

[](#prerequisites)

- Before you can use this package, you need to install the Oracle Instant Client with Tools Package. You can download the package from the [Oracle website](https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html).
- You should also take note of the path where the `sqlldr` executable is located.
    - For example, if you installed the Oracle Instant Client with Tools Package in `/usr/local/oracle/instantclient_19_6`, the `sqlldr` executable will be located in `/usr/local/oracle/instantclient_19_6/sqlldr`.
    - You can also add the path to the `sqlldr` executable to your system's PATH environment variable.
    - You can also set the path to the `sqlldr` executable in the `.env` file using the `SQL_LOADER_PATH` key.
    - You can also set the path to the `sqlldr` executable in the `config/sql-loader.php` file using the `sqlldr` key.
    - You can symlink the `sqlldr` executable to `/usr/local/bin` using the following command: ```
        sudo ln -nfs /usr/local/oracle/instantclient_19_6/sqlldr /usr/local/bin/sqlldr
        ```
- Knowledge of how to use `sqlldr` is also required. You can read the documentation [here](https://docs.oracle.com/en/database/oracle/oracle-database/23/sutil/oracle-sql-loader.html#GUID-8D037494-07FA-4226-B507-E1B2ED10C144).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require yajra/laravel-sql-loader:^1.0
```

Quick Start
-----------

[](#quick-start)

Below is a quick example of how to use the package:

```
Route::get('sql-loader', function () {
    Schema::dropIfExists('employees');
    Schema::create('employees', function ($table) {
        $table->id();
        $table->string('name');
        $table->integer('dept_id');
        $table->timestamps();
    });

    Yajra\SQLLoader\CsvFile::make(database_path('files/employees.csv'), 'w')
        ->headers(['name', 'dept_id', 'created_at', 'updated_at'])
        ->insert([
            ['John Doe', 1, now(), now()],
            ['Jane Doe', 2, now(), now()],
            ['John Doe', 1, now(), now()],
            ['Jane Doe', 2, now(), now()],
        ])
        ->close();

    $loader = Yajra\SQLLoader\SQLLoader::make();
    $loader->inFile(database_path('files/employees.csv'))
        ->dateFormat('YYYY-MM-DD HH24:MI:SS')
        ->withHeaders()
        ->into('employees')
        ->execute();

    return DB::table('employees')->get();
});
```

Execution Mode
--------------

[](#execution-mode)

The default execution mode is `Mode::APPEND`. The package supports the following execution mode:

- `Yajra\SQLLoader\Mode::INSERT` - Insert data into table.
- `Yajra\SQLLoader\Mode::APPEND` - Append data to table.
- `Yajra\SQLLoader\Mode::REPLACE` - Replace data in table.
- `Yajra\SQLLoader\Mode::TRUNCATE` - Truncate table then insert data.

Date Formats
------------

[](#date-formats)

The SQL\*Loader default date format is `YYYY-MM-DD"T"HH24:MI:SS."000000Z"` to match Laravel's model date serialization. You can change the date format using the `dateFormat` method.

```
$loader->dateFormat('YYYY-MM-DD HH24:MI:SS');
```

Available Methods
-----------------

[](#available-methods)

### Options

[](#options)

You can pass additional options to the `sqlldr` command using the `options` method.

```
$loader->options(['skip=1', 'load=1000']);
```

### Input File(/s)

[](#input-files)

You can set the input file to use for the SQL\*Loader command using the `inFile` method.

```
$loader->inFile(database_path('files/employees.csv'));
```

You can also set multiple input files.

```
$loader->inFile(database_path('files/employees.csv'))
    ->inFile(database_path('files/departments.csv')),
```

### Mode

[](#mode)

You can set the execution mode using the `mode` method.

```
$loader->mode(Yajra\SQLLoader\Mode::TRUNCATE);
```

### Into Table

[](#into-table)

You can set the table to load the data into using the `into` method. This method accepts the following parameters:

- [`table`](https://docs.oracle.com/en/database/oracle/oracle-database/23/sutil/oracle-sql-loader-control-file-contents.html#GUID-9E95D9E3-C554-495C-9400-A0B0840DCF35) - Specifies the table into which you load data.
- [`columns`](https://docs.oracle.com/en/database/oracle/oracle-database/23/sutil/oracle-sql-loader-field-list-contents.html#GUID-46A9380D-3BFD-49E4-9DD5-0AC5785A6DB9) - The field-list portion of a SQL\*Loader control file provides information about fields being loaded.
- [`terminatedBy`](https://docs.oracle.com/en/database/oracle/oracle-database/23/sutil/oracle-sql-loader-control-file-contents.html#GUID-D1762699-8154-40F6-90DE-EFB8EB6A9AB0) - The terminated by character.
- [`enclosedBy`](https://docs.oracle.com/en/database/oracle/oracle-database/23/sutil/oracle-sql-loader-control-file-contents.html#GUID-D1762699-8154-40F6-90DE-EFB8EB6A9AB0) - The enclosed by character.
- [`trailing`](https://docs.oracle.com/en/database/oracle/oracle-database/23/sutil/oracle-sql-loader-control-file-contents.html#GUID-717EBE8E-C972-4D2C-9E42-16440CF069AA) - set to `true` to configure SQL\*Loader to treat missing columns as null columns.
- [`formatOptions`](https://docs.oracle.com/en/database/oracle/oracle-database/23/sutil/oracle-sql-loader-control-file-contents.html#GUID-5740B2F9-C5C3-4D44-BB3F-81484417F02D) - Specifying Datetime Formats At the Table Level.
- [`when`](https://docs.oracle.com/en/database/oracle/oracle-database/23/sutil/oracle-sql-loader-control-file-contents.html#GUID-227B995D-72A8-42EE-ADD9-350B8A229495) - Specifies a WHEN clause that is applied to all data records read from the data file.

```
$loader->into('employees', ['name', 'dept_id']);
```

### With Headers

[](#with-headers)

Using `withHeaders` will skip the first row of the CSV file.

Important

1. `withHeaders` must be called before the `into` method.
2. This method assumes that the headers are the same as the table columns.
3. Non-existent columns will be flagged as `FILLER`.
4. Date headers will be automatically detected and data type is appended in the control file.
5. Date values must follow the default date format. If not, use the `dateFormat` method.
6. If the headers are different from the table columns, you should define the `columns` in the `into` method.

#### Building a CSV File from Eloquent Collection

[](#building-a-csv-file-from-eloquent-collection)

```
$users = User::all();
Yajra\SQLLoader\CsvFile::make(database_path('files/users.csv'), 'w')
    ->headers(array_keys($users->first()->toArray()))
    ->insert($users->toArray())
    ->close();
```

#### Loading CSV File with Headers

[](#loading-csv-file-with-headers)

Load users from `oracle` to `backup` database connection.

```
$loader->inFile(database_path('files/users.csv'))
    ->withHeaders()
    ->mode(Yajra\SQLLoader\Mode::TRUNCATE)
    ->connection('backup')
    ->into('users')
    ->execute();
```

### Wildcard Path with Headers

[](#wildcard-path-with-headers)

When using a wildcard path, the first file is assumed to contain the headers. The succeeding files should not have headers or it will be reported as a bad record.

```
$loader->inFile(database_path('files/*.csv'))
    ->withHeaders()
    ->mode(Yajra\SQLLoader\Mode::TRUNCATE)
    ->into('employees')
    ->execute();
```

- employees-1.csv

```
name,dept_id
John Doe,1
Jane Doe,2
```

- employees-2.csv

```
John Doe,1
Jane Doe,2
```

### Constants

[](#constants)

In some cases, we need to insert constant values to the table. You can use the `constants` method to set the constant value.

Important

`constants` must be called before the `into` method.

```
$loader->withHeaders()
    ->constants([
        'file_id CONSTANT 1',
        'created_at EXPRESSION "current_timestamp(3)"',
        'updated_at EXPRESSION "current_timestamp(3)"',
    ])
    ->into('users');
```

### Connection

[](#connection)

You can set the connection name to use for the SQL\*Loader command using the `connection` method.

```
$loader->connection('oracle');
```

### Disk

[](#disk)

You can set the disk to use for the control file using the `disk` method.

```
$loader->disk('local');
```

### Logging

[](#logging)

You can get the logs of the execution using the `logs` method.

```
return nl2br($loader->logs());
```

### Custom Control File

[](#custom-control-file)

You can use a custom control file by passing the control file name to the `as` method.

```
$loader->as('employees.ctl');
```

### Execute

[](#execute)

You can execute the SQL\*Loader command using the `execute` method.

```
$loader->execute();
```

You can also set the execution timeout in seconds. Default is 3600 seconds / 1 hr.

```
$loader->execute(60);
```

### Execution Result

[](#execution-result)

You can check if the execution was successful using the `successfull` method.

```
if ($loader->successfull()) {
    return 'Data loaded successfully!';
}
```

### Process Result

[](#process-result)

You can get the process result using the `result` method.

```
$result = $loader->result();
```

Using array as data source
--------------------------

[](#using-array-as-data-source)

You can use an array as a data source by using `begindData` method.

```
$loader = Yajra\SQLLoader\SQLLoader::make();
$loader->beginData([
        ['John', 1],
        ['Jane', 1],
        ['Jim, K', 2],
        ['Joe', 2],
    ])
    ->mode(Yajra\SQLLoader\Mode::TRUNCATE)
    ->into('employees', [
        'name',
        'dept_id',
    ])
    ->execute();
```

Available Configuration
-----------------------

[](#available-configuration)

You can publish the configuration file using the following command:

```
php artisan vendor:publish --provider="Yajra\SQLLoader\SQLLoaderServiceProvider" --tag="config"
```

### Connection Config

[](#connection-config)

You can set the connection name to use for the SQL\*Loader command.

```
'connection' => env('SQL_LOADER_CONNECTION', 'oracle'),
```

### SQL\*Loader Path Config

[](#sqlloader-path-config)

You can set the path to the SQL\*Loader executable.

```
'sqlldr' => env('SQL_LOADER_PATH', '/usr/local/bin/sqlldr'),
```

### Disk Config

[](#disk-config)

You can set the disk to use for the control file.

```
'disk' => env('SQL_LOADER_DISK', 'local'),
```

Credits
-------

[](#credits)

- [Arjay Angeles](https://github.com/yajra)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance85

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 90.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~41 days

Recently: every ~152 days

Total

16

Last Release

105d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c245d1effe6022f9f09b2e8b9cce26743de03a64d612cea4ce9885560d7c0b2?d=identicon)[yajra](/maintainers/yajra)

---

Top Contributors

[![yajra](https://avatars.githubusercontent.com/u/2687997?v=4)](https://github.com/yajra "yajra (145 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (5 commits)")[![EJ-OB](https://avatars.githubusercontent.com/u/135292423?v=4)](https://github.com/EJ-OB "EJ-OB (4 commits)")[![hpacleb](https://avatars.githubusercontent.com/u/24486552?v=4)](https://github.com/hpacleb "hpacleb (2 commits)")[![semantic-release-bot](https://avatars.githubusercontent.com/u/32174276?v=4)](https://github.com/semantic-release-bot "semantic-release-bot (1 commits)")[![emmanuelarturo](https://avatars.githubusercontent.com/u/61183606?v=4)](https://github.com/emmanuelarturo "emmanuelarturo (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (1 commits)")[![nikoolz](https://avatars.githubusercontent.com/u/167667339?v=4)](https://github.com/nikoolz "nikoolz (1 commits)")

---

Tags

hacktoberfestlaravelloaderoci8oraclesqlsql-loaderyajralaraveloracleoci8sqlldr

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/yajra-laravel-sql-loader/health.svg)

```
[![Health](https://phpackages.com/badges/yajra-laravel-sql-loader/health.svg)](https://phpackages.com/packages/yajra-laravel-sql-loader)
```

###  Alternatives

[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8703.0M17](/packages/yajra-laravel-oci8)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
