How to use NTILE in a stored proc.?
My module works in SQL*Plus but not in a stored proc. Have tried dynamic SQL to no avail.
Has anyone been successful (in 8.1.7)? If so, how did you overcome the problem?
Thanks, Rich.
Here is my similar effort:
create or replace procedure New_CSD_Hist(p_yr IN number,
p_qtr IN number,
p_market IN varchar2)
is
TYPE CSD_cur_type is REF CURSOR;
CSD_cur CSD_cur_type;
more_data BOOLEAN:=TRUE;
begin
OPEN CDS_cur FOR
SELECT client,
(ntile(3) over(order by sum(csd_spend) DESC)) as csd
from csd_hist
where csd = '0' and
csd_spend > 0 and
market = p_market and
yr = p_yr and
qtr = p_qtr
group by client;
HERE is another effort, trying to follow an example from Pipelines:
lv_stmnt :=
'declare '||
'lv_yr varchar2(4) := :1; '||
'lv_qtr varchar2(1) := :2; '||
'lv_market varchar2(16) := :3; '||
'begin '||
'insert into clientspend select client,'||
'ntile(3) over (order by sum(csd_spend) DESC) as csd '||
'from csd_hist where csd = ''0'' and csd_spend > 0 and '||
'market = :3 and yr = :1 and qtr = :2 '||
'group by client; end;';
execute immediate lv_stmnt using p_yr,p_qtr,p_market;
commit;
Again,
Thanks for your comments and suggestions.,
Dick Berry
Similar Messages
-
** How to use TO_DATE function in Stored Proc. for JDBC in ABAP-XSL mapping
Hi friends,
I use ABAP-XSL mapping to insert records in Oracle table. My Sender is File and receiver is JDBC. We use Oracle 10g database. All fields in table are VARCHAR2 except one field; this is having type 'DATE'.
I use Stored procedure to update the records in table. I have converted my string into date using the Oracle TO_DATE function. But, when I use this format, it throws an error in the Receiver CC. (But, the message is processed successfully in SXMB_MONI).
The input format I formed like below:
<X_EMP_START_DT hasQuot="No" isInput="1" type="DATE">
Value in Payload is like below.
<X_EMP_START_DT hasQuot="No" isInput="1" type="DATE">TO_DATE('18-11-1991','DD-MM-YYYY')</X_EMP_START_DT>
Error in CC comes as below:
Error processing request in sax parser: Error when executing statement for table/stored proc. 'SP_EMP_DETAILS' (structure 'STATEMENT'): java.lang.NumberFormatException: For input string: "TO_DATE('18"
Friends, I have tried, but unable to find the correct solution to insert.
Kindly help me to solve this issue.
Kind Regards,
Jegathees P.
(But, the same is working fine if we use direct method in ABAP-XSL ie. not thru Stored Procedure)Hi Sinha,
Thanks for your reply.
I used the syntax
<xsl:call-template name="date:format-date">
<xsl:with-param name="date-time" select="string" />
<xsl:with-param name="pattern" select="string" />
</xsl:call-template>
in my Abap XSL. But, its not working correctly. The problem is 'href' function to import "date.xsl" in my XSLT is not able to do that. The system throws an error. Moreover, it is not able to write the command 'extension-element-prefixes' in my <xsl:stylesheet namespace>
May be I am not able to understand how to use this.
Anyway, I solved this problem by handling date conversion inside Oracle Stored Procedure. Now, its working fine.
Thank you. -
How to use order by in stored procedure base block?
How to use order by in stored procedure base block? I need to change order by dynamically
Use SET_BLOCK_PROPERTY('BLOCK_NAME',ORDER_BY,'COLUMN_NAME1, COLUMN_NAME2');
-
How to use @jws:sql call Stored Procedure from Workshop
Is there anyone know how to use @jws tag call Sybase stored procedure within
Workshop,
Thanks,Anurag,
Do you know is there any plan to add this feature in future release? and
when?
Thanks,
David
"Anurag Pareek" <[email protected]> wrote in message
news:[email protected]..
David,
In the current release, we do not support calling stored procedures from a
database control. You will have to write JDBC code in the JWS file to call
stored procedures.
Regards,
Anurag
Workshop Support
"David Yuan" <[email protected]> wrote in message
news:[email protected]..
Anurag,
I know how to use DB connection pool and create a db control with it. In
fact, we have created a Web Service with the db control using plain SQL
in
@jws:sql. However, my question here is how to use @jws tag in Weblogic
Workshop to create a Web Services based on Sybase stored procedure orany
Stored Proc not plain SQL.
Thanks,
David
"Anurag Pareek" <[email protected]> wrote in message
news:[email protected]..
David,
You can use a database control to obtain a connection from any JDBC
Connection Pool configured in the config.xml file. The JDBC Connectionpool
could be connecting to any database, the database control is
independent
of
that.
Regards,
Anurag
Workshop Support
"David Yuan" <[email protected]> wrote in message
news:[email protected]..
Is there anyone know how to use @jws tag call Sybase stored
procedure
within
Workshop,
Thanks, -
How to set variable values in Stored Procs
Hi all,
please excuse my newbie questions - I've spent too long using SQL Server......
Anyway,
I'm playing with SP basics and was wondering how I can set a variable value in a stored proc, ideally getting a value from a table or some select .
for instance...........
CREATE OR REPLACE PROCEDURE RPT_SP_ANT_TESTING
P1 IN NUMBER,
P2 IN VARCHAR2
IS
TmpNum NUMBER;
TmpStr VARCHAR2(255);
BEGIN
--How do set these?
SET TMPNUM := SELECT Count( * ) FROM ALL_TABLES;
SET TMPSTR := P2 + '_APPENDED';
INSERT INTO TEST_TABLE
( STRINGFIELD, NUMBERFIELD )
VALUES
( TmpStr, TMPNUM )
END;
Regards
DCSome ways are...
setting directly
x := 1;
setting from a select use INTO clause
select 1 into x from dual
setting from a select into a collection type use BULK COLLECT INTO
select name bulk collect into lName from your_table.
It would be better if you read the document.
Thanks,
Karthick. -
How to compare the table, constraint, stored proc, view between 2 schema ?
Hi All,
We have two schema : app_test & app_prod :
app_test is where user run acceptance test, and where we make correction etc
app_prod is where user prepare data for going live/production.
Now we need to make sure that :
table structure
stored proc
view
function
sequence
constraint ...
Is the SAME between the two schema : Is there any script that can automate the process ?
Thank you very much,
xtantoYou may use TOAD, OEM, and use "ALL_" views to compare.
And also, take a look into the duplicate thread on this forums.
How to compare two oracle database schemas
You can also check in the google for any free tools for this !!
Regards,
Sabdar Syed. -
How to use methods when objects stored in a linked list?
Hi friend:
I stored a series of objects of certain class inside a linked list. When I get one of them out of the list, I want to use the instance method associated with this object. However, the complier only allow me to treat this object as general object, ( of Object Class), as a result I can't use instance methods which are associated with this object. Can someone tell me how to use the methods associated with the objects which are stored inside a linked list?
Here is my code:
import java.util.*;
public class QueueW
LinkedList qList;
public QueueW(Collection s) //Constructor of QuequW Class
qList = new LinkedList(s); //Declare an object linked list
public void addWaiting(WaitingList w)
boolean result = qList.isEmpty(); //true if list contains no elements
if (result)
qList.addFirst(w);
else
qList.add(w);
public int printCid()
Object d = qList.getFirst(); // the complier doesn't allow me to treat d as a object of waitingList class
int n = d.getCid(); // so I use "Object d"
return n; // yet object can't use getCid() method, so I got error in "int n = d.getCid()"
public void removeWaiting(WaitingList w)
qList.removeFirst();
class WaitingList
int cusmNo;
String cusmName;
int cid;
private static int id_count = 0;
/* constructor */
public WaitingList(int c, String cN)
cusmNo = c;
cusmName = cN;
cid = ++id_count;
public int getCid() //this is the method I want to use
return cid;Use casting. In other words, cat the object taken from the collection to the correct type and call your method.
HashMap map = /* ... */;
map.put(someKey, myObject);
((MyClass)(map.get(someKey)).myMethod();Chuck -
Using collection as a stored proc. parameter
I have a requirement of a using a stored proc ('in') parameter as a collection and using it futher in the where clause of a sql query. What are my options here ? I am currently trying with a nested table, getting errors in using with sql query.
What are my options here ?sql>create or replace type NumberTable as table of number;
2 /
Type created.
sql>create or replace procedure p_test
2 (p_list in NumberTable)
3 is
4 v_count pls_integer;
5 begin
6 select count(*)
7 into v_count
8 from table(p_list);
9 dbms_output.put_line( 'Count: ' || v_count );
10 end;
11 /
Procedure created.
sql>declare
2 v_list NumberTable := NumberTable(1, 2, 3, 4, 5);
3 begin
4 p_test(v_list);
5 end;
6 /
Count: 5
PL/SQL procedure successfully completed.There are some cases where you need to use CAST with the TABLE function:
table(cast(p_list as NumberTable)) -
Using Java within a stored proc to access multiple database connections
Hi List;
We have an environment where we have needs to provide cross database visibility between Oracle, Sql Server and PostgreSQL. So we need the capability for Oracle to query PostgreSQL and Sql Server tables, PostgreSQL must be able to query Oracle and Sql Server tables and Sql Server must be able to query Oracle and PostgreSQL tables.
I'm thinking that we can implement stored procs which are either written in java or call a java process . The java code in turn should be able to connect to any DBMS desired via JDBC query the tables in question and return the result set to the calling database.
Any thoughts on how feasable this is would be appreciated. Does this seem like a solid solution? Any initial concerns or red flags? what about performance via JDBC?
Thanks in advance for your help.John,
from your description I understand that you essentially program the VO yourself. So I suggest that you read chapter 35.9 of the 'Fusion Developer’s Guide for Oracle Application Development Framework' (I guess you know where to find it). Since you still call the actual SQL not all of the chapter apply, but you get the idea how it works.
And yes you analyzed the behavior correct. executeQueryForCollection() is allways called bevore getQueryHitCount().
Timo -
How to declare a cursor with stored proc?
Hi All,
Can we declare a cursor with stored proc?
For Example -
CREATE PROCEDURE DDL_proc() LANGUAGE SQLSCRIPT AS
CURSOR c_cursor1 (v_isbn VARCHAR(20)) FOR CALL SYS.GET_OBJECT_DEFINITION(<SCHEMA_NAME>, <TABLE_NAME>).;
BEGIN
FOR cur_row as c_cursor1 DO
END FOR;
END;
Could you please have a look on the same?
Thank you,
VijeeshOracle PL/SQL also has a select into statement which is described in the same manual the link takes you to part of.
select column_list
into variable_list
from table(s)
where conditions
The PL/SQL Users Guide is something you are going to want to have gone over cover to cover before you start converting because so that you make the best choices for how to rewrite the code: select into, explicit cursor, implicit cursor, for loop, simple loop, while loop, collections,bulk load, etc ....
HTH -- Mark D Powell -- -
How to SEND PAGE from Oracle stored proc
I've searched all Oracle docs and internet. Need to be able to
send a msg to a pager via SMS (or some other method) from a
stored proc. Saw some mention of Oracle Paging Server but not
much doc on implementing. Please feel free to post here or
mailto:[email protected]if you need to send sms message you need to have wapgateway and
wml background -
How to pass the values to stored proc using presentation variable in OBIEE
Need your help regarding in resolving an issue in OBIEE 10.1.3.4.1
There are 6 reports say ‘A’,’B’,’C’,’D’,’E’,’F’ in the same subject area.
The reports are being configured with prompts using either the repository/presentation variables.
One of the reports say ‘A’ has been configured to pass the values using presentation variables from the prompt in Advanced Tab of the report request to the stored procedure defined in the Execute Before Query section of the connection pool.
After running another report ‘B’ in the same subject area, upon visiting the report ‘A’ view display error is being seen ( Please have a look below screen shot for your reference) .
Speculate the issue is around presentation variables of report ‘A’ getting initialized even before running the report.
Appreciate your earliest advise as this is a prod issue.Hi Prasad,
I got your note, you should not use Session variable syntax to call presentation variable.
you should use like @{AIC_PROJ_PLAT_SEQ_NO}
One more thing: first test the variable AIC_PROJ_PLAT_SEQ_NO value then try to pass to SP.
Hope this helps -
How pass ext characters to a stored proc by odbc when enable sqlserver syntax is on??
how pass french characters or extended characters to a stored procedure by odbc
error: ORA-01756: quoted string not properly terminated
une chaine entre apostrophhes ne se termine pas correctement
oracle Retrieving extended characters thru ODBC
PL/SQL procedure parameters
hi, i hope you can help to me.
I have a problem with french and german characters.
i have a little stored procedure than return what i'm passing to him.
see these example: (the second one work fine on plsql)
first exemple:
1) i created a new odbc dsn
2) i'm going into sqlserver migration tab to choose
Enable Exac Syntax.
3) i'm open Winsql (this is a odbc tools)
http://www.indus-soft.com/winsql/
4) i'm write
exec ksp_test 0,'HiLLO ORACLE'
i receive this error:
Error: ORA-01756: quoted string not properly terminated
(State:S1000, Native Code: 6DC)
I trying to changed too the NLS_LANG in the registry
like FRENCH_CANADA.WE8ISO8859P1
French_France.WE8ISO8859P1
but without any success..
i got the same problem with
oracle 9 database with utf8 characters set.
oracle 8.1.7 with iso8859p1 characters set.
i trying all latest odbc driver from oracle website.
second exemple:
SQL> variable mytest refcursor;
SQL> exec ksp_test (0,'HiLLO ORACLE',:MYTEST);
PL/SQL procedure successfully completed.
SQL> PRINT MYTEST;
Your Database Value
HiLLO ORACLE
CREATE OR REPLACE PACKAGE KSP_PLSQLRSETPKG
AS
TYPE RCT1 IS REF CURSOR;
END;
CREATE OR REPLACE PROCEDURE KSP_TEST (
PATCH INT DEFAULT 0,
PONC VARCHAR2,
RC1 IN OUT KSP_PLSQLRSETPkg.RCT1
AS
BEGIN
OPEN RC1 FOR
SELECT PONC "Your Database Value" FROM DUAL;
FROM DUAL;
RETURN ;
END;
i'm trying also different nls setting but no good result.
AMERICAN_AMERICA.US7ASCII
AMERICAN_AMERICA.WE8MSWIN1252
FRENCH_CANADA.WE8DEC
FRENCH_CANADA.UTF8
FRENCH_CANADA.WE8MSWIN1252
FRENCH_FRANCE.WE8DEC
FRENCH_FRANCE.UTF8
FRENCH_FRANCE.WE8MSWIN1252
is working well on sqlplus but not by odbc..
also..
i'm declare a variable and
i set
v_variable := 'id'
and the procedure return the good syntax...
i think is a odbc driver problem....
the driver don't want to accept a extended characters set by a parameters coming from the procedure.
can you confirm to me ..this is a major bug for the driver..
my procedure is very basic to make a little test.
did you try my procedure to be sure you have the same problem?
i try with a oracle instance utf8,WE8MSWIN1252 and
i got always the same problem.
if i write insert into test values ('di');
everything is fine...but when i call the procedure...
the procedure don't want to accept any german..french or any extended characters...
our application is working by odbc driver.
i'm pretty sure is a bug in the driver ...the bug is coming only when i select "ENABLE EXEC SYNTAX" IN THE DSN (SQLSERVER MIGRATION SECTION) ... i try with Shema Database and Owner and Empty and i got
always the same problem
exec KSP_TEST 0,'TiEST'
------------------------>>>>>>>NOT WORKING.
BUT IF I WRITE
CALL KSP_TEST (0,'TiEST')
------------------------->>>>IS WORKING
if i select enable exec or i unselect enable exec...
the CALL KSP_TEST...... is always working properly.
BETWEEN THESE SYNTAX THE NLS_LANG IS NEVER CHANGED....
IS WORKING.....THE NLS_LANG IS GOOD.......because i make a little modification in procedure to be sure the INSERT IS inside the database CORRECTLY.
CREATE OR REPLACE PROCEDURE KSP_TEST
PATCH INT,
PONC VARCHAR2
AS
v_test varchar2(100);
BEGIN
v_test := 'test';
INSERT INTO YYY VALUES (PONC);
END;If "just using Crystal Reports XI R2" means using Crystal Report Viewer and do not want to see the prompt, please follow the below steps.
1. Select the report you want to see
2. Select "Process" tab
3. Select Parameters menu under the process tab.
4. You would see two date parameters there.
Select the [Empty] value for each parameter and fill out the value you want.
Hope this would help. -
How to use materialized view in stored procedure
in my stored procedure I use couple of queries (see the script below). I want to create materialized views to replace these queries. Is it possible to achieve and how to achieve it in my case? thanks in advance
set serveroutput on
DECLARE
v_cur_tid NUMBER(5):=0;
v_cur_cs_attendance NUMBER(5):=0;
v_cur_c_tot_enrolments NUMBER(5):=0;
v_most_enrolments NUMBER(5):=0;
v_least_enrolments NUMBER(5):=0;
v_most_pop_cid NUMBER(5):=0;
v_least_pop_cid NUMBER(5):=0;
CURSOR class_cursor IS
select
id,
name,
max_attendees
from
class
where
id in (select distinct(event_id) from trainer_schedule where event_type='c' and is_active='y')
order by id;
BEGIN
DBMS_OUTPUT.PUT_LINE('==================================================================================================================================');
--print the report header
DBMS_OUTPUT.PUT_LINE('Summary Report No.3: Training Class Active Schedules Summary Report');
FOR r_class IN class_cursor LOOP
--print the header or subsection
select sum(enrolments) into v_cur_c_tot_enrolments from class_schedule where class_id = r_class.id;
IF v_most_enrolments < v_cur_c_tot_enrolments OR v_most_enrolments = 0
THEN v_most_enrolments := v_cur_c_tot_enrolments; v_most_pop_cid := r_class.id;
END IF;
IF v_least_enrolments > v_cur_c_tot_enrolments OR v_least_enrolments = 0
THEN v_least_enrolments := v_cur_c_tot_enrolments; v_least_pop_cid := r_class.id;
END IF;
DBMS_OUTPUT.PUT_LINE('******************************************************************************************');
DBMS_OUTPUT.PUT_LINE('CLASS_ID: ' || r_class.id ||' '|| 'CLASS_NAME: ' || r_class.name ||' '||'CAPACITY: ' || r_class.max_attendees ||' '||'TOTAL_ENROLMENTS: ' || v_cur_c_tot_enrolments);
DBMS_OUTPUT.PUT_LINE(rpad('____________', 12) || lpad('____________', 12) || lpad('____________________', 20) || lpad('____________________', 20) || lpad('____________',12) || lpad('____________',12));
DBMS_OUTPUT.PUT_LINE(rpad('SCHEDULE_ID', 12) || lpad('TRAINER_ID',12) || lpad('START_TIME', 20) || lpad('END_TIME',20) || lpad('ENROLMENTS',12) || lpad('ATTENDANCE',12));
DBMS_OUTPUT.PUT_LINE(rpad('____________', 12) || lpad('____________',12) || lpad('____________________', 20) || lpad('____________________', 20) || lpad('____________',12) || lpad('____________',12));
FOR r_cs IN (select id,to_char(start_time,'DD-MM-YYYY HH24:Mi') as start_time, to_char(end_time,'DD-MM-YYYY HH24:Mi') as end_time, enrolments from class_schedule where class_id = r_class.id order by id)
LOOP
select trainer_id into v_cur_tid from trainer_schedule where event_type='c' and event_id = r_cs.id;
select count(training_session.id) into v_cur_cs_attendance
from training_session, class_schedule
where training_session.attended = 'y' and
training_session.type='c'and
to_char(training_session.start_time,'DD-MM-YYYY HH24:Mi') = to_char(class_schedule.start_time,'DD-MM-YYYY HH24:Mi') and
class_schedule.id = r_cs.id;
DBMS_OUTPUT.PUT_LINE(rpad(r_cs.id, 12) || lpad(v_cur_tid,12) || lpad(r_cs.start_time, 20) || lpad(r_cs.end_time,20) || lpad(r_cs.enrolments,12) || lpad(v_cur_cs_attendance,12));
END LOOP;
END LOOP;
DBMS_OUTPUT.PUT_LINE('******************************************************************************************');
DBMS_OUTPUT.PUT_LINE('******************************************************************************************');
DBMS_OUTPUT.PUT_LINE('MOST_POPULAR_CLASS: '||v_most_pop_cid||' TOTAL_ENROLMENTS_TO_DATE: '||v_most_enrolments);
DBMS_OUTPUT.PUT_LINE('LEAST_POPULAR_CLASS: '||v_least_pop_cid||' TOTAL_ENROLMENTS_TO_DATE: '||v_least_enrolments);
DBMS_OUTPUT.PUT_LINE('==================================================================================================================================');
END;
/Hi,
you could use Dynamic SQL /Execute immediate to run DDL from a stored procedure.
http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/11_dynam.htm
Could you please tell why do you want to create a materialized view in stored procedure ?
How frequently you will runt this procedure . It would is better to create a MV once and use it.
thanks -
How to wake-up a Java Stored Proc at Oracle Server Startup
Hi,
I am writing a Java Stored Procedure responsible to
execute periodically (daily for example) a command (the
command and its arguments are prepared by the Java stored
procedure and they are date and time sensitive).
My questions are:
1. Is there any way that my Java stored procedure is
initially NOTIFIED (woke-up) when the Oracle server is
started ? I noticed that there is a built-in Java stored procedure in Oracle DB declared as:
"PROCEDURE notify_at_startup( user_schema VARCHAR2, classname VARCHAR2) ;"
Can this be used in any way for my purpose ? If yes, how ?
2. I can do the PERIODIC scheduling of execution of the
command using standard (SUN) java timer/Thread
primitives. Are there any Oracle Java classes/methods
which can be used instead for this scheduling ?
Thanks for any help/suggestions.
ArminiusI would look at two things.
1) Create a database level trigger that fires at server start up.
2) Define an Oracle Job that runs every xx minutes and restarts itself.
Chet West
Maybe you are looking for
-
Using Time Capsule as a dedicated external hard drive + back up device
I am running very low on storage space on my current Macbook so I was wondering if I could permanently transfer data to Time Capsule and use it as an external hard drive. If so, can I still also use it to back up the rest of the data on my Macbook? J
-
My 24" imac will not read cd's, reads dvd's fine
My 24" imac will not read cd's, reads dvd's just fine.
-
Could not apply the Blur Gallery workspace because the file is locked...
I fixed the permissions 10x times (from Safe Mode as well). I reassigned and reassigned the Permissions. I reset the PS Preferences. I "Uninstall LT5, Uninstall PSCC2014, Unistall Creative Cloud. Reinstall Creative Cloud, Install PSCC 2014 from the C
-
HTML Signature with logo does not display when read by clients
I have had this problem for a while now. I am using 10.5.6 and Apple Mail to send all of my emails. I have only one signature for my business email account which is a GoogleMail pro account. I have set up a signature to display my business logo which
-
Display Stock level for every user
Hi I need to display the stock level for each user (partdetail.aspx). So they know how many they can order. I know it is only displaying for the superusers. Is there anyway of display the stock level for other users as well rather than just showing t