select sec_sec_nm,count(1)OVER() from nms_num_scheme
where nms_sec_nm like 'CMIG4%';
This query runs in one Oracle DB.
But the same query does not return any data in other DB though data are available.
This should work:
SELECT sec_sec_nm from nms_num_scheme where nms_sec_nm like 'CMIG4%';
I really don't know what you're trying to do with:
select sec_sec_nm,count(1)OVER()
But I don't think that will work at all.
select sec_sec_nm,count(1) cnt from nms_num_scheme
where nms_sec_nm like 'CMIG4%'
group by sec_sec_nm
Related
I have a struct in a table (Iceberg Database format) and I would like to expand all of the children of the struct.
The normal query would look like :
SELECT
base.el1,
base.el2,
base.el3
FROM myTable
Instead of that, I would like to have a statement as the following: (not working - just an idea)
Select
base.*
FROM myTable
That would return
el1
el2
el3
One
Two
Three
Is it possible to realize such statement?
In real-life I have like hundreds of elements and do not wish write all of them down.
If I do the proposed (not-working) statement.
It returns something like:
col1
(One,Two,Three)
Do you just want to concatenate the columns like this?
select concat(el1,',',el2,',',el3) as b from a;
https://www.db-fiddle.com/f/cqusK23oVYcTBvD4cv9GoA/0
Apparently, it just works with the following statement:
Select
base.*
FROM myTable
For some reason it was returning an erroronous result but not from my part of the Query statement.
I have written a query like this :
select *
from DATASYNCH_HA_TO_TRG_AUDIT_HIST
where PSX_BATCH_ID IN (select PSX_BATCH_ID
from DATASYNCH_HA_TO_TRG_AUDIT_T
);
Here,when I execute the sub-query alone, it results some values and when I put those values in the place of sub-query the main query also returns some values.But,when I use this whole query ,it does not result any values.How is it possible?
Hope PSX_BATCH_ID column datatype is integer. if it is varchar filed, then trim the value.
SELECT *
FROM DATASYNCH_HA_TO_TRG_AUDIT_HIST
WHERE TRIM(PSX_BATCH_ID) IN
(SELECT TRIM(PSX_BATCH_ID) FROM DATASYNCH_HA_TO_TRG_AUDIT_T);
Instead of using IN query, use JOIN
SELECT *
FROM DATASYNCH_HA_TO_TRG_AUDIT_HIST A
INNER JOIN DATASYNCH_HA_TO_TRG_AUDIT_T B
ON (A.PSX_BATCH_ID = B.PSX_BATCH_ID)
Really Sorry guys,I found out it was actually a database issue.I ran the query recently in a procedure,it is working fine.
I would like to know if is it possible to use the clause "with as" with a variable and/or in a block begin/end.
My code is
WITH EDGE_TMP
AS
(select edge.node_beg_id,edge.node_end_id,prg_massif.longueur,prg_massif.lgvideoupartage,prg_massif.lgsanscable from prg_massif
INNER JOIN edge on prg_massif.asset_id=edge.asset_id
where prg_massif.lgvideoupartage LIKE '1' OR prg_massif.lgsanscable LIKE '1')
,
journey (TO_TOWN, STEPS,DISTANCE,WAY)
AS
(SELECT DISTINCT node_beg_id, 0, 0, CAST(&&node_begin AS VARCHAR2(2000))
FROM EDGE_TMP
WHERE node_beg_id = &&node_begin
UNION ALL
SELECT node_end_id, journey.STEPS + 1
, journey.DISTANCE + EDGE_TMP.longueur,
CONCAT(CONCAT(journey.WAY,';'), EDGE_TMP.node_end_id
)
It create a string as output separated by a ; but i need to get it back as variable or table do you know how? I used a concat to retrieve data in a big string. Can i use a table to insert data
,
A need to use the result to proceed more treatment.
Thank you,
mat
No, WITH is a part of an SQL statement only. But if you describe why you need it in pl/sql, we'll can advice you something.
Edit: if you have SQL statement which produces result you need, you can assign it's value to pl/sql variable. There are several methods to do this, simpliest is to use SELECT INTO statement (add INTO variable clause into your select).
You can use WITH clause as a part of SELECT INTO statement (at least in not-too-very-old Oracle versions).
SELECT DEPARTMENT.D#,DEPARTMENT.DNAME,DEPARTMENT.MANAGER#
FROM DEPARTMENT,PROJECT
WHERE DEPARTMENT.D# <> PROJECT.D#;
when this code run in SQL plus, a lot repeated output come out, my output should be
one time only.
Use as
SELECT DEPARTMENT.D#,DEPARTMENT.DNAME,DEPARTMENT.MANAGER#
FROM DEPARTMENT,PROJECT
WHERE DEPARTMENT.D# != PROJECT.D#;
Not sure if this is something that you want, but if you want only those departments that do not have any projects use
SELECT DEPARTMENT.D#,DEPARTMENT.DNAME,DEPARTMENT.MANAGER#
FROM DEPARTMENT
WHERE DEPARTMENT.D# not in (select PROJECT.D# from project);
Hope it Helps
Vishad
as topic says, I don't want to return the first two letters in the return values
just an example:
select companyname from companies
returns companyX
Can I write a query that returns panyX instead?
Thanks in advance
select right(companyname, len(companyname)-3) as companyname will do the thing (this should work for microsoft T-SQ, see more string functions here )
Since you don't say what RDBMS you're using, here is an ANSI-compliant answer:
SELECT SUBSTRING(mycolumn,3,CHARACTER_LENGTH(mycolumn))
SELECT SUBSTRING(companyname, 3, len(companyname) - 2)
FROM companies
Here is a bunch of string manipulation stuff for sql
Tutorial 4: SQL functions
SELECT SUBSTR(COMPANYNAME,3) FROM COMPANIES;
u can solve ur issue using following queries,
--> select substring([image],4,len([image]))from dbo.emp
--> select replace([image],'ima','') from dbo.emp
Thanks
Venkat