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,
Olle
Hi,
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
Similar Messages
-
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.
-
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é -
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 Function returns slow in Interactive Report
I have an Interactive Report that returns well but when I add in a function call in the where clause that does nothing but return a hard coded string of primary keys and is compared to a table's primary key with a like operator the performance tanks. Here is the example:
get_school2_section(Y.pk_id,M.pk_id,I.section,:P577_SECTION_SHUTTLE) LIKE '%:' || I.pk_id || ':%'
I have the values hard coded in the return of the function. There are no cursors run in the function, there is no processing done in the function. It only declares a variable. Sets the variable, and returns that variable back to the SQL statement.
I can hard code the where clause value to look like this:
':90D8D830A877CCFFE040010A347D1A50:8ED0BBFDEAACC629E040010A347D6471:9800B8FDBD22B761E040010A347D0D9A:' LIKE '%:' || I.pk_id || ':%'
This returns fast. When I add in the function call which returns the same hard coded values, the page goes from returning in 1 to 2 seconds to 45 or more seconds.
Why does adding a simple function call into the where clause cause such a deterioration in performance.
Edited by: alamantia on Aug 17, 2011 7:39 AM
Edited by: alamantia on Aug 17, 2011 7:40 AMSo you are telling me that the where clause with a function call will NOT run the function on every row? Please explain that to me further?
if you have code that is the following:
select a,b,c from a_table where a > 2 and b < 3 and function_call(c) > 0You are telling me that Oracle will NOT call that function on EVERY row it tries to process in the select?
Thank you,
Tony Miller
Webster, TX
I cried because I did not have an office with a door until I met a man who had no cubicle.
-Dilbert
If this question is answered, please mark the thread as closed and assign points where earned.. -
Same sql statement gives output in different lines in 12.1.3 vs 11i
Hi all,
DB:11.2.0.3.0
EBS:11i and 12.1.3
O/S: Solaris SPARC 64 bits 5.10
The below query gives the output in one line in 11i as expected but it gives the output in two separate lines in 12.1.3. Are there any server level settings for linesize and pagesize to be performed?
set term off;
set serveroutput on size 1000000;
set feedback off;
set pagesize 0;
set head off;
set linesize 72;
set pause off;
set colsep '';
select
lpad(code_combination_id,15,0)||
rpad(to_char(start_date_active,'YYYYMMDD'),8,' ')||
rpad(to_char(end_date_active,'YYYYMMDD'),8,' '),
substr(SEGMENT1,1,3)|| --entity
rpad(substr(SEGMENT2,1,6),6,' ')|| --account
rpad(substr(SEGMENT3,1,5),5,' ')|| --costcenter
rpad(substr(SEGMENT4,1,6),6,' ')|| --activity
substr(SEGMENT6,1,3)|| --product
substr(SEGMENT7,1,3)|| --service
substr(SEGMENT5,1,3)|| --country
substr(SEGMENT8,1,3)|| --intercompany
rpad(substr(SEGMENT9,1,8),8,' ')|| --regional
substr(enabled_flag,1,1) -- active flag
from gl_code_combinations
where last_update_date >=
(select nvl(max(actual_start_date),'01-JAN-1951')
from fnd_concurrent_requests
where concurrent_program_id = (select concurrent_program_id
from fnd_concurrent_programs
where
concurrent_program_name = 'XYZACCT')
and status_code = 'C'
and actual_completion_date is not null)
order by 1;
OUTPUT in 11i
============
00000000000100020120930 7014912000000000000000000000000000000000Y
00000000000100120120930 5014912000000000000000000000000000000000Y
OUTPUT in 12.1.3
==============
00000000000116020120930
4881124010000000000000000000000000000000Y
000000000001161
6103229990000000000000000000000000000000Y
11i and 12.1.3 should get the output in one line as per the above sql statement.
Could anyone please share the fix on the above issue?
Thanks for your time
Regards,Hi,
Can you confirm in what session are you running this query.
Try this
Column Code_Date_Range format a25
Column Segments format a50
set lines 300
set pages 200
set term off;
set serveroutput on size 1000000;
set feedback off;
set pagesize 0;
set head off;
set linesize 72;
set pause off;
set colsep '';
select
lpad(code_combination_id,15,0)||
rpad(to_char(start_date_active,'YYYYMMDD'),8,' ')||
rpad(to_char(end_date_active,'YYYYMMDD'),8,' ') Code_Date_Range,
substr(SEGMENT1,1,3)|| --entity
rpad(substr(SEGMENT2,1,6),6,' ')|| --account
rpad(substr(SEGMENT3,1,5),5,' ')|| --costcenter
rpad(substr(SEGMENT4,1,6),6,' ')|| --activity
substr(SEGMENT6,1,3)|| --product
substr(SEGMENT7,1,3)|| --service
substr(SEGMENT5,1,3)|| --country
substr(SEGMENT8,1,3)|| --intercompany
rpad(substr(SEGMENT9,1,8),8,' ')|| --regional
substr(enabled_flag,1,1) Segments -- active flag
from gl_code_combinations
where last_update_date >=
(select nvl(max(actual_start_date),'01-JAN-1951')
from fnd_concurrent_requests
where concurrent_program_id = (select concurrent_program_id
from fnd_concurrent_programs
where
concurrent_program_name = 'XYZACCT')
and status_code = 'C'
and actual_completion_date is not null)
For more details, please see:
Formatting SQL*Plus Reports
Thanks &
Best Regards -
Execute Stored Procedure SQL Statement with Parameter from Cell
I would like to know if there is a way to pass the parameters to SQL Statement of Power Query. For example, I have a SQL Statement as follows:
EXEC [dbo].[spReportBuilder]
@Report = N'Revenue Summary',
@Year = N'2014',
@Period = N'11'
I would like to know if it is possible to pass the @Report, @Year, @Period values from cells in the workbook, preferably without vba.
Thanksrtisserand,
Here is the M code:
let
IDValue = Excel.CurrentWorkbook(){[Name="YearTable"]}[Content],
Source = Sql.Database("localhost", "AdventureWorks2012", [Query="EXEC [dbo].[spReportBuilder] @Report = N'Revenue Summary', @Year = N'" & Number.ToText(IDValue[ID]{0}) & "', @Period = N'11'"])
in
Source
Some notes:
You have to reference the excel query from another step in the query or you will get the following error:
Formula.Firewall: Query <>something<> references other queries or steps and so may not directly access a data source. Please rebuild this data combination.
I only did the parameter for one value.
Hope this helps.
Reeves
Denver, CO -
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
SivaramanHi,
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 -
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 -
How to run a sql statement with bind variable in a test environment
Hello,
I have a sql statement in prod that I like to run in test. I got the sql statement from statspack, but the statement has bind variables. How do I get this statement to run in test? Thank you.Hi,
If you have the SQL statement and all the referenced objects are available in your test env then what is the problem to run it?
If I am not wront to get your reqmnt...
i.e
SQL> select * from emp
where emp_no = &empno
and dept_code = &deptcode;
Thanks -
Dynamic SQL Statements with an JDBC Adapter
Hello,
i have a simple scenario:
A WebService calls SAP XI and XI has convert this request into an dynamic SQL for a particular DB-Table.
Two Questions:
1. Can this done with an JDBC-Receiverchannel or do i have to write a Java Server-Proxy?
2. How do i bring dynamic SQL Stratement into the JDBC Receiver-Adapter?
Regard
GunnarI think you should be able to achieve this using the SQL_QUERY / SQL_DML action in the JDB receiver adapter...
The SQL string can be dynamically created....
see the help link on different document types with JDBC receiver adapater....look for statement6...
http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm
<StatementName6>
<anyName action= SQL_QUERY | SQL_DML>
<access>SQL-String with optional placeholder(s)</access>
<key>
<placeholder1>value1</placeholder1>
<placeholder2>value2<placeholder2>
</key>
</anyName >
</StatementName6>
Thanks,
Renjith
Maybe you are looking for
-
HT5517 Is there a way to select multiple speakers from my ATV3?
I have ATV3, an iPad2, a Sony Vaio laptop and another audio system connected to my WiFi network via an Airport Express. Via ATV I can only select one speaker / output at a time (i.e. EITHER Airport Express OR ATV). When I have a party in the house (
-
How to move data of LONG RAW column to another table?
I want to transfer the Long Raw datatype from A ( a Long Raw) to B (b Long Raw) in PL/SQL. The data of a colum is bigger than 32KB Pls help me to advise how to do that? Thanks a lot for your reply.
-
Hi. I don?t speak( or write)English very good so i?ll be quick. My program will display 4 "panels". (it�s like a test for your bad habits) On the first, you ?ll input some general facs like name, age, etc(in JTextfields). On the second, third, and fo
-
Hi, We have ECC5.0 and ESS/MSS on EP6. We are unable to view the Payslip of the current month ,at the Portal end but at the R/3 end we are able to see the Payslip generated. whats the step that i am missing ? We are able to see the previous months' p
-
I have just started using iPhone 4s and cannot find how to delete photos. Have used iPhone 3 GS for last 2 years and not had this problem. I have iCloud for my Apple family and don't know if this is causing problem. Help please.