Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all 13329 articles
Browse latest View live

Multiple cursors Infinite loop

$
0
0
Hi,

I have written one procedure . every thing is working fine. But My first loop is entering into infinite loop. I tried to resolve this but unable to get .sorry for posting my code. I am missing something here .
can some one kindly help me out.



CREATE PROCEDURE proc1 ()
DYNAMIC RESULT SETS 5
P1: BEGIN

DECLARE curr_db_name varchar(32672);
DECLARE p_db_name varchar(32672);
DECLARE p_table_name varchar(200);
DECLARE db_name varchar(32672);
DECLARE table_name varchar(200);
DECLARE column_name varchar(200);
DECLARE column_id varchar(200);
DECLARE s_column_type_id varchar(200);
DECLARE encryption_method varchar(20);
DECLARE id_use varchar(240);
DECLARE id_use2 varchar(240);
DECLARE column_length float;
DECLARE dynsqlstr varchar(32672);
DECLARE l_col_specific_str varchar(32672);
DECLARE l_table_specific_set_str varchar(32672);
DECLARE JOB_ID INTEGER;
DECLARE LOG_PROCESS varchar(32672);
DECLARE l_row_count INTEGER;
DECLARE l_error INTEGER;
DECLARE l_column_list varchar(1000);
DECLARE L1 VARCHAR(32672);
DECLARE L2 VARCHAR(32672);
DECLARE TEXT VARCHAR(32672);
DECLARE ENCR_STMT VARCHAR(32672);
DECLARE COL_STMT VARCHAR(32672);
DECLARE ID_STMT VARCHAR(32672);
DECLARE L1_STMT VARCHAR(32672);
DECLARE L2_STMT VARCHAR(32672);
DECLARE STMT2 VARCHAR(32672);
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';

DECLARE l_select_str varchar(1000);
DECLARE l_query varchar(1000);
DECLARE l_from_str varchar(1000);
DECLARE l_join_str varchar(2000);
DECLARE l_where_str varchar(1000);
DECLARE l_groupby_str varchar(1000);
DECLARE l_chunk INTEGER;
DECLARE exitcode INTEGER DEFAULT 0;


-- Declare cursor
DECLARE wo_cursor_orangezi CURSOR WITH RETURN for
select zi.OWNER DB_NAME,zi.MT_NAME TABLE_NAME,total_complex_columns as max_chunk
FROM orangezi as zi, orangezi_counts as zic
WHERE COALESCE(truncate_flag, 'N') = 'N'
and zi.owner = zic.owner
and zi.mt_name = zic.mt_name
and zic.total_rows > 0
order by 1, 2 ;

DECLARE wo_cursor_orangeziC CURSOR WITH RETURN for STMT1;

DECLARE CONTINUE HANDLER FOR NOT FOUND
SET exitcode = 1;

--DECLARE CONTINUE HANDLER FOR SQLSTATE '02000'

-- Getting Job ID

OPEN wo_cursor_orangezi;

-- Fetching values from First cursor
FETCH FROM wo_cursor_orangezi
INTO
p_db_name,
p_table_name,
m_i;

wloop1:
WHILE (SQLCODE = 0)
DO
--IF (exitcode =1)
--THEN
--LEAVE wloop1;
--END IF;



SET TEXT = ('select zi.OWNER as DB_NAME,zi.MT_NAME as TABLE_NAME,zic.MCL_NAME as COLUMN_NAME,zic.ENCR_METHOD as ENCRYPTION_METHOD,
zic.ID_USE ID_USE,zic.ID_USE2 ID_USE2 FROM orangezi as zi, orangeziC as zic WHERE zic.MT_ID = zi.MT_ID
and zic.orangeC_ID = zi.orangeC_ID and zi.OWNER =''' || p_db_name || ''' and zi.MT_name =''' || p_table_name || '''
and zic.encr_method <> ''SRD'' and ENCR_METHOD <> ''T'' and ENCR_METHOD <> ''Z'' order by sort_order');

PREPARE STMT1 FROM TEXT;

SET l_table = NULL;

OPEN wo_cursor_orangeziC;

-- Fetching values from dynamic cursor
FETCH FROM wo_cursor_orangeziC
INTO db_name,
table_name,
column_name,
encryption_method,
id_use,
id_use2;


SET l_col_specific_str = NULL;

wloop2:
WHILE (SQLCODE = 0 )
DO

-- Fetching function based on Encryption code
SET STMT2 ='set ? = (SELECT l_r FROM orange_u where CODE = ''' || encryption_method ||''')' ;
PREPARE S1 FROM STMT2;
EXECUTE S1 into ENCR_STMT;
set l_col_specific_str = ENCR_STMT;

SET L1= 'set ? =(SELECT LOCATE ('||'''<<COL>>''' || ',''' || l_col_specific_str ||''',1) FROM SYSIBM.SYSDUMMY1)';
PREPARE S1 FROM L1;
EXECUTE S1 into L1_STMT;

-- Replacing column name
IF (L1_STMT > 0 )
THEN
SET STMT2 = 'set ? =(SELECT REPLACE ('''|| l_col_specific_str ||''','|| '''<<COL>>''' || ',''' || COLUMN_NAME ||''') FROM SYSIBM.SYSDUMMY1)';
PREPARE S1 FROM STMT2;
EXECUTE S1 into COL_STMT;
set l_col_specific_str = COL_STMT;

END IF;

SET L2 = 'set ? =(SELECT LOCATE ('||'''<<ID_USE>>''' || ',''' || l_col_specific_str ||''',1) FROM SYSIBM.SYSDUMMY1)';
PREPARE S1 FROM L2;
EXECUTE S1 into L2_STMT;

-- Replacing value for date function
IF (L2_STMT > 0 )
THEN
SET STMT2 = 'set ? =(SELECT REPLACE ('''|| l_col_specific_str ||''','|| '''<<ID_USE>>''' || ',''' || COLUMN_NAME ||''') FROM SYSIBM.SYSDUMMY1)';
PREPARE S1 FROM STMT2;
EXECUTE S1 into ID_STMT;
set l_col_specific_str = ID_STMT;

END IF;

SET l_table = l_table || l_col_specific_str ;

FETCH FROM wo_cursor_orangeziC
INTO db_name,
table_name,
column_name,
encryption_method,
id_use,id_use2;

IF (exitcode = 1)
THEN
LEAVE wloop2;
END IF;

IF (SQLCODE = 0)
THEN
SET l_tabler = l_table || ',';
END IF;

-- Get the next column to work with
---END LOOP loop_over_cursor_orangeziC;

END WHILE;



-- calling update stateorange
--call ZYNSQ(l_tabler,l_i,p_db_name,p_table_name);
-- Cursor left open for client application
---OPEN cursor1;


CLOSE wo_cursor_orangeziC;

FETCH FROM wo_cursor_orangezi
INTO
p_db_name,
p_table_name,
l_chunk;


END WHILE;

--CLOSE wo_cursor_orangeziC;
CLOSE wo_cursor_orangezi;
END P1


error:

wloop1 Infinite loop. can some one tell me how to exit from the first loop.


Thanks

Macro for a selected range

$
0
0
Hello, this is my very first post, so bear with me.

We have a standard format we need charts in excel to be, so I thought it would be useful to make macros to put the chart into the correct format. I recorded the following using the recorder, and I thought I could just change what it effects to the selected cells. However, I have found very little out there helpful. Any help is always apprecieated. :)

Code:

Sub Chart_Body_Format()
'
' Chart_Body_Format Macro
' Format chart body to Novus Format
'
' Keyboard Shortcut: Ctrl+Shift+B
'
   
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
End Sub

Is ACTIVATE db the same as CONNECT TO DB ?

$
0
0
Is db2 ACTIVATE DB <dbname> the same as db2 CONNECT to <dbname> ? What is the difference in terms of back-end behaviour? I don't think they are the same because when we activate DB, STMM turns on, mem tunning turns on. Do Logs start to archive when DB is activated. What if it is deactivated, the logs won't archive?

Please advise, thank you

Help with question on database being moved and now web tool is broken

$
0
0
Hi!
I am a newbie to PHP and databases. I would appreciate any help on this! For my job, the database being used by a web tool on our site has been moved (to a new location or server, not sure which). Thus, the url for the data source that this web tool accesses and uses has been changed. As a result, the web tool is not currently working. The website is using javascript and the web tool is using PHP. The website host tells me that I "need to craft another url that will grab the data from the proper directories or migrate the CGI script to the new machine". I am not sure what this means or how to proceed? Help?! THANKS!!!!!
tillsey 

OnChange insert Date

$
0
0
Hi all

Just a little help please...

I have created a very simple database to capture marketing data.

I have a form which is linked to a table. On the form are fields such as, company name, contact name and Email address. The Email Address field is always blank and needs to be populated when we identify what it is.

Another field is [Date Changed], which its default is also blank (format date/time).

Could you please advise what code I should add to the Event/OnChange to the [Email Address] field so that when the field is changed, the Now() data will be inserted in the [Date Changed] field?

Thanks
Gary

Removing Headers from multiple files while concatenating

$
0
0
HI,
I have a requirement to merge multiple files into one.All the files are of the same type with same number of columns and exact column names as Header.
When i merge all these files using cat command,i see the big file is getting all the header rows as well from multiple files.I tried many different ways but couldn't figure it out the header rows from the files.I only need one header row and the data from all the multiple files.

I have test1 ,test2,test3 ....testn with all the same header row .

cat > $working\test*.csv >$working\bigfile.csv

when i concatenated the bigfile.csv getting all the header records as well.Can anyone please guide me hoe to rid of the header rows from second file onwards,i only need one header row in the bigfile.

Thanks,
Murali

Auto System Current Date and Time

$
0
0
Hi there guys,

I would like to ask for help on what scripts and behavior to execute to let the Database automatically input the DATE and TIME?

Please help.

Thank a lot :)

I don't want to use FOR EACH ROW condition in trigger

$
0
0
Hi All,

I have created a trigger in my database for updation of previous year values while i upload data into RS_KPI_DLR_DETAIL table.

here is the Trigger definition-

CREATE TRIGGER ASPECT.RS_DLR_PREV_VALUE_TRIGGER
AFTER INSERT ON ASPECT.RS_KPI_DLR_DETAIL
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
CALL ASPECT.RS_DEALER_PREV_DATA_POPULATE('81930');
END


Here RS_DEALER_PREV_DATA_POPULATE is my procedure that i want to trigger when i insert data into RS_KPI_DLR_DETAIL table.

So this is working fine, but this is working with each row insertion, and i have a excel file by which i will populate 10000 rows at a time.

So i want that this RS_DEALER_PREV_DATA_POPULATE procedure will run after whole data insertion.

I doesn't want FOR EACH ROW MODE in my trigger. how it is possible.:confused:

Can anyone help me.

Thanks in advance.

DISTINCT not working

$
0
0
I have a table 'advice' which contains various fields including:
clientid, clientname, adviceid and date

I want to get a list out which has everybody who has received advice in it but which only lists the person once no matter how many times they have visited.

I have tried

SELECT DISTINCT clientid, clientname, adviceid FROM advice ORDER BY clientid ASC

but this doesn't remove duplicates from the list.

What am I do wrong?

Many thanks

Package in db2

$
0
0
Hi,

I have a scenario & i accomplished that using 2 procedures . But my requirement is to make that 2 procedures into a single package. I am new to db2 , Now I came to know how to write procedures .
what is a package in db2luw/udb?
How can i combine 2 procedures into a Db2 package.Any steps to this conversion?
can i debug a package as if I done for a procedure.

can some one help me out .

Calculated column reference in DB2

$
0
0
I have a table with the columns:date1,name and price. What i want to do is to add 2 columns one right having the minimum and maximum dates of the consecutive dates of the same name.
I have written the following query that explains the rule:
select date1,name,price
case
when lag(name,1) over(order by date1 ASC,name ASC)=name then lag(minDate,1) over(order by date1 ASC,name ASC)
else date1
end as minDate,
case
when lag(name,1) over(order by date1 DESC,name DESC)=name then lag(maxDate,1) over(order by date1 DESC,name DESC)
else date1
end as maxDate
from MyTable order by date1 ASC,name ASC
My problem is that i get an "invalid context for minDate/maxDate" (SQLCODE=-206, SQLSTATE=42703) Why can't i refer to a calculated column? Is there any other way?

How to edit BLOB values in "IBM data studio" Version 4.1.0.2

$
0
0
Hi,

In my project work, I copy data from one database to another for particular record.

For a BLOB data, we follow the following technique:

1) Open the Data studio Version 3.1.1.0.
2) Right click on the table and Select 'Data' and click 'Edit'. This opens the data in spreadsheet format .
3) When we move the cursor to the BLOB column, we get a small button.
4) When we click on the button, the BLOB is editable in a dialogue box. From there we will copy the data and paste in the table column in the another database.

But, Last week , the Data studio was upgraded to Version 4.1.0.2.

When the data of a table is opened in a editable format, we are not able to copy the BLOB column data?

Any idea anybody?

How to join the result of two queries

$
0
0
Guys,

I have two tables and I get the count of them like this:

--First

SELECT EXTRACT(YEAR FROM L.DATAHORALCTOFIS) ANO, COUNT(*) LANCAMENTOS
FROM LCTOFISENT L
WHERE L.ORIGEMDADO IN (1,2,3)
GROUP BY ANO
ORDER BY ANO

Result:
ANO LANCAMENTOS
2009 2100
2010 1385
2011 1289
2012 1525
2013 1621
2014 866

--Second

SELECT EXTRACT(YEAR FROM L.DATAHORALCTOFIS) ANO, COUNT(*) LANCAMENTOS
FROM LCTOFISENT L
WHERE L.ORIGEMDADO IN (1,2,3)
GROUP BY ANO
ORDER BY ANO

Result:
ANO LANCAMENTOS
2009 6588
2010 4772
2011 5122
2012 5190
2013 3379
2014 496


What I need:
Join the result of this two queries in one. Like this:
2009 8688
2010 6157
2011 6411
2012 6715
2013 5000
2014 1362


Any help???

Thanks in advance.

Grant seelct on all objects in a schema to a user

$
0
0
How to grant select on all objects in a schema to a user . I want this grant to be available on new objects that will be created in the schema ..

Devart Introduces dbForge Studio for SQL Server 4.0 with T-SQL Code Analyzer

$
0
0
Devart announces the release of dbForge Studio for SQL Server, v4.0. The new version introduces new general features:

T-SQL Code Analyzer

T-SQL Code Analyzer is a code analyzing utility that can identify possible defects and check T-SQL code for compliance with best practices. To fine tune the T-SQL analysis process you can create code analysis profiles and edit them according to your needs.

Visual Index Editor

New individual editors for each type of indexes:
- Clustered
- Nonclustered
- Primary XML
- Secondary XML
- Spatial
- Nonclustered columnstore index

Custom mapping for objects by their names

While comparing database schemas you can manually connect objects that that do not have identical names to map them. Objects mapping even allows you to compare tables with different names in different database types.

Server Events Profiler

SQL Server Profiler is a GUI to SQL Trace for monitoring an instance of the SQL Server Engine. By using SQL Server Profiler you can:
- Create a trace
- Watch the trace results as the trace runs
- Store the trace results in a table
- Start, stop, pause, and modify the trace results as necessary
The events are saved in a trace file that can later be analyzed or used to replay a specific series of steps when trying to diagnose a problem.

Improved Performance

The application performance has been significantly improved. Now it supports Windows 10 and works faster when executing a query, opening a table, designing a diagram, and building a query in the Query Builder.

dbForge Studio for SQL Server is a powerful IDE for SQL Server management, administration, development, data reporting and analysis. The tool will help SQL developers to manage databases, speed up routine tasks, as well, as to make complex database changes.

To learn more visit http://www.devart.com/dbforge/sql/studio/

Pricing and Availability

dbForge Studio for SQL Server with functionality of Professional Edition is available for 30-day trial period. The license prices starts from 149.95$.

About Devart

Devart is a recognized vendor of database connectivity solutions for Microsoft .NET and Embarcadero Delphi development platforms as well as database development and management software.

Company's solutions support such databases as Microsoft SQL Server, Oracle, MySQL, PostgreSQL, InterBase, Firebird, SQLite, etc.

Along with database oriented software Devart offers productivity tools for Visual Studio which help developers to be empowered, stay focused, and deliver their best all the time.

For additional information about Devart, visit http://www.devart.com/

date difference problems

$
0
0
I have two tables:
clients containing clientid, forename, surname
advice containing adviceid, date, clientid

A client could come any number of times for advice.

I want to extract:
the number of clients who have received advice between two dates - date1 and date2 (I can do this)
the number of people who are ‘new’ i.e. the ones who last received advice 12 months or more before date1

It is this second one that I can’t do.

Can anyone help?

restricting column to latest date

$
0
0
HI all

I'm very new to Crystal reports and have a problem with a report I've been asked to look at that was built by another person that is sadly no longer with the company

I have a list of Clients and Client activity dates (and a few other things but the Client activity date is the thing I'm interested in )

Client | Client activity date |

Some of the dates could be in the future i.e next week next month i'm sure you get the jist

Some Clients have a number of activity dates associated with them, how can I restrict this to just one activity that being the latest date regardless of whether it is in the future, current or in the past?

Thank you

Difficulty getting correct data ---Running a Report

$
0
0
I am trying to run a report showing 3 things
Name of employee
Start date of open issue
Days since the issue is open (For calculating days I am using formula =DateDiff("d",[Start Date],Now())
and my query is

SELECT [Form].[Employee Name], Count([Form].[Completed By]) AS [CountOfCompleted By], [Form].[Start Date]
FROM [Form]
WHERE ((([Form].[Close Date]) Is Null))
GROUP BY [Form].[Completed By], [Form].[Start Date]
HAVING ((([Form].[Completed By]) Is Not Null) AND ((Count([Form].[Completed By])) Is Not Null))
ORDER BY [Form].[Completed By];

But my problem is my query gives employees name duplicate times

so my data looks as this
Name Start Date Days issue open
John 2/2/2014 2
John 3/2/2014 4
John 4 /2/2014 6

Where is I want employee name to appear once with maybe total number of days
John 2/2/2014 6

Showing start date is not required in the report.

I tried doing where condition for start date and then query gives me correct data as in
John 2/2/2014 6
However as start date is where doesn't show up on report and thus no calculation days issue open.

Cursor: Pin S Wait on X

$
0
0
Hi all,

Please find below how do I get list of queries that caused "Cursor: Pin S Wait on X" on database.

Now how do I get list of only the top wait for these queries?

Quote:

select distinct j1.sql_id, j1.sql_text from v$sql j1,
(
select distinct t1.sql_id
from V$ACTIVE_SESSION_HISTORY t1,
(
select distinct mutex_identifier
from V$MUTEX_SLEEP_HISTORY where trunc(sleep_timestamp) = trunc(sysdate)
) t2
where t1.p1 = t2.mutex_identifier
) j2
where j1.sql_id = j2.sql_id

Open Google Earth desktop version to specific location

$
0
0
I'm a newbie so please bear with me.
I am looking to open the application and center the display to the Lat. and Long. stored in my table. My question is how do I send the data to Google Earth through the command line?
Viewing all 13329 articles
Browse latest View live