A possible fix for plsql:S1192 in views - substitute the repeated literal with client‑side variable

Hi Sonar Community,

Following up on PL/SQL Duplicated string literals in Views (#130460): the conclusion there was that this is a false positive because a view has no declaration block for a constant. That’s true inside the view, but there’s a possible fix worth considering that sidesteps it: define the literal once as a client‑side substitution variable and reference it in each spot. The substitution happens before the SQL reaches the database, so it works even though a view can’t declare a constant, and the literal is written exactly once.

Original code from the thread

'HZ_PARTIES' is repeated three times:

```

CREATE OR REPLACE FORCE VIEW chpont_sf_cust_contacts_v AS

SELECT DISTINCT ...

  FROM hz_parties hp_cntct, hz_contact_points hcp_email, ...

 WHERE ...

       AND hr.subject_table_name        = 'HZ_PARTIES'

       AND hr.subject_type              = 'PERSON'

       AND hr.relationship_code         = 'CONTACT_OF'

       AND hcp_email.owner_table_name(+) = 'HZ_PARTIES'

       AND hcp_email.contact_point_type(+) = 'EMAIL'

       AND hcp_phone.owner_table_name(+) = 'HZ_PARTIES'

       AND hcp_phone.contact_point_type(+) = 'PHONE'

       ...;

```

Suggested fix

Declare the literal once (pre‑quoted so each expansion is a valid SQL literal) and reference it, no repetition, so S1192 no longer fires:

```

\set HZ_PARTIES ‘’‘HZ_PARTIES’‘’

CREATE OR REPLACE FORCE VIEW chpont_sf_cust_contacts_v AS

SELECT DISTINCT ...

  FROM hz_parties hp_cntct, hz_contact_points hcp_email, ...

 WHERE ...

       AND hr.subject_table_name         = :HZ_PARTIES

       AND hr.subject_type               = 'PERSON'

       AND hr.relationship_code          = 'CONTACT_OF'

       AND hcp_email.owner_table_name(+)  = :HZ_PARTIES

       AND hcp_email.contact_point_type(+) = 'EMAIL'

       AND hcp_phone.owner_table_name(+)  = :HZ_PARTIES

       AND hcp_phone.contact_point_type(+) = 'PHONE'

       ...;

```

The :HZ_PARTIES references expand to 'HZ_PARTIES' at parse time, so the stored view definition is identical, only the source now has the literal in a single place. (The example uses psql’s \set; the Oracle SQL*Plus equivalent is DEFINE HZ_PARTIES = 'HZ_PARTIES' referenced as &HZ_PARTIES.)

Sharing in case it helps others hitting S1192 on view definitions. Also, is there any update on the status of SONARPLSQL-886?

SONARPLSQL-886 is marked ‘Done’ with a fix version of 3.18, which was released with SonarQube Server 2025.6.0+ / 2026.1+.