I am trying to describe a table without using the DESCRIBE
command but I want to combine the query with a substitution variable. Assuming I have the following table:
--DROP TABLE customers CASCADE CONSTRAINTS PURGE;
CREATE TABLE customers
( customer_id number(10) NOT NULL,
customer_name varchar2(50) NOT NULL,
city varchar2(50)
);
Following the posts here and here but adding a substitution variable, I have the following:
ACCEPT myv CHAR PROMPT 'Enter a table name: '
SELECT
column_name AS "Name",
nullable AS "Null?",
concat(concat(concat(data_type,'('),data_length),')') AS "Type"
FROM user_tab_columns
WHERE table_name = '&myv';
This returns a blank table with the appropriate column names. It doesn't matter if I entered the table name in the input prompt as CUSTOMERS or customers. However, desc customers
yields:
Name Null Type
------------- -------- ------------
CUSTOMER_ID NOT NULL NUMBER(10)
CUSTOMER_NAME NOT NULL VARCHAR2(50)
CITY VARCHAR2(50)
Any idea how I can get substitution variable to work here? Thanks.