---
title: "BASENAME"
description: "The BASENAME SQL function extracts the file name from a file path."
language: en
source_language: en
translation_state: complete
canonical: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/sql-functions/basename
original: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/sql-functions/basename
updated: 2026-08-09T00:00:00Z
license: https://documentation.invantive.eu/en/
---

## Syntax
```mermaid
%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    Start((START)) --> BASENAME[BASENAME]:::quoted
    BASENAME --> FUNCPARS1["("]:::quoted
    FUNCPARS1 --> FUNCPARS2[parameters]
    FUNCPARS2 --> FUNCPARS3[")"]:::quoted
    FUNCPARS3 --> End((END))
```

## Purpose
The `BASENAME` SQL function extracts the file name from a file path.

Parameters:
- File path (`varchar2`): full path of a file, containing filename, but also possibly drive, folders and extension.
- Extension (optional, `varchar2`): extension to remove, including leading '.' when necessary.

Returns: the file name from the file path as `varchar2`.

## Examples
The following example extracts the filename from a file name and path:
```sql
select basename('c:\temp\myfile.png')

--------------------
myfile.png
```
The following example extracts the filename from a file name and path, including removal of the `.png` extension:
```sql
select basename('c:\temp\myfile.png', '.png')

--------------------
myfile
```