Oracle returns value in 2 tables - sql

currently I'm facing a problem where I select the data from db where it returns the data into 2 tables.
I have attached a screenshot of the output. Hope you guys can help. Thanks
This is Screenshot.

You need to format the output in the SQL*Plus to make the output looks proper.
You can use
COLUMN <column_name> FORMAT <format>;
for string:
COLUMN SCENE_NAME FORMAT a15
Example for numbers:
COLUMN SCENE_ID FORMAT 99
For more details on column formatting, please refer Oracle documentation here
Also, you will need to set the LINESIZE using
set linesize 250
here, 250 means the total character that can fit into one line and the size of the character is calculated based on the column format.

Before that you mention which database table you will display. After do select query

Related

Trouble creating a SQL script in Excel

So I have some data in column A1 that is typically always numbers but can be different character lengths, I need the output of the sql script to contain it in single quotes ''.
I also have data in column B1 that is always a date which I need it to be contained in single quotes as well as be in the format of mm/dd/yyyy when it's output to the SQL script.
I've been trying to accomplish this with a CONCATENATE formula but I can't seem to get it right.
I've tried formatting column A and B accordingly and it works for those columns but it doesn't transfer the output of the formatting into the script.
Here's an example of the formula I'm using:
=CONCATENATE("update unit set dtavailable = ",B1," ,dtready = ",B1," where scode = ",A1,""," ","and hproperty = ",C1,"")
Any help would be much appreciated!
Thanks.
Example

How batch edit contents of near 2000 field values in MariaDB table?

I would need to edit and change the content for around 2000 field values in my database "alyssa" for "products" table and for all its field of "productId".
Every productId is in numeric format "1234567890".
I would need to change all of these numeric id's to conform the following format:
"alyssa-PROD-1234567890-1".
So, e.g. if the product id was like "3298374237" it would need to be changed to the format of "alyssa-PROD-3298374237-1".
The fixed values are "alyssa-PROD-" and tailing "-1". These won't be changing.
Please could you possibly kindly assist me to form a script / command which I could run in order to batch change all of the productId's to the described format?
Thank you so much in advance! :) Yours, Alyssa
You can use update:
update t
set productId = concat('alyssa-PROD-', productId, '-1');
Note: This assumes that productId is stored as a string, albeit a string consisting only of digits. If you only want numeric strings to be converted:
update t
set productId = concat('alyssa-PROD-', productId, '-1')
where productId regexp '^[0-9]+$';

Commas using SAS and TD SQL

I am using SAS to pull data in a Teradata environment. I am counting the rows in the Teradata table, but want the output to be in a comma format (i.e. 1,000,000). I was able to use the code below to display the value as a comma, but when I try to add the column in SAS, I can't since the output is in a character format. Does anyone have any suggestions on how to format the number value as comma, so that it can be used for calculation purposes in SAS? Thanks.
CAST(Count(*) as (format 'Z,ZZZ,ZZ9')) as char(10)) as rowCount,
Assuming you're using pass through, pull it in as numeric and format it on the SAS side. You've now converted it to character (char10) and SAS doesn't do math on character variables which makes logical sense.
select rowCount format=comma12. from con
(select
count(*) as rowCount ....
)
If you have a select * you can always format it later in a data step or via PROC DATASETS. SAS separates the display and storage layers so the format controls the appearance but the underlying data still remains numeric.

Need to get a value till precision of 15 digit after decimal in DB2 Query

One of DB2 table column value is appearing as 0.3901369869709015 and we need to compare this value against my expected value as 0.390136986970901. I tried to get the value from DB2 by using Decimal/Dec method. With that the value is getting round off and appearing as 0.390136986970902. Could you please help me to correct the below query that i am using to extract data from my DB2 table.
SELECT DECIMAL(UV_FIELDSCOREMAP,15,15) AS UV_FIELDSCOREMAP From cvsinst.uv_occ WHERE CASEID = '20170720'
Use TRUNCATE(UV_FIELDSCOREMAP, 15) instead.

Truncation Warning when data should fit

We are updating column A with the exact value from column B. The length of column B is 255 and column A is 4. The data in column B has been verified by LEN(REVERSE(colB)) to be only 4. When we try to update the error message says:
'String or binary data would be truncated.'
here is the query:
update table
set columnA=columnB
where Column B in ('ABC','ABCD','AB')
we have also verified that this works:
update table
set columnA=left(columnB,4)
where Column B in ('ABC','ABCD','AB')
any guesses as to what could be wrong?
thanks
It could be that you are using a char (not varchar) data type for column B, in which case your database engine may consider the width of the column, regardless of the width of the data. A trim function may then get rid of the error.
SQL doesn't check the actual length of the string - it just detects that the string value COULD overflow the new container and gives you an error message. Try this:
update table set ColumnA=(select LEFT(ColumnB, 4) from table where ColumnB in ('ABC', 'ABCD', 'AB'));
This selects only the first four characters of the data from columnB.
This query works And I am ok with it.
update table
set columnA=columnB
where Column B in ('ABC','ABCD','AB') and len(columnb)<=4
I am still curious as to why