How to remove unnecessary line breaks in SQL Plus Spooling? - sql

I am spooling a package from a database and this is what I get:
CREATE OR REPLACE PACKAGE BODY "CPI"."GIPI_WBOND_BASIC_PKG"
AS
FUNCTION get_gipi_wbond_basic (p_par_id gipi_wbond_basic.par_id%TYPE)
RETURN gipi_wbond_basic_tab PIPELINED
IS
v_wbond gipi_wbond_basic_type;
BEGIN
FOR i IN (SELECT a.par_id, a.obligee_no, a.bond_dtl, a.inde
mnity_text,
a.clause_type, a.waiver_limit, a.contract_date, a.cont
ract_dtl,
a.prin_id, a.co_prin_sw, a.np_no, a.coll
_flag,
a.plaintiff_dtl, a.defendant_dtl, a.civil_case_no
FROM gipi_wbond_basic a
WHERE a.par_id = p_par_id)
And I am expecting it to be something like this:
CREATE OR REPLACE PACKAGE BODY cpi.gipi_wbond_basic_pkg
AS
FUNCTION get_gipi_wbond_basic (p_par_id gipi_wbond_basic.par_id%TYPE)
RETURN gipi_wbond_basic_tab PIPELINED
IS
v_wbond gipi_wbond_basic_type;
BEGIN
FOR i IN (SELECT a.par_id, a.obligee_no, a.bond_dtl, a.indemnity_text,
a.clause_type, a.waiver_limit, a.contract_date,
a.contract_dtl, a.prin_id, a.co_prin_sw, a.np_no,
a.coll_flag, a.plaintiff_dtl, a.defendant_dtl,
a.civil_case_no
FROM gipi_wbond_basic a
WHERE a.par_id = p_par_id)
Please help me on how can I get rid of those new lines and ugly format. Thanks!

Ok this one solved my problem.
From this,
SET HEADING OFF;
SET ECHO OFF;
SET PAGES 999;
SET LONG 999999;
I added this:
SET LONGCHUNKSIZE 999999;
SET PAGESIZE 0;
SET LINESIZE 500;

TO remove extra Line breaks Try :-
SET FEED OFF

Additionally (to ladiesman1792's own answers, which were below this post when I posted!):
column text format a120 --<< will wrap at 120 chars (maybe bytes, not sure on that)
This is an Oracle sqlplus directive, as per the other answers.

You can do it using the regular expression in SSMS:
1) Ctrl-H to bring up the Find And Replace window
2) Select USE -> Regular Expressions
3) Put ^\n in the Find What
4) Keep Replace With empty
5) Click Replace (All)
Good luck
-- Nilesh Umaretiya (India)

Related

Foxpro String Variable combination in Forloop

As in title, there is an error in my first code in FOR loop: Command contains unrecognized phrase. I am thinking if the method string+variable is wrong.
ALTER TABLE table1 ADD COLUMN prod_n c(10)
ALTER TABLE table1 ADD COLUMN prm1 n(19,2)
ALTER TABLE table1 ADD COLUMN rbon1 n(19,2)
ALTER TABLE table1 ADD COLUMN total1 n(19,2)
There are prm2... until total5, in which the numbers represent the month.
FOR i=1 TO 5
REPLACE ALL prm+i WITH amount FOR LEFT(ALLTRIM(a),1)="P" AND
batch_mth = i
REPLACE ALL rbon+i WITH amount FOR LEFT(ALLTRIM(a),1)="R"
AND batch_mth = i
REPLACE ALL total+i WITH sum((prm+i)+(rbon+i)) FOR batch_mth = i
NEXT
ENDFOR
Thanks for the help.
There are a number of things wrong with the code you posted above. Cetin has mentioned a number of them, so I apologize if I duplicate some of them.
PROBLEM 1 - in your ALTER TABLE commands I do not see where you create fields prm2, prm3, prm4, prm5, rbon2, rbon3, etc.
And yet your FOR LOOP would be trying to write to those fields as the FOR LOOP expression i increases from 1 to 5 - if the other parts of your code was correct.
PROBLEM 2 - You cannot concatenate a String to an Integer so as to create a Field Name like you attempt to do with prm+i or rbon+1
Cetin's code suggestions would work (again as long as you had the #2, #3, etc. fields defined). However in Foxpro and Visual Foxpro you can generally do a task in a variety of ways.
Personally, for readability I'd approach your FOR LOOP like this:
FOR i=1 TO 5
* --- Keep in mind that unless fields #2, #3, #4, & #5 are defined ---
* --- The following will Fail ---
cFld1 = "prm" + STR(i,1) && define the 1st field
cFld2 = "rbon" + STR(i,1) && define the 2nd field
cFld3 = "total" + STR(i,1) && define the 3rd field
REPLACE ALL &cFld1 WITH amount ;
FOR LEFT(ALLTRIM(a),1)="P" AND batch_mth = i
REPLACE ALL &cFld2 WITH amount ;
FOR LEFT(ALLTRIM(a),1)="R" AND batch_mth = i
REPLACE ALL &cFld3 WITH sum((prm+i)+(rbon+i)) ;
FOR batch_mth = i
NEXT
NOTE - it might be good if you would learn to use VFP's Debug tools so that you can examine your code execution line-by-line in the VFP Development mode. And you can also use it to examine the variable values.
Breakpoints are good, but you have to already have the TRACE WINDOW open for the Break to work.
SET STEP ON is the Debug command that I generally use so that program execution will stop and AUTOMATICALLY open the TRACE WINDOW for looking at code execution and/or variable values.
Do you mean you have fields named prm1, prm2, prm3 ... prm12 that represent the months and you want to update them in a loop? If so, you need to understand that a "fieldName" is a "name" and thus you need to use a "name expression" to use it as a variable. That is:
prm+i
would NOT work but:
( 'pro'+ ltrim(str(m.i)) )
would.
For example here is your code revised:
For i=1 To 5
Replace All ('prm'+Ltrim(Str(m.i))) With amount For Left(Alltrim(a),1)="P" And batch_mth = m.i
Replace All ('rbon'+Ltrim(Str(m.i))) With amount For Left(Alltrim(a),1)="R" And batch_mth = m.i
* ????????? REPLACE ALL ('total'+Ltrim(Str(m.i))) WITH sum((prm+i)+(rbon+i)) FOR batch_mth = i
Endfor
However, I must admit, your code doesn't make sense to me. Maybe it would be better if you explained what you are trying to do and give some simple data with the result you expect (as code - you can use FAQ 50 on foxite to create code for data).

Delete specific word at the beginning

in my table within some columns i got strings which starting always with /PicsDB
like this below:
/PicsDB/Something 2015/Some thing bla/Some thing other/img34234.jpg
what i want to achieve is to for each row delete starting string /PicsDB
so using above string the final result should be:
/Something 2015/Some thing bla/Some thing other/img34234.jpg
How to achieve that?
Can i just simply do ? :
UPDATE my_table SET path = replace(path, '/PicsDB', '');
Just use substring:
UPDATE my_table SET path = substring(path, 8, 9999);
where path like '/PicsDB%'

Making an SQL prodedure to add characters to a string

Hi I'm trying to make a procedure in SQL that adds a bunch of zeroes to a string to complete its length to 18 characters for example:
0446793932' ====> '000000000446793932
and this procedure would go inside an update command,
UPDATE Table SET variable = prototype_procedure('0446793932') WHERE .......
I don't know much about SQL or procedures, if anyone could guide me through something that could help me understand, I would appreciate,
You can use REPLICATE function to achieve what you want.
http://msdn.microsoft.com/en-us/library/ms174383.aspx
DECLARE #t NVARCHAR(10) = N'0446793932'
SELECT #t, REPLICATE(N'0', 18 - LEN(#t)) + #t
depending on what language you are using along the SQL, your best bet is to just add the characters to the string before you send the data to database, that way you don't risk screwing up your tables.
I would using something like this in php for example:
$myvar = "123456";
$myvarLength = strlen($myvar);
if($myvarLength < 12){
while{$myvarLength != 12){
$myvar = "0".$myvar;
$myvarlength = strlen($myvar);
}
}
This should get the job done for you

sql to set an xml value

I'm a novice in mySql.
I'm trying to replace a value in the xml column of my table.
my select method works.
SELECT * FROM `comics` WHERE ExtractValue(xml,'comic/pageNumber') = 6
my replace method doesn't. I've been searching for the correct syntax for a bit now...
SET xml.modify(
replace value of ('comic/pageNumber') with 5
)
some background:
this situation comes up when i delete a comic page.
it leaves a gap in the page numbers, after which i would either:
iterate through all the comics and remove any gaps in the page numbers.
or
iterate through all comics with pageNumber larger than the deleted page, and reduce their pageNumber by 1.
How about
UPDATE comics
SET xml = UpdateXML(xml,'comic/pageNumber', '<pageNumber>5</pageNumber>')
WHERE ExtractValue(xml,'comic/pageNumber') = 6
Tested on MySQL version 5.1
UPDATE `comics`
SET xml = UpdateXML(xml,
'comic/pageNumber',
concat('<pageNumber>',(ExtractValue(xml,'comic/pageNumber')+1),'</pageNumber>'))
WHERE ExtractValue(xml,'comic/pageNumber') >= 1
You'd be better off actually storing the fields in the table, rather than a single field with xml in it. Then the following would work. Otherwise there's not much point using a relational database at all.
BEGIN;
DELETE FROM `comics`
WHERE `comicID` = :id AND `pageNumber` = :page;
UPDATE `comics` SET `pageNumber` = `pageNumber` - 1
WHERE `comicID` = :id AND `pageNumber` > :page;
COMMIT;

Using comma with an update sentence

I want to update a row which has some html tags inside. For instance:
src='/imagem.png'></ p></ body>
> UPDATE ISTANBUL_TABLE SET TEXT = '<
> body>< p>< img src='/imagem.png '></
> p></ body>' WHERE 1=1
You see after src=' means the query ends, but it does not end. How can i solve it without using " (double comma)? Any solution please?
best regards bk
You need to escape the single-quotes, by typing them twice:
UPDATE ISTANBUL_TABLE SET TEXT = '< body>< p>< img src=''/imagem.png ''>' WHERE 1=1
Also, your WHERE clause is nonsensical and can be dropped entirely
UPDATE ISTANBUL_TABLE SET TEXT = '<body><p><img src=''/imagem.png''>'
Use parameterised SQL:
UPDATE ISTANBUL_TABLE SET TEXT = #HTML WHERE...
Then from your calling code, you just pass in the #HTML parameter and don't need to double up the single quotes.