SQLPLUS Column Format and Select query executed simultaneously - sqlplus

I was curious if there was a way in SQLPLUS to run the column format option as well as the select query in one line? instead of having to run each format column line individually. for example:
((column "Role" heading "Role" Format a30,
column "User ID" heading "User ID" Format a5,
column "Password" heading "Password" format a8,
column "Group" heading "Group" format a50,
column "User Name" heading "User Name" Format a15),
(Select ...);
Thanks for any input!

The COLUMN ... FORMAT command keeps config for a given column until either you exit from SQL*Plus or provide a new format. So NO, it does not apply to a single query and it cannot go inside a single query.
(Oracle reference)

Related

Query function to select all columns of an imported data set, starting from a specific column

I am looking to query specific columns of an imported dataset from a separate google sheet. Ideally, I would like to query all columns after the "product ID" column (refer to "Test Data Set"). The reason why I am doing this is that I need the product ID column to remain in a particular position in the "Final Destination Sheet" since the "Product ID"s will be used as a reference range for the index and match formulas on another tab of that sheet.
The formula I have so far to import and query the original dataset for the "Product ID" column is as so:
=QUERY({IMPORTRANGE("1aPpdSy5venMl97ayn7VwaOo_AcAtcoc6_l4a1loPhNI","Sheet1!A:D")}, "SELECT Col" &MATCH("Product ID", IMPORTRANGE("1aPpdSy5venMl97ayn7VwaOo_AcAtcoc6_l4a1loPhNI","Sheet1!A1:1"),0),1)
However, I am unsure how to make the formula understand to query up all the columns after the "Product ID" column. Do note, the test data set only has 4 columns and a set number of columns but the real data set I am working with will be dynamic so more columns can be added or deleted over time. (So I won't know what the finite column letter will be and if columns are deleted from the left of B then it might shift its position which is why I used the match function in my original formula to ID that specific column's location on the spreadsheet).
Thank you in advance!
Final Destination Sheet (where the data is imported to and where I am trying to query the original data for specific columns): link
Test Data Set (where the data is imported from): link
if you know the headers you can do:
=TRANSPOSE(QUERY(TRANSPOSE(IMPORTRANGE("1aPpdSy5venMl97ayn7VwaOo_AcAtcoc6_l4a1loPhNI",
"Sheet1!A:D")), "where lower(Col1) matches 'product id|size'", 0))
update:
=IMPORTRANGE("1aPpdSy5venMl97ayn7VwaOo_AcAtcoc6_l4a1loPhNI",
"Sheet1!"&ADDRESS(1, MATCH("Product ID",
IMPORTRANGE("1aPpdSy5venMl97ayn7VwaOo_AcAtcoc6_l4a1loPhNI",
"Sheet1!1:1"), 0))&":1000")
assuming headers are in row 1 this will look for a column called product id and import it and all the columns to the right of it

How to join tables using Query or Vlookup

I have 2 sheets
people sheet has
[company first_name last_name full_name address_line1 address_city address_state address_zip address_country telephone email order_id order_date order_time processor order_type order_currency commission campaign_id]
sales sheet has
[DATE PROSPECT NAME EMAIL ADDRESS CONTACT METHOD PRODUCT RESULT NOTES ]
How do I make the report to generate when people.email = sales.EMAIL ADDRESS and display the records only if they match (Not all of sales sheet)
Report fields are
full_name
EMAIL ADDRESS
PRODUCT
commission
Sample File
Please try to use basic formula for joining sheets + query to skip some rows.
Basic formula:
=FILTER({Sales!B14:B,Sales!C14:C,Sales!E14:E, vlookup(Sales!E14:E,{People!B2:B,People!D2:D},2,), Sales!F14:F},Sales!A14:A<>"")
The formula you need:
=QUERY(FILTER({Sales!B14:B,Sales!C14:C,Sales!E14:E, IFERROR(vlookup(Sales!E14:E,{People!B2:B,People!D2:D},2,), "do not show"), Sales!F14:F},Sales!A14:A<>""),"select * where Col4 <> 'do not show'")
How it works
It uses iferror(expression, "do not show") to replace #N/A error with the text "do not show".
Then it uses query to hide rows with value "do not show":
"select * where Col4 <> 'do not show'"
Basic formula and the question is here
Notes about usage:
Sales!B14:B,Sales!C14:C,Sales!E14:E are some columns you need to select first
IFERROR(vlookup(Sales!E14:E,{People!B2:B,People!D2:D},2,) will return column from "People", it is column People!D2:D. Please note that columns Sales!E14:E and People!B2:B are both containing a key, in the sample it is e-mail list.
Sales!F14:F is a column to return next.
filter condition Sales!A14:A<>"" is to skip empty rows from original sheet. You may also add other conditions into a filter.
query part will shorten the report and skip values where keys (emails) do not match. You may add other conditions into a query.
Note. Query language in Google Sheets does not have joins, and provided solution is a workaround. It shows how to make a join with a help of vlookup function in Sheets.
The provided formula gathers rows from sheet "Sales" and makes vlookup to sheet "People". You also may want to make vice-versa report: collect data from "People" and 'vlookup` data from "Sales".
"Vice-versa" report:
=QUERY(FILTER({vlookup(People!B2:B ,{Sales!E14:E, Sales!B14:B, Sales!C14:C, Sales!E14:E},{2, 3, 4},), People!B2:B, IFERROR(vlookup(People!B2:B ,{Sales!E14:E, Sales!F14:F},2,),100500)},People!A2:A<>""),"select * where Col5 <> 100500")
note! In this formula used numeric value 100500 to skip values because query works with the single data type (number or text).
Please comment here if you have any questions about how it works.

How to leave a blank field in table in sqlplus?

In sql, if some fiels are to be left blank while inserting the values in the table, how shall we do it?
For eg. For name field, i want to insert 'First Name' & 'Last Name' but not 'Middle Name'.
But the field is already present by default in the table.
If I have understood you correctly, you simply need to execute an INSERT sentence, without using the columns (fields) you don't want to inform.
As an example, if you have three columns and don't want to inform column2 use
INSERT INTO table_name (column1,column3)
VALUES (value1,value3);
instead of
INSERT INTO table_name (column1,column2,column3)
VALUES (value1,value2,value3);
Hope it helps!

Formatting: Changing Column Headers for SqlPlus Query

I'm having trouble with two formatting issues that I would really appreciate help with:
1) The Days Open column is displaying the number of days properly, but the column name is being overwritten by my conversion command, and
2) I need the Order Date (OOpenDate) to be displayed in the "MM/DD/YYYY" format
Code:
column O_Num heading 'Order|Number' format a6
column OOpenDate heading 'Order|Date' format a10
column (sysdate-OrderOpenDate) heading 'Days|Open' format a4
select O_Num, OOpenDate, to_char(sysdate-OOpenDate, '999')
from Orders
where Status = 'Open';
What its currently displaying:
Order Order
Number Date TO_C
------ --------- ------
100 03-DEC-13 14
What I want it to display as:
Order Order Days
Number Date Open
------ --------- ------
100 12/03/2013 14
Thank you in advance!
The simplest approach would be to alias the "Days Open" column and apply the format mask to the alias
column days_open heading 'Days|Open' format a4;
select O_Num, OOpenDate, to_char(sysdate-OOpenDate, '999') days_open
from Orders
where Status = 'Open';
Otherwise, the column name in your column command would need to exactly match the expression in your SELECT statement (including the to_char, any spaces, etc.) That's possible but it generally makes things rather hard to maintain.

How can I have column E copy its data into the right column based on the initials in column M?

So what I have so far is a spreadsheet that will auto time stamp column N when my technicians enter their initials into column M.
Now the 2nd thing I would like the spreadsheet to do is.
When I enter the hours (example: 1.8) into column E "HRS." And have the spreadsheet put the HRS. into the correct Technicians column. Based on the initials entered in column M "Tech Up".
Example: if E4=1.8 it would put 1.8 into G4 because M4=AB
Example: if E6=3.2 it would put 3.2 into J6 because M6=JW
Does anyone know what type formula this would require? Or where I might look to find one?
If the data starts in row 4, and the individual technician columns start at column G, try in G4:
=ArrayFormula(IF(E4:E*(M4:M={"AB","CD","GM","JW","RT"});E4:E;IFERROR(1/0)))
and if the initials of the technicians are already in G2:L2 as headers:
=ArrayFormula(IF(E4:E*(M4:M=G2:L2);E4:E;IFERROR(1/0)))
Notes if using the first option:
Change the initials in the embedded array to match your columns
If your spreadsheet is set to a locale that uses commas as a decimal, change the commas in the embedded array to \

Resources