SQL change the "enter value" text to something else? - sqlplus

I am inputting a value into sql plus, and here is how I am getting the input:
And Abc.Abdef = &Abcdef;
When I execute it, it says:
Enter value for Abcdef:
How can I change the text enter value for to something else?
Is it possible?

No, it is not possible. SQL*Plus doesn't let you customise the prompt for substitution variables.
However, you can prompt for an input (with a custom prompt) and assign that to a variable which you then use in your statement:
SQL> accept foo prompt 'FOO: '
FOO: bar
SQL> select * from dual where '&foo'='bar';
old 1: select * from dual where '&foo'='bar'
new 1: select * from dual where 'bar'='bar'
D
-
X

Related

How to configure sql query shortcuts in SQL Workbench/J?

I want to get rid of writing a full sql syntax,
like I'm using for years in PL/SQL Developer editor or SQL SERVER Management Studio.
Examples:
count1 = select count(1) from
counthaving = select count(1) from having count(1)>?
s* = select * from
w = where
to_date = to_date('','dd/mm/yyyy')
sc* = select count(*) from
Thanks
This is what macros are intended for.
You can define a macro as "expandable" by selecting the "Expand while typing" check box in the macro definition.
If you type the "name" of such a macro in the editor and use the tab expansion key, the text will be replaced with the text of the macro.
It's recommended to un-check the option "Include in menu" for those macros.

How to hide ACCEPT command used for user input in SQL Plus while spooling it in a text file? I have tried "set VERIFY off"

I am new in SQL Plus. I have multiple queries in a SQL file.
Some queries have variables so whenever I use ACCEPT for that, the output file gets spooled including the command and input I entered.
Something like that:
SP2-0003: Ill-formed ACCEPT command starting as ,name char prompt 'Enter name:'
with the old and new statements like:
Enter value for name: 'john diaz'
old 3: (select * from sample where upper(name) = upper(&name)),
new 3: (select * from sample where upper(name) = upper('john diaz'))
How to remove those statements from output file?? Anyone??
SQL> SET VERIFY OFF
SQL> ACCEPT name CHAR PROMPT 'Enter name:: ' HIDE
Enter name:
SQL> select * from sample where upper(name) = upper(&name);
This way, it will not show OLD/NEW Value, and also you could enter Value in Hidden Way. No display on what you enter.

Can I use a parameter for the IN clause in a MySQL query/stored proc

I want to retrieve data in Delphi using a stored procedure. I used the below SQL statement and Initial as a parameter:
SELECT * FROM "PackUser" where Initials in (:Initial)
It didn't select any records when the user types A,B in my Edit box, because it sends a single string 'A,B' to the stored procedure. I want to add extra quotes in the middle: 'A','B'.
How can I do this?
This can be done like this:
input_string=',A,B,C.D'
SELECT * FROM "PackUser" where locate(concat(',', Initials), input_string);

How to show data in a table by using psql command line interface?

Is there a way to show all the content inside a table by using psql command line interface?
I can use \list to show all the databases, \d to show all the tables, but how can I show all the data in a table?
Newer versions: (from 8.4 - mentioned in release notes)
TABLE mytablename;
Longer but works on all versions:
SELECT * FROM mytablename;
You may wish to use \x first if it's a wide table, for readability.
For long data:
SELECT * FROM mytable LIMIT 10;
or similar.
For wide data (big rows), in the psql command line client, it's useful to use \x to show the rows in key/value form instead of tabulated, e.g.
\x
SELECT * FROM mytable LIMIT 10;
Note that in all cases the semicolon at the end is important.
Step 1. Check the display mode is "on" by using
\x
Step 2. Don't forget the ;
I tried for fifteen minutes just because I forgot the semicolon.
AND USE UPPERCASE ENGLISH.
TABLE users;
And you will get something like
On Windows use the name of the table in quotes:
TABLE "user"; or SELECT * FROM "user";
you should use quotes
example =>
1) \c mytablename
2) SELECT * FROM "mytablename"; OR TABLE "mytablename";
postgres commande line
to show databases : \l
to show tables : \dt
to show data in table x : SELECT * FROM "x";
to exit : \q
If you use schemas, the following will be correct:
SELECT * FROM "schema-name"."table-name";

union between requests with remplacement variables in sqlplus

I have 14 fields which are similar and I search the string 'A' on each of them. I would like after that order by "position" field
-- some set in order to remove a lot of useless text
def col='col01'
select '&col' "Fieldname",
&col "value",
position
from oneTable
where &col like '%A%'
/
-- then for the second field, I only have to type two lines
def col='col02'
/
...
def col='col14'
/
Write all the fields which contains 'A'. The problem is that those field are not ordered by position.
If I use UNION between table, I cannot take advantage of the substitution variables (&col), and I have to write a bash in unix in order to make the replacement back into ksh. The problem is of course that database code have to be hard-coded in this script (connection is not easy stuff).
If I use a REFCURSOR with OPEN, I cannot group the results sets together. I have only one request and cannot make an UNION of then. (print refcursor1 union refcursor2; print refcursor1+refcursor2 raise an exception, select * from refcursor1 union select * from refcursor2, does not work also).
How can concatenate results into one big "REFCURSOR"? Or use a union between two distinct run ('/') of my request, something like holding the request while typing new definition of variables?
Thank you for any advice.
Does this answer your question ?
CREATE TABLE #containingAValueTable
(
FieldName VARCHAR(10),
FieldValue VARCHAR(1000),
position int
)
def col='col01'
INSERT INTO #containingAValueTable
(
FieldName , FieldValue, position
)
SELECT '&col' "Fieldname",
&col "value",
position
FROM yourTable
WHERE &col LIKE '%A%'
/
-- then for the second field, I only have to type two lines
def col='col02'
INSERT INTO...
/
def col='col14'
/
select * from #containingAValueTable order by postion
DROP #containingAValueTable
But I'm not totally sure about your use of the 'substitution variable' called "col" (and i only have SQL Server to test my request so I used explicit field names)
edit : Sorry for the '#' charcater, we use it so often in SQL Server for temporaries, I didn't even know it was SQL Server specific (moreover I think it's mandatory in sql server for creating temporary table). Whatever, I'm happy I could be useful to you.

Resources