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" - sqlplus

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.

Related

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";

Firebird: simulating create table as?

I'm searching a way to simulate "create table as select" in Firebird from SP.
We are using this statement frequently in another product, because it is very easy for make lesser, indexable sets, and provide very fast results in server side.
create temp table a select * from xxx where ...
create indexes on a ...
create temp table b select * from xxx where ...
create indexes on b ...
select * from a
union
select * from b
Or to avoid the three or more levels in subqueries.
select *
from a where id in (select id
from b
where ... and id in (select id from c where))
The "create table as select" is very good cos it's provide correct field types and names so I don't need to predefine them.
I can simulate "create table as" in Firebird with Delphi as:
Make select with no rows, get the table field types, convert them to create table SQL, run it, and make "insert into temp table " + selectsql with rows (without order by).
It's ok.
But can I create same thing in a common stored procedure which gets a select sql, and creates a new temp table with the result?
So: can I get query result's field types to I can create field creator SQL from them?
I'm just asking if is there a way or not (then I MUST specify the columns).
Executing DDL inside stored procedure is not supported by Firebird. You could do it using EXECUTE STATEMENT but it is not recommended (see the warning in the end of "No data returned" topic).
One way to do have your "temporary sets" would be to use (transaction-level) Global Temporary Table. Create the GTT as part of the database, with correct datatypes but without constraints (those would probably get into way when you fill only some columns, not all) - then each transaction only sees it's own version of the table and data...

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

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

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