Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Stored Procedures

Empfohlene Antworten

Frage:

Schreiben Sie eine stored procedure, die bei Eingabe eines Tabellennamens die Anzahl der Sätze, die aktuell in dieser Tabelle sich befinden, ausgibt.

Kann man das so machen?

CREATE PROCEDURE table_count (

in_table_name IN VARCHAR2, out_anzahl OUT NUMBER

)

AS

v_tablename VARCHAR2 := in_table_name;

BEGIN

SELECT COUNT (*) INTO out_anzahl

FROM v_tablename;

END;

EXCEPTION

WHEN NO_DATA_FOUND THEN

out_anzahl:=0;

END;

EXCEPTION

WHEN OTHERS THEN

RAISE_APPLICATION_ERROR(-20010,’proc’||’table_count: ‘|| substr(SQLERRM,1,80));

END;

Danke vorab!

Hi,

nicht ganz. Zuerst müsste man wissen wohin das Ergebnis ausgegeben werden soll.

Bei einem SELECT count() wird nie eine NO_DATA_FOUND Exception gefunden. Bei 0 Sätzen wird einfach 0 geliefert. Den entsprechenden Exceptionteil kannst also weglassen.

Dann kann man kein statisches SQL machen, bei dem der tabellenname nicht fest ist. Hier braucht man dynamisches SQL:

EXECUTE IMMEDIATE' select count(*) from '||in_table_name INTO out_anzahl;

Weswegen scheidest Du denn die Fehlermeldung auf 80 Zeichen ab?

Dim

Danke für die Antwort,

mein Problem ich kenne mich mit stored procedures gar nicht aus...

kann ich dann den AS Teil ganz weglassen?

CREATE PROCEDURE table_count (

in_table_name IN VARCHAR2, out_anzahl OUT NUMBER

)

AS

v_tablename VARCHAR2 := in_table_name;

BEGIN

EXECUTE IMMEDIATE' select count(*) from '||in_table_name INTO out_anzahl;

END;

EXCEPTION

WHEN OTHERS THEN

RAISE_APPLICATION_ERROR(-20010,’proc’||’table_count: ‘|| substr(SQLERRM,1,80));

END;

Danke schon mal....

Weglassen? Nein nur ersetzen:

CREATE PROCEDURE table_count ( in_table_name IN VARCHAR2, out_anzahl OUT NUMBER) AS

BEGIN

  EXECUTE IMMEDIATE 'select count(*) from '||in_table_name INTO out_anzahl;

END;

Des weiteren sind das ' und keine Backticks (’) wie du sie verwendet hast.

Dim

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.