How can I take substring in Oracle [closed] - oracle

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a row string in oracle table.
Some text № 3694452 from 31.08.2013, stilltext 02.09.2013 18:16:27
How can I take "02.09.2013 18:16:27" (from the end of row and after stilltext)
for converting it to date.

Assuming that the date string always positioned at the end of text,
you can use regular expression like this:
select
to_date(
regexp_substr(your_column_name, '\d{2}.\d{2}.\d{4} \d{2}:\d{2}:\d{2}$'),
'dd.mm.yyyy hh24:mi:ss')
from you_table_name;

This assumes that the date is always at the end of the string and is fixed in format.
with dummy as
(select '3694452 from 31.08.2013, stilltext 02.09.2013 18:16:27' data
from dual)
select to_date(substr(data,length(data)-19), 'MM.DD.YYYY HH24:MI:SS')
from dummy
There are more elegant ways to do this with regular expressions, but I am assuming this will suffice.
SQL Fiddle demo here

Related

Oracle pl/sql check if number starts with 9 or 8 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i am trying to validate data inside my database that is number.
Am i able to detect the retrieved data whether it starts with 8 or 9?
For example:
8999999 is valid
9999999 is valid
7000000 is invalid
Thanks
You can try checking the first character of the field using SUBSTR():
SELECT field_value
FROM your_table
WHERE SUBSTR(TO_CHAR(field_value), 1, 1) IN ('8','9')
The following query will return all records where column data begins with an 8 or 9:
SELECT data
FROM your_table
WHERE REGEXP_LIKE (CAST(data AS varchar2(30)), '^(8|9)(*)');
I assume here that data is a numeric type, and so I cast it to varchar before using REGEXP_LIKE.

Function to convert a string to character [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
select 'open' as "documentno" from c_order
union all
select documentno as "documentno" from c_invoice
.This is not working in oracle.
i need a query that works in both oracle and postgres
You have not provided enough information to answer your question.
My guess is that you want to include columns in a union that do not have the same data type and are looking for a way to cast a number to a character value (again I'm guessing because you didn't tell us what data type documentno is).
The following works in Oracle and Postgres:
select 'open' as "documentno" from c_order
union all
select cast(documentno as varchar(20)) as "documentno" from c_invoice;
However: the first part of the union does not make sense. Why are your retrieving the same constant value for each and every row in c_order without any additional information from that table?

Convert Row into columns [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
how can I convert rows of my table as column value
for eg I have a table a
emp id
1
2
3
4
and I want my output as
1 2 3 4
i am also using pivot in oracle and crosstab in postgres but not able to get desired solution as shown above.
Check the listagg function. Note you need at least Oracle 11 for this.
Use this script and change it to your values to get desired results
SELECT * FROM (SELECT emp_id, emp_points
FROM emp_data)
PIVOT (
SUM(emp_points) AS sum_emp_points
FOR (emp_id) IN (1 AS [1], 2 AS [2],3 AS [3],4 AS [4])
);
select * from (select empno from t7) pivot(min(empno) for empno in (1,2,3,4));

Delete trailing space from all values [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table that contains more than 4 thousand rows. Suppose I have a column named columnname that has values for all rows but each value may have leading and/or trailing blank characters. So, it might look like this
columname
"value "
"value "
"value "
...
And I need a query or technique that removes the leading and/or trailing spaces, like this:
columname
"value"
"value"
"value"
How can I achieve this? (I use oracle 11g)
UPDATE table SET columnname = TRIM( columnname );
followed by
DELETE FROM table WHERE columnname IS NULL;
Just this:
Update table set columnname = trim(columnname)

how to find memory utilisation of a table? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to find the memory utilised by a particular table in Oracle DB. Could anyone provide me the DB query for the same?
Thanks in advance!
Following what #Alex said,
You can check the table size on disk by querying dba_segments
select segment_name , segment_type , byte/1024/1024 mb
from dba_segments
where owner = 'X'
and segment_name= 'Y';
If you want to see which or how many blocks from the table are currently stored in the cache you can query v$cache. read about it here

Resources