Loop & Instr question
Dear all,
I have a string that will spool to a file from sql*plus, and the string maybe more than 255 characters, e.g.:
v_sql := 'select surname, firstname, sex, birth,
address1, address2,
address3, ..., .... from employee;'
dbms_output.put_line(v_sql);
Now, I want to chop the string in several lines when 'meet' the comma ',' , the output I want become to, e.g.:
dbms_output.put_line('select surname,');
dbms_output.put_line('firstname,');
dbms_output.put_line('sex,');
dbms_output.put_line('... from employee;');
So, I use the loop and instr in a procedure:
procedure xxx (p_sql in varchar2) is
v_len number := length(p_sql);
v_comma number := 0;
v_next_comma number := 0;
v_string varchar2(1000);
begin
for v_cnt in 1..v_len loop
if v_comma = 0 then
v_comma := instr(p_sql, ',');
v_string := substr(p_sql, 1, v_comma-1);
dbms_output.put_line(v_string);
else
v_comma := instr(p_sql, ',');
v_next_comma := instr(substr(p_sql, v_comma+1, v_len-v_comma), ',');
v_string := substr(p_sql, v_comma+1, v_next_comma-1);
dbms_output.put_line(v_string);
end if;
if v_comma > 0 and v_next_comma = 0 then
v_cnt := v_comma +1; <--- v_cnt will not change
elsif v_next_comma > 0 then
v_cnt := v_next_comma +1;
end if;
end loop;
end xxx;
From the above coding, however, I found a problem that v_cnt will not skip to the 'comma' position. And I feel that it is not efficient if the length of the string is very long...
So, is there another way to do? Please help. Thank you!
Remarks: Database 10g.
Regards.
yes, it would see that you aren't running 10r2. here is the code you need
http://www.oraclecommunity.net/group/sqlplus/forum/topic/show?id=1988559%3ATopic%3A9386
the file - vsql.sql - is attached at the end. instead of using a cursor loop (curr_sql in my code) to get a statement, you'll just use your sql statement already in a variable. it's a simple procedure - breaks on certain keywords, or delimiters (like commas) before the linessize (132) is reached, and dbms_outputs the text.
changing the end of script to use a static sql statement:
begin
my_stmt := 'MERGE /*+ dynamic_sampling(ST 4) dynamic_sampling_est_cdn(ST) */ INTO STATS_TARG'||
'ET$ ST USING (SELECT STALENESS, OSIZE, OBJ#, TYPE#, CASE WHEN STALENESS > .5 THE'||
'N 128 ELSE 0 END + AFLAGS AFLAGS, STATUS, SID, SERIAL#, PART#, BO# FROM ( SELECT'||
' /*+ no_expand dynamic_sampling(4) dynamic_sampling_est_cdn */ DECODE(BITAND(T.F'||
'LAGS,16), 16, ROUND( LOG(0.01, NVL( LEAST( 100, GREATEST( 0.01, (DECODE(BITAND(M'||
'.FLAGS, 1), 1, GREATEST(T.ROWCNT, M.INSERTS), LEAST((M.INSERTS + M.DELETES ';
sql_frmt ( my_stmt, save_line, prefix );
if (save_line is not null) then
dbms_output.put_line( prefix || save_line );
save_line := null;
end if;
end;
MERGE /*+ dynamic_sampling ( ST 4 ) dynamic_sampling_est_cdn ( ST ) */ INTO STATS_TARGET$ ST USING (
SELECT STALENESS, OSIZE, OBJ#, TYPE#, CASE WHEN STALENESS > .5 THEN 128 ELSE 0 END + AFLAGS AFLAGS, STATUS, SID, SERIAL#, PART#,
BO#
FROM (
SELECT /*+ no_expand dynamic_sampling ( 4 ) dynamic_sampling_est_cdn */ DECODE ( BITAND ( T.FLAGS, 16 ), 16, ROUND ( LOG ( 0.01,
NVL ( LEAST ( 100, GREATEST ( 0.01, ( DECODE ( BITAND ( M.FLAGS, 1 ), 1, GREATEST ( T.ROWCNT, M.INSERTS ), LEAST ( ( M.INSERTS
+ M.DELETES
Similar Messages
-
CBO (optimizer) nest-loop join question
OS: Red Hat Linux
DB: 11gR1
I have gotten two conflicting answers while reading books by Don Burleson and Dan Hotka. It has to do with the CBO and nested-joins:
One says the CBO will choose the 'smaller' table as the driving table, the other states that the 'larger' table will be the driving table. And both stick by this philosophy as the preferred goal of any SQL Tuning -- that is, one states that the 'smaller' table should be the driving table. The other says the 'larger' table should be the driving table.
I had always thought that the 'smaller' table should be the driving table. That in a nested loop the driving will not likely use an index even. Who is correct? (I am not going to say who said what, btw). :-)
But I got to let one of them know they got a 'typo' ... :-)
Thx.user601798 wrote:
It is an over-simplistic scenario but, as I mentioned, if all other things are 'equal' -- which would include 'access time/work', then I think the small table as the driving table has the advantage.
It is not possible for +"*all* other things to be equal"+. (my emphasis).
If by +'access time/work'+ you mean the total is the same then it doesn't matter which table is first, the time/work is the same either way round.
If you want to say that the +'access time/work'+ for acquiring the first rowsource is the same for both paths, and the +'access time/work'+ for acquiring related rows from the second table is the same FOR EACH DRIVING ROW, then the total +'access time/work'+ will be difference, and it would be better to start with the smaller table. (The example by Salman Qureshi above: Re: CBO (optimizer) nest-loop join question would apply.)
On the other hand, and ignoring any idea of "all other things being equal", smaller tables tend to have smaller indexes, so if your smaller rowsource comes from a smaller table then acquiring those rows may be cheaper than acquiring rows from a larger table - which leads to the observation that (even with perfectly precise indexing):
<ul>
smaller number of rows * larger unit cost to find related rows
</ul>
may produce a larger value than
<ul>
larger number of rows * smaller unit cost to find related rows
</ul>
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
A general reminder about "Forum Etiquette / Reward Points": http://forums.oracle.com/forums/ann.jspa?annID=718
If you never mark your questions as answered people will eventually decide that it's not worth trying to answer you because they will never know whether or not their answer has been of any use, or whether you even bothered to read it.
It is also important to mark answers that you thought helpful - again it lets other people know that you appreciate their help, but it also acts as a pointer for other people when they are researching the same question, moreover it means that when you mark a bad or wrong answer as helpful someone may be prompted to tell you (and the rest of the forum) what's so bad or wrong about the answer you found helpful. -
Adding loops and loops format question
Hi, i've been facing difficulties adding loops into my GB. My problem is: "Loops do not appear in my loop browser nor the loop list from the silver loop bar above the browser".
Yes, forgive me for asking this repeated question but after checking the help tutorial, my personal GB guide books, and even HangTime's FAQ, sadly, i still dont find any answers.
Generally, the procedure is pretty simple from all the sources i've read. Simply drag the folder or loops into the browser and thats DONE right? I did exactly what it said but sigh...maybe there's something wrong with my Macbook?
For your information, all the loops that i've been adding are loops from CDs coupled with FutureMusic and ComputerMusic magazines, so i believe the sources are pretty reliable i hope.
As i was struggling to add the loops, this msg popped up for the first time; "Loops that are not in Apple format will not be added into GB"
So, is the loop format the main cause of my problem?
if yes, is there any way to convert the format? what is the procedure?
ps: My current status is, some loops i added are in my browser while some dont although they exist in User/Library/Audio/AppleLoops/UserLoops.
Thank you in advance.
PeaceSo, is the loop format the main cause of my problem?
likely.
if yes, is there any way to convert the format? what is the procedure?
apple's loop utility:
http://www.bulletsandbones.com/GB/GBFAQ.html#looputility
also note:
http://www.bulletsandbones.com/GB/GBFAQ.html#missingloops -
Hi all. My question is, are all of the loops provided in Logic, Garageband, or any of the Jampacks, free from copyright restrictions? Meaning when utilized for commercial purpose, do they need to be declared as samples, or is everything provided, basically up for grabs? Thanks!
I thought this was quite clear:
"2. Permitted License Uses and Restrictions.
This License allows you to install and use one copy of the Apple Software on a single Apple-labeled computer at a time. You may use the Apple and third party audio loop content (“Audio Content”), contained in or otherwise included with the Apple Software, on a royalty-free basis, to create your own original soundtracks for your video and audio projects.
You may broadcast and/or distribute your own soundtracks that were created using the Audio Content, however, individual samples, sound sets, or audio loops may not be commercially or otherwise distributed on a standalone basis, nor may they be repackaged in whole or in part as audio samples, sound libraries, sound effects or music beds." -
Closed loop configuration question
I have a motor(with encoder feedback) attached to a linear actuator(with end limit switches).
The motor has a commercially bought servo drive for control.
The servo drive will accept either a step/direction (2 seperate TTL
digital pulse train inputs) or an analog -10 to 10vdc input for
control.
The purpose is to drive a linear actuator(continiously in and out) in
closed loop operation utilizing a ( (SV) Setpoint variable)value from a
file converted to a frequency to compare with an actual ( (PV) Position
variable) measured frequency.
I have created and experimented with individual vi's allows analog
control and digital pulse train control (thankfully with the help of
examples).
Before I pose my question, I would like to make the following
observations: It is my understanding that Closed loop control
means that I dont need to know an exact position at which to drive, but
constant comparision of PV and SV through PID applictation.
Without getting into any proprietery information I can say that the
constant positioning of the linear actuator will produce a latency of 2
to 3 seconds based on the time the actuator moves to a new position and
when the PV will change. While experimenting with the analog
input, i noticed imediate response to motor velocity, but after the
motor is stopped, position is not held in place. However, while
experimenting with the Digital pulse train input, I noticed that the
servo drive can only accept one command at one time; if, halfway
through a move, position error produces a response to move the linear
actuator in the opposite or different direction, the origional move
must finish first.
Can anyone recommend the proper configuration for the closed loop control i have described?
If I can make the system work with the servo drive/motor I plan to use
the simple (pci 6014) daq card with the Analog out, or utilize the
digital out.
If I cant get this to work, we do have a pxi with 7344 motion card(I
would like to exhaust all efforts to use the PCI 6014 card).
Depending on where I go from here, I planned to use the PID vi's for the loop control.
Thanks,
Wayne HilburnThanks for the reply
Jochen. I realize there is a built-in latency with windows but I
think the I/O control would be ok. A change in actuator position
will not result in an immediate change in process variable; Is
there a way to measure the latency or is it calculated? A
satisfactory reaction time could be from 1 to 1.5 sec.
Use of the PCI-6014 is to supply the control output to the servo
drive/amp, and not to drive the motor itself. As stated earlier,
while using the 6014 board, I have the choice of digital or analog
output.
Currently I am at a point where I must choose which configuration,
analog control or digital control(in the form of digital pulse train),
(i am inserting from first message)
While experimenting with the analog
input, i noticed imediate response to motor velocity, but after the
motor is stopped, position is not held in place. However, while
experimenting with the Digital pulse train input, I noticed that the
servo drive can only accept one command at one time; if, halfway
through a move, position error produces a response to move the linear
actuator in the opposite or different direction, the origional move
must finish first. .
I dont claim to understand all the limitations with the
specific boards, however, i am using an approach that is showing me the
characteristics(a couple are listed in the above paragraph) of
the hardware and software configurations.
So I am really back to my origional question; Which configuration
would be better for closed loop control, analog or digital pulse train?
Thanks,
Wayne Hilburn -
Infinite Loop (newbye question)
Hi guys,
I have a question :
I am trying to have a piece of text blink by changing its alpha
To reach that goal I have two options :
- A Classic tween with Alpha variation and then go back to first frame
- Change the alpha with an AS3 script using loops
I am trying the second option for a smoother result .
Though I think that an infinite loop make Flash crash (which append indeed when I tested)
Do you know what I should add top the below code to make it work ?
I need to call 'decreasealpha' first then 'increasealpha' and back to 'decreasealpha' and this endlessly ... but don't know how to do it
var alphamax:Number = 0.40;
var alphamin:Number = 0.15;
Text_mc.alpha = alphamax;
function decreasealpha (a:MovieClip):void
while (a.alpha > alphamin)
a.alpha = a.alpha-0.01;
a.alpha=alphamin;
function increasealpha (a:MovieClip):void
while (a.alpha < alphamax)
a.alpha = a.alpha+0.01;
a.alpha = alphamax;
Many ThanksGet rid of the while loop altogether. Essentially you are not letting Flash update at each increment. Use timer to callback into your decrease/increase-alpha functions. Or better yet, use a tween simulater (like Tweener)...
protected function decreasealpha()
Tweener.addTween(Text_mc, {alpha:alphamin, time:1.0, onComplete:increasealpha});
protected function increasealpha()
Tweener.addTween(Text_mc, {alpha:alphamax, time:1.0, onComplete:decreasealpha});
Cheers,
Jason -
[SOLVED]Python3 If/Else Loop (Noob Question)
I'm learning python because of it's ease of use and mathematical libraries, and I decided to create a program to mess with loops.
Here is the program:
#!/usr/bin/python
#Filename: evil.py
print("*******************************************************************")
print("* Gorge of Eternal Peril Challenge *")
print("* *")
print("*******************************************************************")
print()
print()
ca2 = 'Blue'
ca3 = 'African or European Swallow?'
a1 = input('What... is Your Name?\n')
if a1 != int:
a2 = input('What... is Your Favorite Color?\n')
if a2 == ca2:
a3 = input('What... is The Airspeed Velocity of an Unladen \
Swallow?\n')
if a3 == ca3:
print(" I don't know that! AAAAAUUUUUUGGGHHHH...")
else:
print('AAAAAUUUUUUGGGHHHH You have been cast in to the Gorge of \
Eternal Peril!')
I'm not sure why, but it won't end up in the else statement. Also, if anyone can tell me how to exclude numbers from question one I'd be much obliged.
Thanks.
EDIT: Some strange things happened in this window. The Title box is lined up and the if statements are at the same tab
Last edited by duke11235 (2011-06-20 04:12:46)#!/usr/bin/python
#Filename: evil.py
print("*******************************************************************")
print("* Gorge of Eternal Peril Challenge *")
print("* *")
print("*******************************************************************")
print()
print()
ca2 = 'Blue'
ca3 = 'African or European Swallow?'
a1 = input('What... is Your Name?\n')
if a1 != int:
a2 = input('What... is Your Favorite Color?\n')
if a2 == ca2:
a3 = input('What... is The Airspeed Velocity of an Unladen \
Swallow?\n')
if a3 == ca3:
print(" I don't know that! AAAAAUUUUUUGGGHHHH...")
else:
print('AAAAAUUUUUUGGGHHHH You have been cast in to the Gorge of \
Eternal Peril!')
do it like this:
#!/usr/bin/python
#Filename: evil.py
print("*******************************************************************")
print("* Gorge of Eternal Peril Challenge *")
print("* *")
print("*******************************************************************")
print()
print()
def questions():
ca2 = 'Blue'
ca3 = 'African or European Swallow?'
a1 = input('What... is Your Name?\n')
if type(a1) is str:
a2 = input('What... is Your Favorite Color?\n')
if a2 == ca2:
a3 = input('What... is The Airspeed Velocity of an Unladen \
Swallow?\n')
if a3 == ca3:
print(" I don't know that! AAAAAUUUUUUGGGHHHH...")
return true
else: return false # Else of if a3 == ca3
else: return fase # Else of if a2 == ca2
else: return false # Else of if type(a1) statement
if questions(): pass
else: print('AAAAAUUUUUUGGGHHHH You have been cast in to the Gorge of \
Eternal Peril!')
Last edited by markbabc (2011-06-20 02:48:07) -
SQL Statement as Loop - easy question?
Am reading from S. Feuerstein's book:
DECLARE
CURSOR checked_out_cur IS
SELECT pet_id, name, checkout_date
FROM occupancy WHERE checkout_date IS NOT NULL;
BEGIN
FOR checked_out_rec IN checked_out_cur
LOOP
INSERT INTO occupancy_history (pet_id, name, checkout_date)
VALUES (checked_out_rec.pet_id, checked_out_rec.name, checked_out_rec.checkout_date);
My question is - where did checked_out_rec came from? Doesn't look like it's declared.
Thanks,http://www.unix.org.ua/orelly/oracle/prog2/ch07_07.htm
In fact the very next section begins,
"This will work just fine. But do we really need to use a cursor FOR loop to accomplish this task?"
(I think the above is from an earlier edition of the book, but later editions make the same point.)
If you flip back a couple of pages there is whole section on the convenience of the implicit record declaration, along with the implicit open, fetch and close. -
Can the loops be used to create my own song and be able to copyright this for myself or are the loops protected by Apple copyright?
ZekeThe2nd wrote:
Can the loops be used to create my own song and be able to copyright this for myself
Yes - although you don't really copyright your song, that happens automatically as soon as you create it. Registering copyright is what requires you to do something.
or are the loops protected by Apple copyright?
As I understand it, only to the extent that you couldn't sell them as your loops. However, you're allowed to use them in your music, in which you own the copyright. -
Nested FOR cursor LOOPs, BASIC QUESTION
Hello,
I am trying to nest a For-loop using a cursor (see below), but the program is not entering the second (nested) for-loop. This program compiles fine, but during run-time, the nested loop does not execute. I'd rather not use FETCH statements and keep everything in place. I think the solution is rather trivial, but I'm new to PL/SQL. PLEASE HELP!!!!!
cursor c1 is
select coi_con_uid,coi_not_code,coi_closed_yn,coi_timestamp
from s_coi_con_issue
where coi_not_code = 'NOT107'
and coi_timestamp <= v_aweekago
and coi_closed_yn = 'N';
cursor c2 is
select tsk_uid
from s_tsk_task
where tsk_status in ('C')
and tsk_tty_code = 'CONTAC'
and tsk_date_end = '' FOR UPDATE;
BEGIN
select to_date(sysdate - 7) into v_aweekago from dual;
DBMS_OUTPUT.PUT_LINE('System date used is ' || v_aweekago);
FOR coi_row in c1 LOOP
v_tsk_cnt := 0;
v_coi_row_cnt := v_coi_row_cnt + 1;
v_con_uid := rtrim(to_char(coi_row.coi_con_uid));
v_tsk_act_str := ('"CON_UID","' || v_con_uid || '"') ;
DBMS_OUTPUT.PUT_LINE('COI_CON_UID: ' || v_con_uid);
DBMS_OUTPUT.PUT_LINE('v_tsk_act_str: ' || v_tsk_act_str);
-----The Program is not entering into this Loop
FOR tsk_row in c2 LOOP
v_update_cnt := v_update_cnt + 1;
update s_tsk_task
set tsk_status = 'A'
where tsk_uid = tsk_row.tsk_uid and
tsk_action_string = v_tsk_act_str;
DBMS_OUTPUT.PUT_LINE('----Task updated');
END LOOP;
END LOOP;
COMMIT;using your query on your cursor c2 when you execute it on sql*plus did it return any rows?
select tsk_uid
from s_tsk_task
where tsk_status in ('C')
and tsk_tty_code = 'CONTAC'
and tsk_date_end = ''; if not it might have something to do with the predicates in your where clause
and tsk_date_end = '';consider revising your c2 cursor select statement to something like:
cursor c2 is
select tsk_uid
from s_tsk_task
where tsk_status = 'C'
and tsk_tty_code = 'CONTAC'
and tsk_date_end IS NULL
FOR UPDATE; -
Can you some how bring up the selected transient spots of a created apple loop into Logic for chopping purposes? then import them into an exs instrument? and if so will the chops adjust accordingly when the tempo is changed on the transport?
thanks
DahNo,
If you want to do that , you need to get Recycle from Propellerheads.
The guys who make Reason,
With Recycle, you can open a Wave or Aiff file, make the slice markers and save it as a Rex file.
You can import a Rex file into EXS and do what you describe. -
why do some of the loops in the (assumed to be) default folder not appear in the garageband loop browser.
no drums seem to appear in the loop browser...And when you click the "Drums" button, absolutely nothing shows up?
-
For-Loops: The question no one asks.
Why don't For-Loops have a premature exit capability --- i.e. why didn't
NI include the exit capability that exists in other languages? Is it a dataflow
thing? I don't see how. Just curious.Jay,
I have to say I`m no programming Guru, but isn`t a State Maschine based on a
case (Switch) statement? This statement does allow the user to hop to and
fro within a certian pre-defined space, but the use of a GOTO is, as far as
I am aware, not limited to a particular region of the code. At least with a
switch statement (Case) the beginning point of each "choice" is well defined
and fixed, therefore reducing the change of mistakes.
just my 2 cents
Shane
Jay schrieb in Nachricht <[email protected]>...
>
>Hey, Tim. You say:
>
>>I believe that the loop exit capability wasn't included because it was
considered
>bad programming practice, like using goto's.
>
> That's funny. How can it be any worse (or different) than putt
ing exit
>logic into a While-Loop? As for Goto's, they're the basic logic behind the
>much revered State Machine, and no one seems to mind that. If you're not
>careful, State Machines can wind up producing some pretty good spaghetti
>code, just like any text-based code can do.
>
>Jay
>
>>> Original message: Why don't For-Loops have a premature exit capability
>--- i.e. why didn't NI include the exit capability that exists in other
languages?
> Is it a dataflow thing? I don't see how. Just curious.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2) -
If I have an apple loop which I want to play at twice the tempo of the song I'm using it in, how do I do it? My song is at 80 bpm and when I drop my apple loop in I want it to play back at 160 bpm not 80 bpm. Is there an easy way to do this?
- solo the audio track w/ loop in it
- set logic to 160 bpm
- bounce the loop & add to audio window
- set logic back to 80 bpm, create new audio track & insert bounced audio
- un-solo -
Dbms_lob.instr question
Hello,
I have a field that holds CLOBs in the database. I have a textfield in which the user can enter a target string, then I hope to use dbms_lob.instr to search for the target string in CLOB. The code looks like: dbms_lob.instr(upper(I.COMMENTS),upper(nvl(:P26_SEARCH_NAME,I.COMMENTS))). If I replace the textfield value :P26_SEARCH_NAME with a string, the line works fine, but the current line returns the error
ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 6250, maximum: 4000) Can someone offer some help with a fix?Steven - Try v('P26_SEARCH_NAME') as a test to see if it makes any difference. If not, I can look at your test case if you put it on apex.oracle.com.
Scott
Maybe you are looking for
-
The no of character in alv top of page
i have to display k: Share\MM_SCUBCode_PDAtxt_Upload\OUT-1090000017-200903171823 - LY 2.txt in the alv top of page but it is taking k: Share\MM_SCUBCode_PDAtxt_Upload\OUT-1090000017-200903171823. any idea how to do it please check my code form top_of
-
Power Nap through Ethernet adapter
Hi, I am wondering what kind of network interface Power Nap can use : wireless, wired, wired via ethernet adapter (USB or Thunderbolt)? I am using a 2012 MBA mainly connecting to the Internet with an Ethernet Thunderbolt adapter. Will Power Nap be ab
-
Hello, At the time of creating the invoices (MIRO) we have accidentally enter the full quantity and posted the invoice and made the payment. But later found out the quantities we have enter is not correct and we want to reverse the payment clearing.
-
Hi, i'm trying to use auto deployement to make the descriptors for my ejb1.1, but the problem is that in the weblogic.jar file, there isn't an ejb11 dir (weblogic.ant.taskdefs.ajb11.DDInit) -> so i thought that wls was s
-
Hi, I moved my iPhoto library to Aperture over a year ago and so far this has been an excellent move. Previously in my iPhoto library I would import RAW+JPEG. Once the import was completed in iPhoto I would export the raw to an external hard drive fo