question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Define variable in script

See original GitHub issue

Hello i have in the same panel query a lot


select x,y from tabA where col1=:param1
UNION
select t,u from tabB where col5=:param1 and col6=:param2

… This works pop upping the variable request panel. sometimes i have to redo the query a lot of time changing only param1 value so i like the possibility to write at the begin of my query something like

def :param1='XXX'
def :param2='YYY'

select x,y from tabA where col1=:param1
UNION
select t,u from tabB where col5=:param1 and col6=:param2

This is useful also if I have to do this on multipl DB so i can copy paste the code in a separate tab change only the value and do the query on another DB.

this syntax can be useful also to remember the last value i used.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

25reactions
serge-ridercommented, Nov 26, 2017

You already can do this with command set: @set paramName=paramValue Like this:

@set param1='XXX'
@set param2='YYY'

select x,y from tabA where col1=:param1
UNION
select t,u from tabB where col5=:param1 and col6=:param2

Is this what you need?

0reactions
ClodoaldoPintocommented, Dec 2, 2019

@damaresende

That is great! What if I want to get the value from a query? Is that possible? I am trying the following but I get an error (ORA-00936: missing expression).

@set cust_doc = 123456789 @set customer = SELECT customer_id FROM customers WHERE customer_document_no = :cust_doc

SELECT subscription_id FROM subscriptions WHERE customer_id = :customer -- many other queries using variable customer

In this case it is simpler and more performant to build the adequate query:

@set cust_doc = 123456789
select subscription_id
from
    subscriptions s
    inner join
    customers c on c.customer_id = s.customer_id
where customer_document_nu = cust_doc
Read more comments on GitHub >

github_iconTop Results From Across the Web

Declaring variables | Mastering Linux Shell Scripting
To declare a variable, just type the name you want and set its value using the equals sign ( = ). ... As...
Read more >
Unix / Linux - Using Shell Variables - Tutorialspoint
In this chapter, we will learn how to use Shell variables in Unix. A variable is a character string to which we assign...
Read more >
Understanding Shell Script Variables
Just about every programming language in existence has the concept of variables - a symbolic name for a chunk of memory to which...
Read more >
How to Use Variables in Shell Scripting - LinuxTechi
User Defined Variables ... These variables are defined by users. A shell script allows us to set and use our own variables within...
Read more >
BASH Programming - Introduction HOW-TO: Variables
You can use variables as in any programming languages. There are no data types. A variable in bash can contain a number, a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found