sys_refcursor outside procedure parameters
HelloI created a procedure who receive the SQL to VARCHAR' datatype settings and return the result in a refcursor set:
create or replace
procedure my_test(VAL1 in number, val2 in number, val3 in number, val4 in VARCHAR2, vla5 out nocopy SYS_REFCURSOR )
is
begin
open vla5 for 'select * FROM (select x_x.* ,rownum rn FROM ('||val4 ||') x_x where rownum <= '|| to_char(val3)||' ) where rn >='|| to_char(val2);
end;
I like to spend and receive val4 and val5 in a settings:procedure my_test(VAL1 in number, val2 in number, val3 in number, val4 in out nocopy SYS_REFCURSOR )
I would like to pass the SQL statement to the VARCHAR2 data type to my procedure and return the result in the same variable settings.I don't know if my English was understanding, but could you please help me find a solution?
Thank you very much.
Salvatore of Cala
Can we have more details please?
A sys_refcursor isn't a SQL statement you can add predicates. So it is not possible to combine the two arguments. Not at all.
To receive a refcursor and try to do is not make sense.
See Refcursor 101 thread:
PL/SQL 101: Understand the Ref Cursor
If you receive a SQL as a CLOB to VARCHAR2/LONG you want and wrap with more predicates then you can do that just with string manipulation - you do.
However, if you receive a SQL string and want to wrap up with one statement select and other predicates, you use binds to the underlying values not string concatenation of literals which is likely to be bad performance and a possible security problem (see also DBMS_ASSERT).
Published by: DomBrooks on November 9, 2010 11:00
Tags: Database
Similar Questions
-
Cannot access stored procedure parameters
Hello
We are at the point where you try to use a stored procedure from our Java through Toplink code but we seem to have a problem here I couldn't find an answer to. Maybe it's that my Google-Fu is miss you in this case.
Our problem is thto so that the procedure seems to be cited correctly, we get nothing to Java code. The procedure in question has been tested with the same input parameters of SQLDeveloper and the procedure returns values as it should.
The procedure signature is
create or replace PACKAGE FORM_METADATA AS
PROCEDURE FORM_LIST_GET)
P_USER_ID IN VARCHAR2,
P_CHANNEL_NO NUMBER,
P_START_FROM in NUMBERS, paging
P_COUNT_TO_RETURN in NUMBERS, paging
P_GET_TOTAL_COUNT in NUMBER, - if number must total be returned then 1, other wise 0
P_RESULT_SET ON SYS_REFCURSOR,
P_TOTAL_COUNT CERTAIN NUMBER);
end FORM_METADATA;
Java code invoking this procedure looks like this:
County of BigDecimal = new BigDecimal(-1);
A session = getSession().
session.setLog (new OutputStreamWriter (System.out));
session.setLogLevel (SessionLog.FINEST);
StoredProcedureCall procedureCall = new StoredProcedureCall();
procedureCall.setProcedureName "(FORM_METADATA. FORM_LIST_GET");
procedureCall.addNamedArgumentValue ("P_USER_ID", "name of user-1");
procedureCall.addNamedArgumentValue ("P_CHANNEL_NO", new BigDecimal (1));
procedureCall.addNamedArgumentValue ("P_START_FROM", new BigDecimal (1));
procedureCall.addNamedArgumentValue ("P_COUNT_TO_RETURN", new BigDecimal (1000));
procedureCall.addNamedArgumentValue ("P_GET_TOTAL_COUNT", new BigDecimal (1));
procedureCall.useNamedCursorOutputAsResultSet ("P_RESULT_SET");
procedureCall.addNamedOutputArgument ("P_TOTAL_COUNT", "count", BigDecimal.class);
DataReadQuery dq = new DataReadQuery();
dq.setCall (procedureCall);
dq.prepareForExecution ();
Object result = session.executeQuery (dq);
System.out.println ("result:" + result);
System.out.println ("result from StoredProcedreCall:" + procedureCall.getResult ());
The output we get looks like this:
[Warning TopLink]: 2015.08.31 16:11:30.781 - failed to get InitialContext for saving of MBean: javax.naming.NoInitialContextException: need to specify the class name in the environment or property of the system, as a cmdlet parameter or in a file of application resources: java.naming.factory.initial
[Warning TopLink]: 2015.08.31 16:11:30.797 - failed to get InitialContext for saving of MBean: javax.naming.NoInitialContextException: need to specify the class name in the environment or property of the system, as a cmdlet parameter or in a file of application resources: java.naming.factory.initial
[TopLink info]: 2015.08.31 16:11:31.685 - DatabaseSessionImpl (1827000661) - TopLink, version: Oracle TopLink - 11 g Release 1 (11.1.1.5.0) (Build 110305)
[TopLink info]: 2015.08.31 16:11:34.147 - DatabaseSessionImpl (1827000661) - dev connection successful
[TopLink Finest]: 2015.08.31 16:11:34.147 - DatabaseSessionImpl (1827000661) - wire (wire [main, 5, main])-Execute query DataReadQuery()
[TopLink Finest]: 2015.08.31 16:11:34.163 - DatabaseSessionImpl (1827000661) - wire (wire [main, 5, main])-re-connect to the external connection pool
[TopLink fine]: 2015.08.31 16:11:34.227 - DatabaseSessionImpl (1827000661) - connection (1635575430) - wire (wire [main, 5, main])-START FORM_METADATA. FORM_LIST_GET (P_USER_ID = >?, P_CHANNEL_NO = >?, P_START_FROM = >?, P_COUNT_TO_RETURN = >?, P_GET_TOTAL_COUNT = >?, P_RESULT_SET = >?, P_TOTAL_COUNT = >?); END;
link = > [name of user-1, 1, 1, 1000, 1, = > P_RESULT_SET = > P_TOTAL_COUNT]
[Result:]
Result of the StoredProcedreCall: null
Process has finished with exit code 0.
I'm pretty sure that our problem is with Java code invoking the procedure, but as I said, we were not able to find the right solution yet. Anyone have a pointer as to where we should begin to look for next?
Thank you in advance,
Mika Leino
One of my colleagues managed to find the reason why the procedure does not seem to return anything. For brevity, I've redacted a couple of settings that we were not used to this forum and we do not believe the reason for the perceived behavior. However, as well as the required parameters these have the value NULL. My colleague seems to try initialize parameters without value and after that the query returned a set of data that was expected.
Our change of code (in Java) was therefore to spend
procedureCall.addNamedArgumentValue("P_ORDER_BY", OracleTypes.NULL);
TO
procedureCall.addNamedArgument("P_ORDER_BY");
Now we're getting data from the cursor, as expected, but the second parameter value still eludes us.
-
Get the EXIT and the RETURN of a stored procedure parameters
I have a stored procedure (SQL Server 2008 R2 MS) as in the following example.
Thanks to the connectivity of database I get OUTPUT parameters, but I can't get the game DATA RECORDS and RETURN value.
Someone knows how to do this?
CREATE PROCEDURE [dbo]. [TS_Teste] (@T057_S_NOMEMAQUINA VARCHAR (20), @STATUS INT OUTPUT, OUTPUT OF NVARCHAR (500) OF @ERRO)
AS
BEGIN
DECLARE THE TABLE @TABLE (CODE INT, DESCRIPTION VARCHAR (30))INSERT VALUES INTO @TABLE (51, 'A')
INSERT VALUES INTO @TABLE (52, 'B')INSERT VALUES INTO @TABLE (53, 'C')
SELECT * FROM @TABLE
SET @STATUS = 1
SET @ERRO = "Nenhum erro!
RETURN 0
END
I finally found what was wrong... He had a line in the stored procedure only aditional. It should be like this:
CREATE PROCEDURE [dbo]. [TS_Teste] (@T057_S_NOMEMAQUINA VARCHAR (20), @STATUS INT OUTPUT, OUTPUT OF NVARCHAR (500) OF @ERRO)
AS
BEGIN
SET NOCOUNT ON; -NEW LINE!DECLARE THE TABLE @TABLE (CODE INT, DESCRIPTION VARCHAR (30))
INSERT VALUES INTO @TABLE (51, 'A')
INSERT VALUES INTO @TABLE (52, 'B')INSERT VALUES INTO @TABLE (53, 'C')
SELECT * FROM @TABLE
SET @STATUS = 1
SET @ERRO = "Nenhum erro!
RETURN 0
END
-
Hello
There is only one version of procedures packed with parameters that are called in the following diagram.Package test
Instead of passing parameters of the procedure for the procedure to be used in the last procedure, namely in test2, I consider to change the schema above and declare a packaged global variable which are available to all procedures in the package...
function A(p1)
as
begin
return x;
end;
procedure test1(x1 ..... ,
x2 tab%rowtype)
as
local_1 .....;
begin
....
local_:=A(p=>....); /*the function is called*/
test2(x3=>x1,
x2=>x4); /*the below procedure is called*/
end;
procedure test2(x3 .....,
x4 tab%rowtype)
as
begin
..... /*before the commit another procedure
is called (which is also declared in this package
but is not written here....)*/
insert into .....
commit;
end;
Something like...package test
Is there another way...?
as
x1 ......;
x2 tab%rowtype;
<other variables>
function A;
procedure test1;
procedure test2;
......
Note: I use DB 10.2.0.4
Thank you
SIMthe only danger is almost simultaneously in the same session
two executions of the packaged procedures/functions are runningBut that can never happen.
A session is single-threaded (I don't know if it's the correct term).
You cannot run two... things... at the same time.
-
How to use the nocopy with java stored procedures parameters
-------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production PL/SQL Release 11.2.0.3.0 - Production CORE 11.2.0.3.0 Production TNS for Linux: Version 11.2.0.3.0 - Production NLSRTL Version 11.2.0.3.0 - Production
I'm a PL/SQL programmer, but not a Java programmer. I have the following java function that does what it's supposed to add a pdf at the end of another pdf document:
import oracle.sql.BLOB; import org.apache.pdfbox.util.PDFMergerUtility; import oracle.jdbc.OracleConnection; import oracle.jdbc.driver.OracleDriver; import java.io.OutputStream; public class PDFUtilities { public static BLOB appendPDF(BLOB pdfdoc1, BLOB pdfdoc2) throws Exception { //create a connection object to the current instance OracleConnection conn = (OracleConnection)new OracleDriver().defaultConnection(); //create the output blob using the connection BLOB outPDF = BLOB.createTemporary(conn, true ,BLOB.DURATION_SESSION); //create an output stream to the output blob OutputStream os = outPDF.setBinaryStream(0); //instantiate the pdf merger utility PDFMergerUtility mergerUtility = new PDFMergerUtility(); //connect the merger to the output stream mergerUtility.setDestinationStream(os); //stream from each input blob into the merger utility mergerUtility.addSource(pdfdoc1.getBinaryStream()); mergerUtility.addSource(pdfdoc2.getBinaryStream()); //merge the 2 input pdfs mergerUtility.mergeDocuments(); //do not close the output stream //return the blob return outPDF; } }
CREATE OR REPLACE package PDFTOOLS.pkg_pdf_utilities as function f_get_merged_pdf ( pi_pdf1 blob , pi_pdf2 blob ) return blob; end pkg_pdf_utilities; / CREATE OR REPLACE package body PDFTOOLS.pkg_pdf_utilities as function f_get_merged_pdf ( pi_pdf1 blob , pi_pdf2 blob ) return blob as language java name 'com.mycode.pdftools.PDFUtilities.appendPDF(oracle.sql.BLOB, oracle.sql.BLOB) return oracle.sql.BLOB'; end PDFTOOLS.pkg_pdf_utilities; /
It's very basic, but doesn't seem to work. However, I want to my function from PL/SQL to a procedure that looks like this:
CREATE OR REPLACE package PDFTOOLS.pkg_pdf_utilities as procedure sp_append_pdf ( pio_pdf2append2 IN OUT NOCOPY blob , pio_pdf2append IN OUT NOCOPY blob ) end pkg_pdf_utilities; /
What is important, what I'm trying to do is to NOCOPY the BLOBs. Otherwise, I have to read my PDF files into 2 BLOBs and create a 3rd blob as output. I prefer to be able to keep the pio_pdf2append2 as the final output. What I actually do call thing in a loop to gradually add a PDF file to a big. I'm not linking this in one operation because of concerns over the use of the system and because the pdfbox library java has would have been question after 850 in PDF format, which is not completely unrealistic in my approach.
How could I achieve this?
Post edited by: Pollocks01 only formatted code blocks because atlassian {code} tags didn't work.
Passage of an argument as input/OUTPUT requires the mapping to a Java array.
Simplified example that adds one FOR the other:
create or replace and compile java source named blob_appender_src as import oracle.sql.BLOB; import java.sql.SQLException; import java.io.OutputStream; import java.io.InputStream; import java.io.IOException; public class BLOBAppender { public static void run (BLOB[] p1, BLOB p2) throws SQLException, IOException { InputStream is = p2.getBinaryStream(); OutputStream os = p1[0].setBinaryStream(p1[0].length()+1); byte[] buffer = new byte[1024]; int len; while ((len = is.read(buffer)) != -1) { os.write(buffer, 0, len); } os.close(); is.close(); } }
create or replace procedure blob_append ( p_lob1 in out nocopy blob , p_lob2 in blob ) as language java name 'BLOBAppender.run(oracle.sql.BLOB[], oracle.sql.BLOB)' ; /
SQL> declare 2 p_lob1 blob := utl_raw.cast_to_raw('ABC'); 3 p_lob2 blob := utl_raw.cast_to_raw('DEF'); 4 begin 5 blob_append(p_lob1, p_lob2); 6 dbms_output.put_line(utl_raw.cast_to_varchar2(p_lob1)); 7 end; 8 / ABCDEF PL/SQL procedure successfully completed.
-
What is the maximum range of the parameter which accept a procedure?
Hello
Reference guide, PL/SQL and PL/SQL from the user program limits
in 9i
http://download-West.Oracle.com/docs/CD/B10501_01/AppDev.920/a96624/e_limits.htm#LNPLS018
The answer is 64 KB.
and in 10 g
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/limits.htm
The answer is 65536.
concerning
HiteshPublished by: Hitesh Nirkhey January 20, 2011 11:12
-
Hello
I'm trying to run a simultaneous program to the OA Page and I wrote the code for the same below.
OADBTransactionImpl t1 = (OADBTransactionImpl) getDBTransaction ();
System.out.println ("submit button 11 testing");
int preqid;
int out_value;
int test = 0;
String perrbuf;
String s1 = "start xxchr_test_submit_program (preqid = >: 1); END; " ;
System.out.println ("submit button 22 testing");
Proc1 OracleCallableStatement = (OracleCallableStatement) t1.createCallableStatement (s1,-1);
Proc1.registerOutParameter(1,OracleTypes.int);
ST1.registerOutParameter(5,OracleTypes.varchar);
out_value = Proc1.GetInt (1);
System.out.println ("testing submit button 33");
Proc1.Execute ();
System.out.println ("submit button 44 testing");
T1.commit ();
System.out.println ("preqid");
System.out.println ("perrbuf");
There is a parameter to my out procedure: xxchr_test_submit_program (preqid = >: 1); as
CREATE or REPLACE procedure APPS.xxchr_test_submit_program (p_request_id_o out varchar2)
-return the number of
as
-number of p_request_id_o;
p_errbuf_o varchar2 (200);
BEGIN
-Fnd_Global.apps_initialize (userId, responsibilityId, applicationId)
Fnd_Global.apps_initialize (28501,50612,800);
p_request_id_o: =.
() fnd_request.submit_request
request = > "XXCHR"
program = > "XXCHR_EDSG_DATA_MAPPING_LOAD"
Description = > NULL,
-start_time = > TO_CHAR (SYSDATE, "MON-DD-YY HH24:MI:SS"),
sub_request = > FALSE);
p_errbuf_o: = substr (fnd_message.get, 1, 240);
-dbms_output.put_line (1 ' | v_request_id);
-dbms_output.put_line (2 ' | x_errbuf);
-return p_request_id_o;
end;
I'm not able to handle this output parameter. .pls help
Proc1.registerOutParameter(1,OracleTypes.int); is also errorin on... Help, please...
Kind regards
PreetiImport oracle.jdbc.driver.OracleTypes;
-
Puppet stuck outside the parameters of the scene
I replace the Frankenstein's head with my own diapers and now, for some reason any when I drag the puppet in the scene it turns off the announcement of edge I can't move it.
I removed the layer of "Fur from his head", which would have something to do with it?
For others reading this thread... the problem was that the coordinate 0,0 for the work plan was lower at work (i.e., upper left corner of the artboard was negative), and the character is currently using the workplan 0,0 in the upper left corner of the stage.
To work around the problem, just reset the coordinates of the artboard, as follows:
1. on the toolbar, click format Document.
2. click on edit work plans.
3. in the toolbar, set him Point of reference on the upper left corner and then set X and Y to 0, 0.
-
How to call parameters for a procedure of a table?
Hello world
I use the oracle 11.1.0.6 version.
I have a procedure that must call 6 parameters in a table. Could I know how to perform the procedure parameters in a table?
Now, I'm running a .sql file.
SELECT TO_CHAR(SYSDATE,'DD/MM/YY hh24:mi:ss') FROM DUAL;
EXEC call_all (201208, 'DBC', 2, 'Choice', 201223, 201236);
Thanks in advanceHow do you get the values of the parameters to pass to the CALL_ALL procedure?
If you want to get all the parameters to pass to CALL_ALL, to be taken from the table, you will need to do so in an anonymous PL/SQL block/function/stored procedure as below:
declare v_bmonth param.bmonth%type; . . . v_tweek_2 param.tweek_2%type; begin select bmonth, ssc, label, tweek_1, tweek_2 into v_bmonth, ..., v_tweek_2 ---> ... corresponds to Individual Parameter variable from param p where p.some_column = some_value ---> This condition should be able to fetch only One row from table, else it will throw error. call_all(v_bmonth, ... v_tweek_2); end; ------Alternative------------------- declare v_param param%rowtype; begin select * into v_param from param p where p.some_column = some_value ---> This condition should be able to fetch only One row from table, else it will throw error. call_all(v_param.bmonth, ... v_param.v_tweek_2); ---> ... corresponds to v_param."Column_Name" for corresponding column names. end;
Just read that you want to run the procedure for all values:
begin for cur in (select * from param) loop call_all(cur.bmonth, ... cur.v_tweek_2); end loop; end;
I want to do it in a simpler way:
create or replace function f_execute_call_all ( b_bmonth in number, b_banner_name in varchar2, b_ssc in number, b_label in varchar2, b_tweek_1 in number, b_tweek_2 in number ) return number is begin call_all(bmonth,banner_name,ssc,label,tweek_1,tweek_2); return 1; exception when others then -- Log Exception Message raise; end; calling Code: select f_execute_call_all(bmonth,banner_name,ssc,label,tweek_1,tweek_2) from param;
-
Process 1 gr 2 OWB flow - how to pass parameters to a procedure
Hello
In 10.1 OWB processflow IN procedure parameters can be passed in the activity view that appears on the choice of the procedure within the processflow. How to enter the parameters IN the case of OWB11gr2. In property inspector no options are there. Any help is much appreciatedHello
Select the processing activity. In the structure window, select the parameter. Then, you can set the binding or the value in the Properties window.
Sometimes the property window is not updated when the setting is selected. Double-click the bar from the window of the property window to maximize.
Kind regards
Carsten. -
issues related to the parameter in the procedure
Hi all
I have a procedure which the code is given below:
create or replace PROCEDURE seods01.get_cert_tx_lot_tmp (acct_alt_id_in in VARCHAR2
, acct_alt_id_cntx_cde_in IN VARCHAR2 default 'COLA account number.
, ibd_id_in IN INTEGER
qry_rslt_out to sys_refcursor)
IS
BEGIN
OPEN FOR Qry_rslt_out
SELECT L.tx_lot_seq_nbr
L.hld_prd_dte
L.orig_purc_dte
L.tx_lot_amt
L.updt_tx_lot_amt
L.tran_desc_txt
OF v_acct_alt_id A
v_cd_tx_lot L
WHERE A.acct_alt_id = acct_alt_id_in
AND A.acct_alt_id_cntx_cde = acct_alt_id_cntx_cde_in
AND A.ibd_id = ibd_id_in
AND L.eods_acct_id = A.eods_acct_id;
EXCEPTION
WHILE OTHERS THEN
dbms_output.put_line(SQLCODE||) SQLERRM);
END get_cert_tx_lot_tmp;
now when I run the SP in the following way it works fine:
VAR C1 REFCURSOR EXECUTE SEODS01.get_cert_tx_lot_tmp ('004000000000000093108026740', 'Number of COLA account', '1',: C1); PRINT C1
When I try to ignore this value by default setting, then it is throwing ' wrong number or types of arguments "error
VAR C1 REFCURSOR EXECUTE SEODS01.get_cert_tx_lot_tmp ('004000000000000093108026740 ', ' 1',: C1); PRINT C1
and when I tried to put this as null or "then it gives me no results. only way through which I can produce results of this procedure without giving the default parameter is the name of the column with the value of the parameter as follows:
VAR C1 REFCURSOR RUN SEODS01.get_cert_tx_lot_tmp (acct_alt_id_in = > '004000000000000093108026740', ibd_id_in = > '1', qry_rslt_out = >: C1); PRINT C1
but the condition is that we do not want our consumers to put names of columns when they do not pass the default value setting, I hope that there should be a way to do it. Could someone help me please on this issue.
Hello
If you want to use positional notation, then you can only omit parameters by default when they are at the end of the parameter list. In your case, this would mean
(acct_alt_id_in in VARCHAR2
ibd_id_in in FULL
qry_rslt_out ON sys_refcursor
acct_alt_id_cntx_cde_in IN VARCHAR2 default 'COLA account number')
Or you can put the procedure in a package and overload
PROCEDURE seods01.get_cert_tx_lot_tmp
(acct_alt_id_in in VARCHAR2
acct_alt_id_cntx_cde_in IN VARCHAR2
ibd_id_in in FULL
qry_rslt_out to sys_refcursor)
PROCEDURE seods01.get_cert_tx_lot_tmp
(acct_alt_id_in in VARCHAR2
ibd_id_in in FULL
qry_rslt_out to sys_refcursor)
In the procedure without the acct_alt_id_cntx_cde_in parameter, you can call the other version and provide the default value.
Concerning
Marcus
-
Recovering the year max for combination when the parameters are not exists
I try to query a table that maintains cumulative information by calendar_year and calendar_period. The problem I encounter is that if I want to ask the total of the transaction for a combination of accounting from a certain calendar_period and calendar_year, I need get the max calendar_year and calendar_period for the previous year or period for the current_year and max calendar_year by combination of accounting (Fund, org prog (, acct) which falls outside the parameters in my where clause, which for this example would be calendar_year = '15' and calendar_period = '03'. For most of all sense I'll post and excerpt from my table.
create table
CREATE TABLE "MAXTABLE" ( "CALENDAR_YEAR" NUMBER, "CALENDAR_PERIOD" NUMBER, "AMOUNT" NUMBER, "FUND" VARCHAR2(20 BYTE), "ACCOUNT" VARCHAR2(20 BYTE), "ORG" VARCHAR2(20 BYTE), "PROG" VARCHAR2(20 BYTE) )
values in the table.
REM INSERTING into MAXTABLE SET DEFINE OFF; Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (15,2,25,'202118','2071','3662','121'); Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (15,3,150,'202118','2070','3662','121'); Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (14,12,50,'202118','2040','3662','121'); Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (14,3,100,'202118','2070','3662','121'); Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (13,14,50,'202118','2010','3662','121');
so now I want to run a query which would show me the total amounts by combination of accounting (Fund, account, org, prog) and I'd like to get it from calendar_year '15' and calendar_period ' 03 ".
I need essentially back on the period and the year previous years courses and get the max (calendar_year) and the max (calendar_period) for the Fund, account, org, combination of prog that is not in the calendar_year '15' and calendar_period ' 03 "
so the results would look something like below. Also the max_period and max_year could be in the same calendar year that I ask for this combination of accounting, an example of this is the 2070 account in the result below.
I would like to run a query similar to this one
SELECT CALENDAR_YEAR, CALENDAR_PERIOD, AMOUNT, FUND, ACCOUNT, ORG, PROG FROM MAXTABLE WHERE CALENDAR_PERIOD = '03' AND CALENDAR_YEAR = '15';
but it would give me only the amounts on the table which exist for this year and the period. I also need to get the max calendar_year and max_calendar_period before calendar_period 03 and calendar_year 15 and add those to my request.
.expected output:
Calendar_Year calendar_period amount Fund account org PROG 15 2 25 202118 2071 3662 121 15 3 150 202118 2070 3662 121 14 12 50 202118 2040 3662 121 13 14 50 202118 2010 3662 121 noticed that I'm not getting the $100 for account 2070 calendar_year question 14 and calendar_period ' 03 ". This point has already had a calendar_year max 15 and period 2 so I exclude it, since is less than 15 calendar_year but it is also a lot already this combination of accounting.
Hope it makes sense.
Sorry, I did not single-digit into account correctly. Two years and by the need to be wrapped with to_char as:
TO_CHAR (yr, 'fm00') | TO_CHAR (per, 'fm00')<=>=>
John
-
Hi all
I have a bunch that I'm trying to call a function of my procedure and I get null in my results.
If I run the function only parameter passing works very well.
It is an example of code:
get_region give me a line with multiple values.create or replace package demo as TYPE v_GetResultSet is REF CURSOR; TYPE CUSTOM_REF_CURSOR IS REF CURSOR; function get_region(my_id in Number) return GetResultSet; procedure get_country(p_id in Number, v_cursor IN OUT CUSTOM_REF_CURSOR) ; end; / create or replace package body demo as function get_region(my_id) return v_GetResultSet is v_cursor v_GetResultSet; begin open v_cursor for select region_id, region_name from countries where country_id = my_id; return v_cursor; EXCEPTION WHEN OTHERS THEN raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM); end; procedure get_country(p_id in Number, v_cursor IN OUT CUSTOM_REF_CURSOR) as begin open v_cursor for select country_name, case region_id when 3 then get_region(3) end; from countries where country_id = p_id; EXCEPTION WHEN OTHERS THEN raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM); end; end;
Any ideas?
Thank you
JohnnyHi Johnny,.
Glad to see you had a go at the objects yourself.
Here is a more complete example for look you...
SQL> create or replace type t_dept as object(dname varchar2(20), loc varchar2(20)) 2 / Type created. SQL> SQL> create or replace package test_pkg as 2 function get_dept(p_deptno in number) return t_dept; 3 function get_emp(p_empno in number) return sys_refcursor; 4 procedure show_emp(p_empno in number); 5 end; 6 / Package created. SQL> SQL> create or replace package body test_pkg as 2 function get_dept(p_deptno in number) return t_dept is 3 v_dept t_dept := t_dept(null,null); 4 begin 5 select dname, loc 6 into v_dept.dname, v_dept.loc 7 from dept 8 where deptno = p_deptno; 9 return v_dept; 10 end; 11 12 function get_emp(p_empno in number) return sys_refcursor is 13 v_rc sys_refcursor; 14 begin 15 open v_rc for 16 select empno, ename, get_dept(deptno) as dept_dets 17 from emp 18 where empno = p_empno; 19 return v_rc; 20 end; 21 22 procedure show_emp(p_empno in number) is 23 v_rc sys_refcursor; 24 v_empno number; 25 v_ename varchar2(20); 26 v_dept t_dept; 27 begin 28 v_rc := get_emp(p_empno); 29 fetch v_rc into v_empno, v_ename, v_dept; 30 close v_rc; 31 dbms_output.put_line('Empno: '||v_empno||' Ename: '||v_ename||' Dname: '||v_dept.dname||' Loc: '||v_dept.loc); 32 end; 33 end; 34 / Package body created. SQL> exec test_pkg.show_emp(7788); Empno: 7788 Ename: SCOTT Dname: RESEARCH Loc: DALLAS PL/SQL procedure successfully completed. SQL>
-
How to perform the procedure in the SQL worksheet?
Hi, anyone knows, how I can execute procedure here?
I try to EXEC sec_roles, EXEC security_admin.sec_roles, EXECUTE - there's a SQL statement error. When I use the CALL - there is no such procedure (I have execute privileges).
Although in SQLPlus EXEC works, but there are problems with the standard SQL commands (each of them '2' returns any content is).
Any ideas?
Concerning
KrzysztofEXEC procedure (parameters) is a plu sql (and some others) shortcut for
BEGIN procedure(parameters); END;
So try that and then pressing / on anything in the sql worksheet that makes a statement in execution.
Note that if your procedure has defined parameters as OUT or IN OUT, you need to provide a variable to accept the returned values.
John
-
How to change the names of the OUT parameters
Hi all
I have a requirment as I'm a "sample_procedure" with two parameters and two stored procedure PARAMETERS.
sample_procedure (p_new IN varchar2,
p_old IN varchar2,
p_start_list OUT t_start, - table type
p_end_list to t_end); -table type
now, I want to change the names of two of the parameters OUT without disturbing the one (sample_procedure) original. so for this, I need to create new stored again procedure.then SP, I call "sample_procedure". returned variables should change as mentioned name new bellow.the Sp mancunts also have the same parameters of entry... like
sample_procedure (p_new IN varchar2,
p_old IN varchar2,
LIST_ONE OUT t_start, - table type
LIST_TWO to t_end); -table type
the p_start_list should be replaced by LIST_ONE
the p_end_list should be replaced by LIST_TWO
the new SP should behave same as 'sample_procedure', but with THE different parameter names (LIST_ONE, LIST_TWO).
can someone guide me please with an example... Thanks in advance.It looks like you want
create or replace procedure sample_procedure (p_new in varchar2, p_old in varchar2, list_one out t_start, -- table type list_two out t_end) -- table type as begin sample_procedure (p_new => p_new, p_old => p_old, p_start_list => list_one, -- table type p_end_list => list_two); -- table type end sample_procedure;
Although I think that maybe you're in trouble because you will not be able to call the procedures more due to the same overload (same name, same types of arguments)...
Maybe you are looking for
-
HP 35s calculator scientific memory clear loop
I was a regular calculation on my 35 s when all of a sudden it started flashing "clear memory". I can't turn off the calculator and none of the buttons respond. I tried the reset of memory, reset the calculator via the button on the back and remove t
-
Uninstall the software to free up memory space
I was unable to uninstall the software from my computer.
-
If I run THAT MSE value automatic update do I still need to install updates for windows 7 security?
-
System turn off when you play.
My system shuts down when I play games. Never had this problem before. I received the following: Esetup.exe is infected with win32: game. Fix error that 42061 repair failed and I had the option to delete the file that I did. The system is up to close
-
Performance - Remote PC temperature monitor
I work in a digital environment, where I have a few servers (2003) and about 130 machines XP - Pro. I often use performance-MS from one of my servers, monitor to observe the behavior of a PC remotely (memory and processor). Lately, I'm beginning to p