Oracle script using cursors
Hi all. I'm doing a script that selects the NAME of a table and order the result by CLASS, by using cursors. The cursor 1, is to select CLASS NAME, where CLASS = '1'; While the 2nd cursor's SELECT CLASS NAME where CLASS = '2'; and after that, you use the LOOP, the script does the job, but I have to write the same code for 2 sliders as follows:If I have a table named LIMBAFK with the NAME and the CLASS in the form of columns and data as follows:
NAME CLASS
JULIAN 1
Michale 1
2 George
DECLARE
CURSOR C1 IS SELECT NAME FROM LIMBAFK WHERE CLASS = '1';
CURSOR C2 IS SELECT NAME FROM LIMBAFK WHERE CLASS = '2';
MYD C1% ROWTYPE;
MY2D C2% ROWTYPE;
BEGIN
OPEN C1;
DBMS_OUTPUT. PUT_LINE('1');
LOOP
FETCH C1 INTO MYD;
WHEN EXIT C1% NOTFOUND;
DBMS_OUTPUT. PUT_LINE (MYD.NAME);
END LOOP;
CLOSE C1;
OPEN C2;
DBMS_OUTPUT. PUT_LINE('2');
LOOP
EXTRACT THE C2 IN MY2D;
WHEN THE EXIT C2% NOTFOUND;
DBMS_OUTPUT. PUT_LINE (MY2D.NAME);
END LOOP;
CLOSE C2;
END;
Then, using this script, the result would be:
1
Julian
Michale
2
George
It's good and it works, but I don't want to write the same code for the two sliders, so I had in mind that the first cursor selects CLASS DISTINCTE of the table, and the 2nd cursor NAME, CLASS, of the same table, and then a comparison between the sliders using, do the same thing. I wrote the code, but it doesn't work at all, so I hope someone can help me.
Here's what I've done so far, but it is not at all finished:
DECLARE
CURSOR C1 IS SELECT CLASS OF LIMBAFK;
CURSOR C2 IS SELECT NAME, CLASS OF LIMBAFK;
MYD C1% ROWTYPE;
MY2D C2% ROWTYPE;
BEGIN
OPEN C1;
LOOP
WHEN EXIT C1% NOTFOUND;
FETCH C1 INTO MYD;
DBMS_OUTPUT. PUT_LINE (MYD. CLASS);
OPEN C2;
LOOP
WHEN THE EXIT C2% NOTFOUND;
EXTRACT THE C2 IN MY2D;
IF C2. CLASS = C1. CLASS
DBMS_OUTPUT. PUT_LINE (MYD. CLASS);
END LOOP;
CLOSE C1;
END;
declare
cursor c1 is select CLASS,NAME, lag(class, 1) over (order by class) prev_class from LIMBAFK;
l_var C1%ROWTYPE;
begin
open c1;
loop
fetch c1 into l_var;
exit when c1%notfound;
if (l_var.prev_class != l_var.class or l_var.prev_class is null) then
dbms_output.put_line(l_var.class);
end if;
dbms_output.put_line(l_var.name) ;
end loop;
end;
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions070.htm#SQLRF00652
Tags: Database
Similar Questions
-
To delete all tables in TT, how can I use cursor this way Timesten 11?
Hello
I want to delete all tables in Timesten, so I create a procedure like this, but it seems does not work correctly.
It seems cursor in not accurate Timesten with which in ORACLE. So we are looking for alternatives to do. Could you please provide your expert voice on it.
Thank you very much.
Like the following:
Command > create or replace procedure dropAllTables
> as
> CURSOR mycursor IS select table_name from user_tables;
> table_name user_tables.table_name%type;
> dropSql varchar2 (200);
> start
> Open mycursor;
> fetch mycursor into table_name;
> while mycursor found %
> loop
> dropSql: = 'drop table ' | table_name;
> immediately execute dropSql;
> fetch mycursor into table_name;
> end of loop;
> close mycursor;
> end;
> /.
Created procedure.
Command > exec dropAllTables;
8507: ORA-01001: Invalid cursor
8507: ORA-06512: at "TT. DROPALLTABLES', line 13
8507: ORA-06512: at line 1
The command failed.
How can I use cursor this way Timesten 11?It is the implementation of cursor close commit on in Timesten is the cause.
As the drop statements are internally auto-valider the transaction so it closes the cursor itself. So when the next time that you attempt to extract it is your "error cursor not valid."
Can you try this instead
create or replace procedure dropAllTables
as
CURSOR mycursor IS select table_name from user_tables;
table-name user_tables.table_name%type;
type t_row_collection is table of the directory index user_tables.table_name%type;
t_rows t_row_collection;
dropSql varchar2 (200);
Start
Open mycursor;
Mycursor fetch bulk collect into t_rows;
Close mycursor;
j in t_rows.first... loop t_rows. Last
dropSql: = 'drop table ' | t_rows (j);
immediately run dropSql;
end loop;
end; -
Create the script from another script using GUEST
Oracle 11
Instead of having to make a link to a different database, I want to create 2 scripts that are run from a shell script and run separately. Run Script1 in Database1 would create 2 Script using PROMPT to create the second script while entering a date of base1 to base2. I've almost got it but the problem is... Script2 using COPY FROM and I need to put a "-" at the end of each line that the GUEST takes as a literal instead of as part of the output.
SCRIPT1:
SCRIPT2 NOW:set pagesize 0 set trimspool on set linesize 2000 set echo off set verify off set feedback off set sqlblanklines on spool /home/michelle/sql_scripts/sl_dtc_copy2.sql PROMPT whenever sqlerror exit sql.sqlcode rollback PROMPT SET ARRAYSIZE 5000 PROMPT SET COPYCOMMIT 20 PROMPT set linesize 4000 PROMPT PROMPT COPY FROM {username}/{pswd}@{DB2} TO {username}/{pswd}@{DB2} PROMPT CREATE SL_DTC_TMP USING SELECT DISTINCT PROMPT col1, col2, col3 PROMPT FROM dual PROMPT WHERE veh_data_elements_cd = 'ODO_READ' PROMPT and dh.data_collected_timstm >= select trunc(sysdate)-7 from dual; PROMPT and substr(vdh.vin,10,1) in ('A','B','C','D') PROMPT / PROMPT spool off PROMPT exit spool off exit
SCRIPT2 HOW IT SHOULD BE:whenever sqlerror exit sql.sqlcode rollback SET ARRAYSIZE 5000 SET COPYCOMMIT 20 set linesize 4000 COPY FROM {username}/{pswd}@{DB2} TO {username}/{pswd}@{DB2} CREATE SL_DTC_TMP USING SELECT DISTINCT col1, col2, col3 FROM dual WHERE veh_data_elements_cd = 'ODO_READ' and dh.data_collected_timstm >= 12-AUG-11 and substr(vdh.vin,10,1) in ('A','B','C','D') / spool off exit
-A [SPACE] AND a [-] at the end of each line
-THE DATE MUST HAVE THE APOSTROPHES AND PREFERABLY AT THE END OF THE PREVIOUS LINE
Thank youwhenever sqlerror exit sql.sqlcode rollback SET ARRAYSIZE 5000 SET COPYCOMMIT 20 set linesize 4000 COPY FROM {username}/{pswd}@{DB2} TO {username}/{pswd}@{DB2} - CREATE SL_DTC_TMP USING SELECT DISTINCT - col1, col2, col3 - FROM dual - WHERE veh_data_elements_cd = 'ODO_READ' - and dh.data_collected_timstm >= '12-AUG-11' - and substr(vdh.vin,10,1) in ('A','B','C','D') / spool off exit
Oops, sorry, I forgot to change the line.
Must be double quotes to delimit the orignial:SELECT 'WHERE veh_data_elements_cd = ''ODO_READ'' -' from dual
Kind regards
Sylvie -
How to run a script using the OMB tcl
I'm trying to run a tcl script using the following syntax in cmd
D:\app\Username\product\11.1.0\db_2\owb\bin\win32 > ombplus.bat c:\t.tcl
and I get the error
OMB01001: Not connected to the repository.
The tcl script was basically accompanied by a tutorial and I can't continue the OWB tutorial, unless I run it firstDeparture ombplus.bat
You can then start the script with the source command such as
source C:/t.tcl
Be careful with the backslash (he is not C:\t.tcl)
You must also add a connection before your script to OWB with the OMBCONNECT
OMBCONNECT $UserLogin/$UserPassword@$DBHostName:$DBHostPort:$ServiceName USE REPOSITORY '$RepositoryUser' USE MULTIPLE_USER_MODE
Replace the parameters $ with your own value.
And then your script, you can disconnect:
OMBDISCONNECT
Success
NicoDocumentation is here for the 11g OMBCOMMAND
http://download.Oracle.com/docs/CD/B28359_01/OWB.111/b31279/TOC.htm -
Help me convert after the SQL Server Oracle script script
could someone help me conversion following script in oracle script
Create procedure Insert_profilebasicdetail
(
@isubprofileid as int,
@Copyisubprofileid as int,
@itranno as int,
)
As
Begin
Declare @IncKeyId as int
Declare @tempkeyId as int
Set @IncKeyId = (select isNull (Max (ikeyId), 0) as profilebasicdetail MaxKeyId)
Declare TempInsert cursor for select ikeyId - iprofileid, iquestionid, vquestionans, cstatusindi, dmodifyon, imodifyby, iyear
of profilebasicdetail where isubprofileid=@Copyisubprofileid and itranno=@itranno
Open TempInsert
the extraction of TempInsert in @tempkeyId
While @fetch_Status = 0
Begin
Set @IncKeyId = @IncKeyId + 1
Insert into profilebasicdetail
(ikeyid, iprofileid, iquestionid, vquestionans, cstatusindi, dmodifyon, imodifyby, itranno, iyear, isubprofileid)
values (select @IncKeyId, iprofileid, iquestionid, vquestionans, cstatusindi, dmodifyon, imodifyby, '1',
profilebasicdetail iYear,@isubprofileid where ikeyId=@tempkeyId)
extract the following TempInsert in @tempkeyId
End
End
Kind regards
AjayYou always seem to be missing the semicolon (;) in the end of your CURSOR, as Aman has pointed out in his last message.
CURSOR TempInsert IS SELECT ikeyid, iprofileid,iquestionid,vquestionans,cstatusindi,dmodifyon,imodifyby,iyear FROM profilebasicdetail WHERE isubprofileid=723 and itranno=58*;*
(Note that the * are simply to point out where the change needs to be done.) You don't want those in your actual code)
Justin
-
Cannot use the Val function in a script use
I'm trying to convert a text string (binary number) in a number by using the Val function in a script of use but the colors of tiara the term Val in red and the script produces an error indicating "Variable is undefined:"Val"
Why is that happen? Some functions are not allowed in use scripts?
In addition, it seems impossible to use debugging in my use - if I try to add a variable to the Watch window, there never have any value even if I put a breakpoint on this line of code. Would it not possible to debug scripts use?
David,
regarding your question on "Val" I would like to direct you to the "File.Formatter.ParseString" function which is part of the API available at DataPlugins.
CDbl and CLng do a good job in general, but they are dependent on the local configuration of the PC. 'ParseString' is so much more reliable.
Andreas
-
Hello
It would be helpful to me if someone can give me instructions on setting the version of driver or oracle client required to connect to the the Oracle DB using excel VBA
My config: -.
Windows - 8-64 bit
Excel 2013-32 bit
The components of the client / I should install, and how to solve the question below...
I tried the VBA code... but you are prompted with the error message above
Void Oracle()
Con Dim As ADODB. Connection
Dim rs As ADODB. Recordset
Dim query As String
The con value = New ADODB. Connection
Set rs = New ADODB. Recordset
strCon = "Driver = {Microsoft ODBC for Oracle}"; "." & _
"CONNECTSTRING = (DESCRIPTION ="& _.
"(ADDRESS =(PROTOCOL=TCP)"& _
"(HOST = HostNumber)(PORT=PortNumber))" & _
"(CONNECT_DATA = (SID = SIDNumber))); UID = username; pwd = password; »
con. Open (strcon)
If err. <>Number 0 then
MsgBox ("Oracle error:" & vbCrLf & err.) Description)
On the other
MsgBox ("Oracle DB Connection successful.")
End If
End Sub
I'll replace it with the values of host origin...
Thanks for the suggestion you till u gave...
complete solution is in the link below...
https://itkbs.WordPress.com/2014/07/28/how-to-install-ODBC-driver-for-Oracle-in-Windows-7/
-
Run Calc Script using MaxL server location
Hello!!
I wonder if anyone has tried running Calc script stored on the server (not in the app folder) using MaxL?
My research on run calculation led to run scripts associated to a particular application, but not on executing a script from a common repository such as the location of the server between multiple applications.
Any help is greatly appreciated.
It is sometimes useful, in my case, I had a unique scenario where I had 10 cubes
Cube 1 essbase process information and then send to the DATA STORE, which then runs a set of calc (some detailed data movement)
Cube 2 then consumes these data and processes to Cube 10.
All scripts used in Essbase is the same. However, we had to keep all applications and maintenance was a nightmare. This RUNCALC scenario helps a lot.
I had to create a dummy app/db to store all Calc and maintenance will be done on this one and a bat script will move those to the respective cubes. I can identify at the request
Concerning
Celvin Kattookaran
-
Run the Ant script using Java in webcenter Portal
Hi all
I have requirement where I have to run an ant script using java or by any means to the webcenter portal.
Ant script must be run on a triggering action.
Please help me in this direction.
Thank you and best regards,
Shakir
Hey all,.
Here is the solution, I had finally
BuildFile file = new File ("myBuild.xml");
Project p = new Project();
p.setUserProperty ("ant.file", buildFile.getAbsolutePath ());
ConsoleLogger DefaultLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream (System.err);
consoleLogger.setOutputPrintStream (System.out);
consoleLogger.setMessageOutputLevel (Project.MSG_INFO);
p.addBuildListener (consoleLogger);
p.init ();
ProjectHelper helper = ProjectHelper.getProjectHelper ();
p.addReference ("ant.projectHelper", assistance);
Helper.Parse (p, buildFile);
p.executeTarget (p.getDefaultTarget ());
Kind regards
Shakir
-
What Oracle network uses for CAR traffic? where you get the Info?
Hello
I use two-node RAC on Oracle 10 g R2 (10.2.0.3.0) version on SUN Solaris 10. I want to know "what Oracle network uses for CAR traffic? where you'll Info»
-KumarHi Kumar,
In 10g, you can query x$ ksxpia. If the cluster_interconnect is stored in the OCR (by default), you will get
SQL > select INST_ID select, PUB_KSXPIA, PICKED_KSXPIA, NAME_KSXPIA, IP_KSXPIA, x$ ksxpia;
If you have specified the cluster_interconnects parameter in your init.ora:
Columns to look in: INST_ID select PICK NAME_KSXPIA IP_KSXPIA P
And also you can use 'CPI oradebug' to see who connects the database uses:
SQL > setmypid oradebug
SQL > oradebug CPIIt could be that useful...
Thank you
LaserSoft -
What is the Action Script (using AS2) code when you loop once a scene and then re-read and slaughter on a certain slice?
Basically, you need keep a count and use it as your stop control. In the first image, it takes something to assign the value, but you do not want to assign an initial value, so you could use...
var County;
if(Count == undefined) {}
Count = 0;
} else {}
Count ++;
}Then in the frame where you want to stop after that a loop is completed you can have...
if(Count == 1) {}
Stop();
}
-
How to operate only a calc script using ODI
Hi John,.
I would like to run only a calc script using ODi. Could if it you please let me know the process. Is it mentioned in your blog anywhere?
Awaiting your response
Thanks in advance
SravanThe km - 'IKM SQL for Hyperion Essbase (DATA)' there is an option 'RUN_CALC_SCRIPT_ONLY', set to Yes and then enter the name of the calc script in "CALCULATION SCRIPT".
It will take still a source and a target in the interface for it to run, but it will ignore the source and the target and just run the calc script, it is possible to customize the KM so it didn't need a source/target, but you should be fine with the method I proposed.See you soon
John
http://John-Goodwin.blogspot.com/ -
Export data to Oracle DB using ODI Essbase
I am trying to export data to Oracle DB using ODI essbase. When I create the schema with data source and target warehouses, my goal has error indicating that the target column has no capabilities of sql. I don't know what that means. Can anyone enlighten us? Thank you.This means that you have not defined a resting area for your columns on the target data store, as you use essbase in your interface, you need a rest area, essbase as a technology has no SQL features.
See you soon
John
http://John-Goodwin.blogspot.com/ -
How to import the XML file into an oracle table using a BPEL process
Hi friends
How can I import XML file in the db oracle table using a BPEL process
(1) I have generated an XML file in my local system with a field
(2) I created a temporary table in my oracledb with the same field in the XML file
(3) that I want to import these XML files which is the local host to my db oracle using a BPEL process
(4) for that what steps should I me fallow please suggest me if there is no document for this?
Thanks in advance
ATHi to
Here you go...
http://blogs.Oracle.com/ajaysharma/2011/03/using_file_adapter_database_adapter_and_mediator_component_in_soa_11g.html
I hope that helps!
Thank you
AJ -
service Oracle script does not...
a newbie question...
I installed oracle 11g R2 on Suse 11 and I created /etc/init.d/oracle script:
also, I changed the permission chmod 750 on thisORA_HOME=/opt/oracle/product/11.2.0/dbhome ORA_OWNER=oracle if [ ! -f $ORA_HOME/bin/dbstart ] then echo "Oracle startup: cannot start" exit fi case "$1" in 'start') #start oracle database su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl LISTENER11 start" su - $ORA_OWNER -c $ORA_HOME/bin/dbstart ;; 'stop') # Stop the Oracle databases: su - $ORA_OWNER -c $ORA_HOME/bin/dbshut su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl LISTENER11 stop" ;; 'Required-Stop') #aaa ;; esac
When I type chkconfig--add oracle, I received a message:
What did I miss?insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: warning: script 'S12oracle' missing LSB tags and overrides insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: warning: script 'oracle' missing LSB tags and overrides insserv: script oracle: service oracle already provided! insserv: script jexec is broken: incomplete LSB comment. insserv: missing `Required-Stop:' entry: please add even if empty. insserv: warning: script 'catalina.sh' missing LSB tags and overrides insserv: Default-Start undefined, assuming default start runlevel(s) for script `catalina.sh' insserv: warning: script 'setclasspath.sh' missing LSB tags and overrides insserv: Default-Start undefined, assuming default start runlevel(s) for script `setclasspath.sh' insserv: warning: script 'tomcat' missing LSB tags and overrides insserv: Default-Start undefined, assuming default start runlevel(s) for script `tomcat' insserv: exiting now! /sbin/insserv failed, exit code 1 oracle 0:off 1:off 2:off 3:on 4:off 5:off 6:off
Salvation;
Please close this thread as answered and update your other post which is available at:
service Oracle script does not...Respect of
HELIOS
Maybe you are looking for
-
Once I open the firefox browser with anything that this either spending 28.0 my browser becomes a paperweight without search from the address bar. Not in the list of the drop downs, do not type the address in the bar. Glued to the homepage there as a
-
I need a USB cord for my DSCWX 300
-
Satellite P200D-127 - where can I get a new card of mother?
Hello I have a Satellite P200D-127 (part number: PSPBLE-02100LEN) which has a tired motherboard. I have a white screen when I turn on the laptop. All lights are on and I can hear the HDD spinning in life, but nothing on the screen. I have tried just
-
Lenovo P780 - unable to connect to WiFi
Hello everyone, I have Lenovo P780 dual SIM mobile. All of these days, I was able to connect to the WiFi. But to leave the afternoon today, I'm getting "obtaining IP address" and "authentication...". "message alternatively and not able to connect to
-
Windows Vista and the problems that are
I'm running Office 2007 Pro in Vista and my programs are useless because of the uniform crashing. I tried to work and it also crashes. Google Earth will crash occasionally. I try running updates on the Microsoft site and it shows 22 update, but none