---
title: "Discussion on \"Writing Fast Queries in APEX\" | Hashnode"
description: "Discussion on \"Writing Fast Queries in APEX\". A function to accomplish tip #9 of my \"Writing Fast Queries\" blog post"
url: "https://hashnode.com/posts/writing-fast-queries-in-apex/67dd8f8b5b905023af864ac2"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Writing Fast Queries in APEX](https://apexdebug.com/writing-fast-queries-in-apex?utm_source=hashnode&utm_medium=feed)

A function to accomplish tip #9 of my "Writing Fast Queries" blog post

Mar 21, 2025 · 3 min read · apexdebug.com  
Updated Apr 3, 2025  
Read the article

-   [#orclapex](https://hashnode.com/tag/orclapex)
-   [#oracleapex](https://hashnode.com/tag/oracleapex)

## Written by

[Anton Nielsen](https://hashnode.com/@ainielsen)

@ainielsen

  
[View profile](https://hashnode.com/@ainielsen)

Bike shop mechanic

## Responses 2

Markdown supported · ⌘↵ to post

[Joe Kerr](https://hashnode.com/@jkerr)

[Mar 29, 2025](https://hashnode.com/posts/writing-fast-queries-in-apex/67dd8f8b5b905023af864ac2/comment/67e847f87c8e2b9bf7fcf6cd)

I am trying to implement this with a more complicated query. Thoughts on a where clause like this, or one using between and dates? ( VW\_Person.Person\_Number = :APP\_PERSON\_PERSON Or :APP\_IS\_ADMIN = 'Y') And ( :P21\_CRITERIA\_STATUS = 'A' AND STATUS\_TRAN\_PERSON = 'ACTIVE' OR :P21\_CRITERIA\_STATUS = 'I' AND STATUS\_TRAN\_PERSON = 'INACTIVE' OR :P21\_CRITERIA\_STATUS NOT IN ('A', 'I')) And (:P21\_CRITERIA\_EPRGENRL\_ID IS NULL OR Employer\_ID = :P21\_CRITERIA\_Employer\_ID); Note: Criteria\_Status is a group letting the user select (A)ctive, (I)nactive, or Al(L) people. Thanks Joe

[Joe Kerr](https://hashnode.com/@jkerr)

[Mar 29, 2025](https://hashnode.com/posts/writing-fast-queries-in-apex/67dd8f8b5b905023af864ac2/comment/67e7db0fd046255723a17507)

Very helpful both for the code, and the perspective. Are there security concerns here from having a function that creates a query from inputs vs. a "hard coded" query?

[Anton Nielsen](https://hashnode.com/@ainielsen)

[Apr 3, 2025](https://hashnode.com/posts/writing-fast-queries-in-apex/67dd8f8b5b905023af864ac2/comment/67e7db0fd046255723a17507#reply-67eed3cdb5891a5450e1c872)

No extra security concerns at all. In fact, that's one reason I decided to write the function. This function uses bind variable and, although it does concatenate on unescaped column names, those columns names are defined by the developer at design time, not run time, and they can't be changed at run time. The only security concern is with the developer, which is the same as it is for a hard coded query.

[Sakthikumar Periyasamy](https://hashnode.com/@psakthikumardpw)

[Mar 27, 2025](https://hashnode.com/posts/writing-fast-queries-in-apex/67dd8f8b5b905023af864ac2/comment/67e53c34118a4b1b00b48419)

Excellent piece, I am going to implement right now
