# Execute SQL in Oracle with tables that contain the "$" character in the name

**URL:** <https://forum.ansible.com/t/execute-sql-in-oracle-with-tables-that-contain-the-character-in-the-name/38734>\
**Category:** Ansible Project\
**Created:** [March 28, 2024, 7:38pm UTC](https://forum.ansible.com/t/execute-sql-in-oracle-with-tables-that-contain-the-character-in-the-name/38734 "2024-03-28T19:38:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luiz\_Gustavo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/luiz_gustavo/32/4846_2.png) [@Luiz\_Gustavo](https://forum.ansible.com/u/Luiz_Gustavo)\
**Post date:** [March 28, 2024, 7:38pm UTC](https://forum.ansible.com/t/execute-sql-in-oracle-with-tables-that-contain-the-character-in-the-name/38734/1 "2024-03-28T19:38:10Z")

</div>

Hello experts,

I’m testing a playbook and I intend to make a SQL query on an Oracle database.  
If the query contains the character “$” or is protected “$”, I need them to be treated as protected “$”.  
I’m using the regex\_replace filter but I’m having difficulty.  
It would be something like:

# Start code

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [March 29, 2024, 12:37am UTC](https://forum.ansible.com/t/execute-sql-in-oracle-with-tables-that-contain-the-character-in-the-name/38734/2 "2024-03-29T00:37:49Z")

</div>

See if this helps. It uses a regex negative lookbehind, only inserting a backslash in front of the dollar sign if there isn’t already one there. You’ll need to adapt it to your use case a little bit.

```auto
---
# escape-dollar.yml
- name: Escape dollar signs
  hosts: localhost
  gather_facts: false
  vars:
    dollar_string: |
      A. Thi$ line contain$ une$caped dollar $igns.
      B. Thi\$ line contain\$ e\$caped dollar \$igns.
  tasks:
    - name: Exec SQL
      shell:
        cmd: |
          printf "%s\n" '{{ dollar_string }}'
          printf "%s\n" '{{ dollar_string | regex_replace('(?<!\)(\$)', '\') }}'
      register: cdb_out

    - name: Output
      debug:
        msg: "{{ cdb_out.stdout_lines }}"

## TASK [Output] ***************************************
## ok: [localhost] => 
## msg:
## - A. Thi$ line contain$ une$caped dollar $igns.
## - B. Thi\$ line contain\$ e\$caped dollar \$igns.
## - ''
## - A. Thi\$ line contain\$ une\$caped dollar \$igns.
## - B. Thi\$ line contain\$ e\$caped dollar \$igns.

```

---

<div class="post-metadata">

**Author:** ![Luiz\_Gustavo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/luiz_gustavo/32/4846_2.png) [@Luiz\_Gustavo](https://forum.ansible.com/u/Luiz_Gustavo)\
**Post date:** [April 1, 2024, 10:53am UTC](https://forum.ansible.com/t/execute-sql-in-oracle-with-tables-that-contain-the-character-in-the-name/38734/3 "2024-04-01T10:53:12Z")

</div>

Worked perfectly! Thanks Todd.
