Single select query or any sql statement with o/p
Hi,
I have one table test_tab with column names empno,empname.The test_tab values is as follows,
empno empname
01 siva
02 ram
03 kamal
04 sathish
i will give the empname values like 'siva,kamal,roshan,sathish' and empno >03,but in the table roshan name is not there.I need the below mentioned o/p
example qry: select empno,empname from test_tab where empname in('siva','kamal','roshan','sathish') and empno>03;
my o/p should be like this,
empname empno
sathish 04
roshan ''
But the empname 'roshan' is not there in table.I need the empname as 'roshan' and empno is null value in a single select query or subquery or any sql statements.
Please help me the resolve this issue.
Thanks
Sivaraman
Hi,
Do you want this?
with data as
(select 1 EMPNO, 'siva' as empname from DUAL union all
select 2 EMPNO, 'ram' from DUAL union all
select 3 EMPNO, 'kamal' from DUAL union all
select 4 EMPNO, 'sathish' from DUAL union all
select null EMPNO, 'roshan' from DUAL )
select * from data
where EMPNAME in ('siva','kamal','roshan','sathish')
and nvl2(empno,empno,4) > 3
Similar Messages
-
ABAP/4 Open SQL statement with WHERE ... LIKE and pattern too long
Dear All,
I am getting an error "ABAP/4 Open SQL statement with WHERE ... LIKE and pattern too long" while executing the following statement:
CLEAR LS_RANGE.
LS_RANGE-SIGN = 'I'
+LS_RANGE-OPTION = 'CP' +
LS_RANGE-LOW = 'S_ADMI_FCD'
LS_RANGE-HIGH = 'S_ADMI_FCD'
COLLECT LS_RANGE INTO LT_RANGE.
SELECT *
FROM UST12
INTO CORRESPONDING FIELDS OF TABLE LT_OBJECT_VALUES
WHERE FIELD IN LT_RANGE
AND AKTPS = 'A'.
For options like BT(Between), EQ(Equal) in range table, this above query is executing without dump. But for option CP, it simply dumps & in dump what i found is, it is concatenating the value in low & high.
Does anyone have any idea regarding open sql using range tables.
Thanks,
BhupinderHi,
I commented as follows:
If LS_RANGE-HIGH is empty, you can use EQ, NE, GT, LE, LT,CP, and NP. These operators are the same as those that are used for logical expressions. Yet operators CP and NP do not have the full functional scope they have in normal logical expressions. They are only allowed if wildcards ( '*' or '+' ) are used in the input fields. If wildcards are entered on the selection screen, the system automatically uses the operator CP.
If LS_RANGE-HIGH is filled, you can use BT (BeTween) and NB (Not Between). These operators correspond to BETWEEN and NOT BETWEEN that you use when you check if a field belongs to a range. You cannot use wildcard characters.
You can try:
CLEAR LS_RANGE.
LS_RANGE-SIGN = 'I'.
+LS_RANGE-OPTION = 'CP' +
LS_RANGE-LOW = 'S_ADMI_FCD'.
LS_RANGE-HIGH = 'S_ADMI_FCD'.
FIND '*' IN LS_RANGE.
IF sy-subrc = 0.
LS_RANGE-OPTION = 'CP'.
ELSE.
LS_RANGE-OPTION = 'EQ'.
ENDIF.
COLLECT LS_RANGE INTO LT_RANGE.
SELECT *
FROM UST12
INTO CORRESPONDING FIELDS OF TABLE LT_OBJECT_VALUES
WHERE FIELD IN LT_RANGE
AND AKTPS = 'A'.
If you use wildcards the LS_RANGE length should not exceed 10 characters.
Hope this information is help to you.
Regards,
José -
Pl/sql statement with output in reports
Hello,
I am quite new to reports and pl/sql, i have built a pl/sql statement with some loops that works fine when running it in sqlplus.
I would really like to have this running in reports with the variables (v_year, v_month and v_sumvalue) in a table/record in the data view, so i can use them just like any ordinary fields in a table for example in a diagram.
I have tried to create a package spec, setting up a record with the variables as fields. And then a pl/sql function with the following sql (which was a bit modified to work in the pl/sql function). Everything seemed to work since the pl/sql table/record was there with the variables as fields in it, but it never returned anything... just fatal error.
Here is the original pl/sql statement which is working in sqlplus, any help/directions in how to get this working so i can use the variables like fileds in a regular table would be fantastic:
DECLARE
v_year number(4);
v_month number(2);
v_sumvalue number(9,3);
v_sta varchar2(10);
v_end varchar2(10);
v_stopmonth number(2);
BEGIN
--## Get last 5 years ##--
select
to_char(add_months(sysdate,-60),'YYYY'),
to_char(sysdate,'MM')
into v_year, v_stopmonth
from
dual;
--dbms_output.put_line(v_year);
--## Loop 5 years ##--
for i in 1..5 loop
v_year := v_year + 1;
--dbms_output.put_line(v_year);
--## Loop 12 times (months) ##--
for k in 0..11 loop
v_month := k +1;
--dbms_output.put_line(v_year ||'-'|| v_month);
select
sum(nvl(p.value,0)) / 3,
last_day(add_months(to_date(v_year ||'-'|| v_month ||'-01','YYYY-MM-DD'),-3))+1,
last_day(to_date(v_year ||'-'|| v_month ||'-01','YYYY-MM-DD'))
into v_sumvalue, v_sta, v_end
from
project p
where
p.country_code = 'SWE'
and
p.project_type_code = 'P'
and
p.start_date between last_day(add_months(to_date(v_year ||'-'|| v_month ||'-01','YYYY-MM-DD'),-3))+1 and last_day(to_date(v_year ||'-'|| v_month ||'-01','YYYY-MM-DD'))
and
p.q_category_code between 1000 and 1299
and
p.geography_code between 2100 and 2199;
dbms_output.put_line(v_year ||'-'|| v_month ||' '|| v_sumvalue);
--dbms_output.put_line(v_year ||'-'|| v_month ||' '|| v_sumvalue ||' '|| v_sta ||' '|| v_end);
--## Stop monthloop ##--
end loop;
--## Stop yearloop ##-
end loop;
END;Output:
2003-1 19.1
2003-2 20.1
2007-11 164.5
2007-12 135.167Best regards,
OlleHi,
Maybe pipelined functions will be useful for you:
http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/x/Table_Functions_Cursor_Expressions/Pipelined_Table_Functions.htm
Regards
Jakub Flejmer -
Dynamic SQL Statement with table name
Dear all
i like to have a SQL statement with a dynamic tablename. Is this possible? If yes, how?
should be something like "select * from <mytablename>"
Thank you
HerbertYes this is possible. use the below reference code for this.
data: g_tablename type w_tabname,
gv_dref TYPE REF TO data.
FIELD-SYMBOLS: <g_itab> TYPE STANDARD TABLE.
gv_tabname = p_tablename (take table name form selection screen or as per ur requirement)
CREATE DATA gv_dref TYPE TABLE OF (g_tabname).
ASSIGN gv_dref->* TO <g_itab>.
now use the below select query to fetch the data
SELECT * FROM (gv_tabname) INTO TABLE <g_itab>.
Hope this will help -
How to find sql statement with Unix process pid
Hi
how to find sql statement with Unix process pid
is there any view to find that.
please if so let me know
Thanks in advancethis is how I am doing this:
oracle 7352340 7459066 0 07:47:10 - 0:00 oracleJDERED (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 7459066 5386396 2 07:47:10 pts/1 0:01 sqlplus
select sid,serial# from v$session where process='7459066';
SID SERIAL#
2178 6067
select sql_text
from
v$sqlarea a,
v$session b
where a.hash_value = b.sql_hash_value
and b.sid = 2178
; -
Hello together,
I post this Question here in
Re: SQL-Statement with OO4O
and i should paste my question again in an another database forum.
now here again:
I have here following Problem:
Everthime I make a connection to my database with this code
Set oSess = Server.CreateObject("OracleInProcServer.XOraSession")
Set oDB = oSess.DbOpenDatabase(tnsname, user/PWD, 4)
I get always this Statement in the DB-queue
SELECT parameter, VALUE
FROM SYS.nls_database_parameters
WHERE parameter IN ('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET')
Can me anyone tell me why I get this statement and how I can disable it?
Best Regards
AndyHi,
What can you do/change?I must ask next week my boss when he is back,
what kind of changes I can do.
Can you add a PL/SQL call to DBMS_APPLICATION_INFO into application?my boss must give me the permission to do a call to DBMS_APPLICATION_INFO.
A way to identify the source of the badly behaving code is required; whether that be within the DB or external of it.I think so too.
So please wait, until I have talk with my boss, than I will give you the answer you want. Sorry.
Any other ideas, what I can do without call/changes on the database to find the problem?
Best Regards
Andy -
SQL statement with union clause
Hi,
I have a scenario where i need to generate a sql statement with UNION .
Eg:
SELECT B.YY_ID,
FROM XXXX.YY B
WHERE (B.YY_TY= 'as')
UNION
SELECT B.YY_ID
FROM XXXX.YY_ALT_NAME A, XXXX.YY B
WHERE (A.YY_TY= 'zx'
AND (B.YY_ID=A.YY_ID)"
I tried ns1:table1() union ns3:table2() in XQuery.
But it is pushdown as 2 seperate sqls.
Is it possible to create XQuery that pushdown as SINGLE SQL statement with union clause ?
ThanksNo. See 3.1.1.5 in the document I referenced in your previous post.
-
Multiple left outer join in single select query
My client requires to apply multiple left outer join in single select query.
Tell me how it is possible . tell me if we can use native sql query.HI vineet,
Using multile left join is possible but it reduce performance as it takes a long time to retrieve data.
The following code would help you in knowing how to use multiple left join
REPORT test.
PARAMETERS:
p_auart LIKE vbak-auart.
DATA:
BEGIN OF fs_sales,
auart LIKE vbak-auart,
vbeln LIKE vbak-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
netwr LIKE vbap-netwr,
END OF fs_sales,
fs_temp LIKE fs_sales.
DATA:
t_sales LIKE STANDARD TABLE OF fs_sales.
SELECT k~auart
k~vbeln
p~posnr
p~matnr
p~netwr
INTO TABLE t_sales
FROM vbak AS k
OUTER JOIN vbap AS p
ON k~vbeln = p~vbeln
WHERE auart = p_auart
AND p~netwr LT 1000.
IF sy-subrc EQ 0.
WRITE:/5 'Sales Document'(001),/,
15 'Sales Document Item'(002),
40 'Material Number'(003).
sort t_sales by netwr ascending.
LOOP AT t_sales INTO fs_sales.
WRITE:/ fs_sales-vbeln under text-001.
LOOP AT t_sales INTO fs_temp WHERE vbeln = fs_sales-vbeln.
WRITE:/ fs_temp-posnr under text-002,
fs_temp-matnr under text-003.
ENDLOOP.
ENDLOOP.
ELSE.
MESSAGE 'No Record Found' TYPE 'I'.
ENDIF.
But i would suggest you to go with views instead of using multiple joins..
Best of luck,
Bhumika -
Display the sql statement with arguments with ojdbc14_g.jar
Hi,
I'd like to display the sql statements with ojdbc14_g.jar.
So I've followed the documentation and set an OracleLog.properties file which is linked to my java program.
The problem is the trace generated is huge and I only need the SQL requests wich are made with the arguments but I don't know how to configure that.
Have you got a sample file which handle that ?
I've tried that :
oracle.jdbc.handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=CONFIG
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
oracle.level=INFO
oracle.jdbc.driver.level=OFF
oracle.jdbc.driver.OraclePreparedStatement.level=OFF
oracle.jdbc.pool.level=OFF
oracle.jdbc.util.level=OFF
oracle.sql.level=INFO
But that doesn't display only the SQL and args :(
Regards.The fact is the statement are made by ejb entities on JBoss so I don't have a way to make specific logger to display the sql order. The only thing I can do is to set the log4j org.jboss.ejb.plugins.cmp to a trace level in order to see the sql order but without the arguments.
I tried those traces however I see stuff like that without any SQL orders :
<<
10:10:53,833 INFO [STDOUT] NFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:52 oracle.jdbc.driver.PhysicalConnection getRemarksReporting
INFO: PhysicalConnection.getRemarksReporting()
29 nov. 2007 10:10:52 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:52 oracle.jdbc.driver.PhysicalConnection getDefaultFixedString
INFO: PhysicalConnection.getDefaultFixedString() returning false
29 nov. 2007 10:10:52 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=1, x=%)
29 nov. 2007 10:10:52 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=2, x=VIEW_ACTION_NAMES)
29 nov. 2007 10:10:52 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:52 oracle.jdbc.driver.T4CPreparedStatement allocateTmpByteArray
GRAVE: oracle.jdbc.driver.T4CPreparedStatement.allocateTmpByteArray : Re-allocate byte array of size : 4000
29 nov. 2007 10:10:52 oracle.jdbc.driver.OracleResultSetImpl close
INFO: OracleResultSetImpl.close()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getMetaData
INFO: PhysicalConnection.getMetaData()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getCatalog
INFO: PhysicalConnection.getCatalog()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRemarksReporting
INFO: PhysicalConnection.getRemarksReporting()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRemarksReporting
INFO: PhysicalConnection.getRemarksReporting()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getDefaultFixedString
INFO: PhysicalConnection.getDefaultFixedString() returning false
29 nov. 2007 10:10:53 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=1, x=%)
29 nov. 2007 10:10:53 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=2, x=PROCESS_TYPE_HIERARCHY)
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.T4CPreparedStatement allocateTmpByteArray
GRAVE: oracle.jdbc.driver.T4CPreparedStatement.allocateTmpByteArray : Re-allocate byte array of size : 4000
29 nov. 2007 10:10:53 oracle.jdbc.driver.OracleResultSetImpl close
INFO: OracleResultSetImpl.close()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getMetaData
INFO: PhysicalConnection.getMetaData()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getMetaData
INFO: PhysicalConnection.getMetaData()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getCatalog
INFO: PhysicalConnection.getCatalog()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRemarksReporting
INFO: PhysicalConnection.getRemarksReporting()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRemarksReporting
INFO: PhysicalConnection.getRemarksReporting()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getDefaultFixedString
INFO: PhysicalConnection.getDefaultFixedString() returning false
29 nov. 2007 10:10:53 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=1, x=%)
29 nov. 2007 10:10:53 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=2, x=PROCESS_TYPE_HIERARCHY)
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.T4CPreparedStatement allocateTmpByteArray
GRAVE: oracle.jdbc.driver.T4CPreparedStatement.allocateTmpByteArray : Re-allocate byte array of size : 4000
29 nov. 2007 10:10:53 oracle.jdbc.driver.OracleResultSetImpl close
INFO: OracleResultSetImpl.close()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getMetaData
INFO: PhysicalConnection.getMetaData()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getCatalog
INFO: PhysicalConnection.getCatalog()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRemarksReporting
INFO: PhysicalConnection.getRemarksReporting()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRemarksReporting
INFO: PhysicalConnection.getRemarksReporting()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getDefaultFixedString
INFO: PhysicalConnection.getDefaultFixedString() returning false
29 nov. 2007 10:10:53 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=1, x=%)
29 nov. 2007 10:10:53 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=2, x=FORM_EMBEDDED_VIEWS)
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.T4CPreparedStatement allocateTmpByteArray
GRAVE: oracle.jdbc.driver.T4CPreparedStatement.allocateTmpByteArray : Re-allocate byte array of size : 4000
29 nov. 2007 10:10:53 oracle.jdbc.driver.OracleResultSetImpl close
INFO: OracleResultSetImpl.close()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getMetaData
INFO: PhysicalConnection.getMetaData()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getMetaData
INFO: PhysicalConnection.getMetaData()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getCatalog
INFO: PhysicalConnection.getCatalog()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRemarksReporting
INFO: PhysicalConnection.getRemarksReporting()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRemarksReporting
INFO: PhysicalConnection.getRemarksReporting()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getDefaultFixedString
INFO: PhysicalConnection.getDefaultFixedString() returning false
29 nov. 2007 10:10:53 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=1, x=%)
29 nov. 2007 10:10:53 oracle.jdbc.driver.OraclePreparedStatement setString
INFO: OraclePreparedStatement.setString(paramIndex=2, x=FORM_EMBEDDED_VIEWS)
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getRestrictGetTables
INFO: PhysicalConnection.getRestrictGetTables() returned false
29 nov. 2007 10:10:53 oracle.jdbc.driver.T4CPreparedStatement allocateTmpByteArray
GRAVE: oracle.jdbc.driver.T4CPreparedStatement.allocateTmpByteArray : Re-allocate byte array of size : 4000
29 nov. 2007 10:10:53 oracle.jdbc.driver.OracleResultSetImpl close
INFO: OracleResultSetImpl.close()
29 nov. 2007 10:10:53 oracle.jdbc.driver.PhysicalConnection getMetaData
INFO: PhysicalConnection.getMetaData()
29 nov. 20>> -
How to Run SQL Tuning Advisor on the SQL statement with SQL_ID?
Can you give the steps to run the SQL tuning advisor on the SQL statement with SQL_ID?
Database version: 10g Release 2Hi,
You can use either the automatic SQL tuning features that are accessible from Enterprise Manager Database Console on the "Advisor Central" page or trough SQL*PLUS using the DBMS_SQLTUNE pakage:
-- creating the tuning task
set serveroutput on
declare
l_sql_tune_task_id varchar2(100);
begin
l_sql_tune_task_id := dbms_sqltune.create_tuning_task (
sql_id => '<your_sql_id>',
scope => dbms_sqltune.scope_comprehensive,
time_limit => 60,
task_name => '<your_tuning_task_name>',
description => 'tuning task for statement your_sql_id.');
dbms_output.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
end;
-- executing the tuning task
exec dbms_sqltune.execute_tuning_task(task_name => '<your_tuning_task_name>');
-- displaying the recommendations
set long 100000;
set longchunksize 1000
set pagesize 10000
set linesize 100
select dbms_sqltune.report_tuning_task('<your_tuning_task_name>') as recommendations from dual;For more information, take a look at link provided by Jaffy.
Cheers
Legatti -
SQL statement with LIMIT and total count?
Hello,
I would like to know if it is possible to execute a single SQL statement that will return me a subset of data (for pagination purposes) that not only includes the subset of data for the page but the count of all available data. Can this be done so as to not take up the cpu and time it takes to essentially run two queries? One to get the subset and one to get the count? I think simply doing a subselect is not going to give me what I want in that we actually query twice.
There may be no way to do this other than that, but I wanted to check with the gurus here first. :)
Thanks,
Markselect *
from (
select i.*,
row_number() over(order by i) rn, -- used for
pagination
count(*) over(partition by 1) cnt -- total count
of rows found for this search
from mytable
where < PUT ALL LIMITING (i.e., "search") CONDITIONS
HERE >
where rn between 41 and 50 -- pagination clauseNice one
BUT of course it adds additional row in execution plan and takes additional time and CPU :)
I assume that it directly depends of course on returned result set and some other factors like available sort space but a simple test case on a table big which actually is 1.6 M rows like dba_source got following results:
here is the first one returning also count(*)
SQL> select *
2 from (
3 select i.*,
4 row_number() over(order by owner, name, type) rn
5 , -- used for pagination
6 count(*) over(partition by 1) cnt -- total count of rows found for this search
7 from big i
8 where owner like 'S%' and name like '%A%'
9 )
10 where rn between 41 and 45
11 /
OWNER NAME TYPE
LINE
TEXT
RN CNT
SYS ANYDATA TYPE
13
STATIC FUNCTION ConvertVarchar(c IN VARCHAR) return AnyData,
41 999744
SYS ANYDATA TYPE
11
STATIC FUNCTION ConvertDate(dat IN DATE) return AnyData,
42 999744
SYS ANYDATA TYPE
9
43 999744
SYS ANYDATA TYPE
7
They serve as explicit CAST functions from any type in the Oracle ORDBMS
44 999744
SYS ANYDATA TYPE
6
enable construction of the AnyData in its entirity with a single call.
45 999744
Elapsed: 00:00:41.02
SQL> ed
Wrote file afiedt.buf
1 select n.name, m.value from v$statname n, v$mystat m
2 where n.statistic# = m.statistic#
3* and (upper(name) like '%SORT%' or upper(name) like '%TEMP%')
SQL> /
NAME VALUE
physical reads direct temporary tablespace 35446
physical writes direct temporary tablespace 17723
RowCR attempts 0
SMON posted for dropping temp segment 0
sorts (memory) 36
sorts (disk) 1
sorts (rows) 1999596
OTC commit optimization attempts 0
8 rows selected.here is the second one returning only rows:
SQL> ed
Wrote file afiedt.buf
1 select *
2 from (
3 select i.*,
4 row_number() over(order by owner, name, type) rn
5 --, -- used for pagination
6 -- count(*) over(partition by 1) cnt -- total count of rows found for this search
7 from big i
8 where owner like 'S%' and name like '%A%'
9 )
10* where rn between 41 and 45
SQL> /
OWNER NAME TYPE
LINE
TEXT
RN
SYS ANYDATA TYPE
13
STATIC FUNCTION ConvertVarchar(c IN VARCHAR) return AnyData,
41
SYS ANYDATA TYPE
11
STATIC FUNCTION ConvertDate(dat IN DATE) return AnyData,
42
SYS ANYDATA TYPE
9
43
SYS ANYDATA TYPE
7
They serve as explicit CAST functions from any type in the Oracle ORDBMS
44
SYS ANYDATA TYPE
6
enable construction of the AnyData in its entirity with a single call.
45
Elapsed: 00:00:12.09
SQL> select n.name, m.value from v$statname n, v$mystat m
2 where n.statistic# = m.statistic#
3 and (upper(name) like '%SORT%' or upper(name) like '%TEMP%')
4 /
NAME VALUE
physical reads direct temporary tablespace 0
physical writes direct temporary tablespace 0
RowCR attempts 0
SMON posted for dropping temp segment 0
sorts (memory) 10
sorts (disk) 0
sorts (rows) 999812
OTC commit optimization attempts 0
8 rows selected.So execution time 41 sec vs 12 sec
sorts (rows) 1 999 596 vs 999 812
physical reads/writes direct temporary tablespace 35446/17723 vs 0/0
I assume that for a small overall returned row count it probably is OK, but for less restrictive search it can be quite deadly as before with two queries.
Gints Plivna
http://www.gplivna.eu -
2 set of conditions to use in a Single Select query in procedure
Good day
I have one procedure, want to use one 2 set of conditions in Where clause
like
where condition1 < value
AND condition 2 > value
AND condition 3 = value
where condition 1 > value
AND condition 2 < value
AND condition 4 = value
How we should combine in a single select statement where cluase.
Please accept my sincere thanks first and looking your advice asap.
Regards
M.K.ThamaraiselvanHi,
While we use this procdure to run at that time it is not picking up any values also it is not running in it, taking very long time.What is not picking the value? Where clause is not picking the value, or
where clause is picking the value but you are not getting the output.
If it is you are not getting the output.
I suggest to run the sql query individually without pl/sql and check if the records actually exist.
Since it is taking very long time, I feel the sql query is actually being executed in the database but could be you are not getting the records (check if records actualy exist or if you are correctly passing the where clause)
Regards
Anurag
PS:
v_sql_string := 'SELECT table/viewname.colomn_name,'||v_order_by||','||v_report_line ||','||
v_output_line||',table/viewname.check_amount'||v_from_clause||v_where_clause||' ORDER BY '||v_order_by;So you are using dynamic sql, can you add an extra line
dbms_output.put_line(v_sql_string);
and check what the actual query is formed by pl/sql, if you are satisified the query is correct run it through sql plus and check why oracle does not give the result. MAy be there is no records satisfiying this condition. And I am sure you meant either table or viewname in (table/viewname.colomn_name) and not something like what you posted.
Edited by: Anurag Tibrewal on Oct 8, 2009 9:15 AM -
Select query inside PL/SQL block.
Hello Experts,
I am just a beginner with PL/SQL.
If I write a select query from client like SQL dev and fire it against a database, it gives me result.
Eg: select * from employee;
Now when I use the same Query inside a PL/SQL block suppose:
Declare
begin
select * from employee;
end;
This gives error on execution, mentioning that an INTO is expected etc...
I have doubts here:
1. Can't I use a plain select inside a PL/SQL block (if so why?)
I know this is kind of very basic question, I tried searching this on the forum but could not find the thread, please redirect me to the link if this is already answered.user8578271 wrote:
Hello Experts,
I am just a beginner with PL/SQL.
If I write a select query from client like SQL dev and fire it against a database, it gives me result.
Eg: select * from employee;
Now when I use the same Query inside a PL/SQL block suppose:
Declare
begin
select * from employee;
end;
This gives error on execution, mentioning that an INTO is expected etc...
I have doubts here:
1. Can't I use a plain select inside a PL/SQL block (if so why?) Because when you run a query in a tool like SQL Developer, or SQL*Plus or TOAD etc. then it opens up a cursor and fetches the data into internal memory structures before displaying it, and that is all done automatically and hidden from you. In PL/SQL, there is no interface to display the results of SQL queries, so you have to specifically tell it what to put the data into.
The syntax is (in basic terms)...
SELECT column1, column2... columnX
INTO variables or record structure
FROM ...Though that can only select a single row of data. If your query returns more than 1 row it will give a TOO_MANY_ROWS exception. If your query returns no rows you will get a NO_DATA_FOUND exception.
If you need to select multiple rows into variables etc., then you would need to "BULK COLLECT" into a collection/array structure, though this takes up valuable memory on the server and shouldn't be used unless necessary (and you understand the implications of doing it). -
USING MULTIPLE SELECT VARIABLE IN A SQL STATEMENT
In HTMLDB, the value of the parameter of a multiple select box is colon delimited(ie P6_Name = Smith:Jones:Burke). Is there an easy way to use this parameter in a SQL statement?
Example
Select *
from names
where
Name=P6_Name
Select *
from names
where
Name IN ('Smith','Jones','Burke')
Thank youThank you for your response! I'm an idiot. It didn't make sense to me because your talking about a <i>multi-select</i> variable and I was thinking about a <i>select-list</i> variable. My problem is that I need to assign a list of values to one select list item.
<br>
For example:
<br>
SELECT * FROM EMPLOYEE
WHERE EMPLOYEE_TYPE IN ( :SELECT_LIST_RETURN_VALUE );
<br><br>
With the select list as
<br><br>
Display value = All Types, Some Types, One Specific Type<br>
Return Value = (Type1, type2, type3), (type1, type2), (type3)
<br><br>
I've just started in all of this so I'd imagine that I'm probably going about it wrong. -
Select query in Advanced SQL Filter
Hi All
I am creating a shared filter and I need to write an sql statement for a column. Can I use
string functions in the Advanced SQL Filter. My sql query is :
select distinct "Exchange Rate"."Type" from "Credit"
where substr(rtrim("Exchange Rate"."Type"),-1,2) in (select distinct substr(rtrim( "-Year"."Year Name"),-1,2)
from "Credit" where CURRENT_DATE between "-Year"."Year Start Date" and "-Year"."Year End Date" )
where, "Credit" = Name of the subject area
"Exchange Rate" and "-Year"= presentation tables
I'm getting the error:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <select>: Syntax error [nQSError: 26012] . (HY000)
I then tried a simple query in the Advanced SQL Filter: "Exchange Rate"."Type" = SELECT "Exchange Rate"."Type" FROM "Credit"
which does not work either.
Can't seem to debug the problem.
ThanksHi user770000,
How did you resolve the issue. I am trying to use the sql query in the filter and getting same error as yours.
Here is the advanced SQL of the filter condition
CAST("ARRA Financial Weekly Report"."DW Updated" AS DATE) = SELECT MAX(CAST("ARRA Financial Weekly Report"."DW Updated" AS DATE)) from "ARRA Recovery Act Status"
When I issue following sql in direct sql, it returns required value
SELECT MAX(CAST("ARRA Financial Weekly Report"."DW Updated" AS DATE)) from "ARRA Recovery Act Status"
Maybe you are looking for
-
How do I send a photo via email ?
I am connecting to Internet through the Opera Mini browser installed on Nokia C3, however, when I try to send a photo as an attachment, the uploading hangs just when the progress bar shows that it reached 100%. Is this some software easter bug or can
-
My new computer is "offline" to Aperture
I bought a new laptop to replace a previous one. I used Migration Manager. All the photo files and the Aperture Library are where they previously were. I renamed the HD on the new computer to match that of the old. I am the same user name and passwor
-
Problem with JFMERGE using the last set of data on all form sets
b Here is the scenario... I have a file of data in character delimited format. Each record needs to produce the same set of forms. I used the Visual Transformation Editor to define the field nominated data file, including the ^form statements. The tr
-
Need assistance from Verizon with a faulty phone.
Hi there, I purchased the Droid Razr a couple of months back. Has been a great phone up until about a week ago. Since then there have been an increasing amount of problems, like when i try to activate the camera or video camera my phone freezes up an
-
Looking to change the names of files all at once as opposed to doing it individually. example: Change "01-Song.aif" to "POS-01-Song.aif" and "02-Song.aif" to "POS-02-Song.aif" etc... all at once. Wondering if this is possible and if so, how??? Thanks